Commit Graph

1918 Commits

Author SHA1 Message Date
Kazu Hirata
f3dcc2351c [clang] Use StringRef::{starts,ends}_with (NFC) (#75149)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-13 08:54:13 -08:00
Jonas Paulsson
b04a419be1 Minor refactororing of ASTContext::getDeclAlign() (NFC) (#72977) 2023-11-30 11:12:13 +01:00
Jonas Paulsson
2e09ea65c4 [clang] Ensure minimal alignment of global vars of incomplete type. (#72886)
The SystemZ ABI requires any global variable to be aligned to at least 2
bytes, and therefore an external global Value with an opaque type should
get this alignment as well.
2023-11-22 11:24:45 +01:00
Mike Rice
3ce5c04ad0 Replace getAs with castAs, dyn_cast with cast (NFC) (#72600)
Make the code clear that nullptrs are not expected.
2023-11-17 09:22:33 -08:00
Chuanqi Xu
0f7aaeb324 [C++20] [Modules] Allow export from language linkage
Close https://github.com/llvm/llvm-project/issues/71347

Previously I misread the concept of module purview. I thought if a
declaration attached to a unnamed module, it can't be part of the module
purview. But after the issue report, I recognized that module purview is
more of a concept about locations instead of semantics.

Concretely, the things in the language linkage after module declarations
can be exported.

This patch refactors `Module::isModulePurview()` and introduces some
possible code cleanups.
2023-11-09 17:44:41 +08:00
Daniel Bertalan
609fe2cb4b [ObjC] Fix offsets following [[no_unique_address]] for @encode() (#71321)
Commit 46ca880fca made `@encode` skip fields that are made zero-sized by
`[[no_unique_address]]`. When iterating the fields, the index which is
passed to `getFieldOffset` failed to be incremented for those due to the
use of an early `continue`, so subsequent fields reported an incorrect
offset. This caused an assertion to be triggered in
`getObjCEncodingForStructureImpl`.

Fixes #71250
2023-11-06 20:36:47 +01:00
Shao-Ce SUN
fbdf6e2724 [RISCV] Introduce and use BF16 in Xsfvfwmaccqqq intrinsics (#71140)
BF16 implementation based on @joshua-arch1's
https://reviews.llvm.org/D152498
Fixed the incorrect f16 type introduced in
https://github.com/llvm/llvm-project/pull/68296

---------

Co-authored-by: Jun Sha (Joshua) <cooper.joshua@linux.alibaba.com>
2023-11-06 11:22:14 +08:00
Vlad Serebrennikov
3e6ce58701 [clang][NFC] Refactor StringLiteral::StringKind
This patch converts `StringLiteral::StringKind` to a scoped enum in namespace scope. This enabled forward-declarations of this enum where necessary, e.g. for `preferred_type` annotation for bit-fields.
2023-11-05 12:30:49 +03:00
Vlad Serebrennikov
edd690b02e [clang][NFC] Refactor TagTypeKind (#71160)
This patch converts TagTypeKind into scoped enum. Among other benefits,
this allows us to forward-declare it where necessary.
2023-11-03 21:45:39 +04:00
Vlad Serebrennikov
ae7b20b583 [clang][NFC] Refactor VectorType::VectorKind
This patch moves `VectorKind` to namespace scope, and make it complete at the point its bit-field is declared. It also converts it to a scoped enum.
2023-10-31 21:50:18 +03:00
Vlad Serebrennikov
4ad2ada521 [clang][NFC] Refactor ElaboratedTypeKeyword
This patch moves ElaboratedTypeKeyword before `Type` definition so that the enum is complete where bit-field for it is declared. It also converts it to scoped enum and removes `ETK_` prefix.
2023-10-31 20:46:07 +03:00
Vlad Serebrennikov
49fd28d960 [clang][NFC] Refactor ArrayType::ArraySizeModifier
This patch moves `ArraySizeModifier` before `Type` declaration so that it's complete at `ArrayTypeBitfields` declaration. It's also converted to scoped enum along the way.
2023-10-31 18:06:34 +03:00
Craig Topper
56183cf608 [RISCV] Disable lax vector conversions between RVVBuiltin types and RVVFixedLengthDataVector.
This seems to be causing issues with using overloaded RVV intrinsics
that take scalar operands. If the scalar type passed in doesn't exactly
match the element type.

I blindly copied this feature from SVE. Since no one has asked for it
I'd prefer to remove it to make overloaded intrinsics work as expected.

By removing the lax conversions, types declared with __attribute__((riscv_rvv_vector_bits(__riscv_v_fixed_vlen)))
can only ever be used like their underlying RVV builtin type. No lax conversions
to other element sizes with the same LMUL.

Fixes #64404.
2023-10-26 12:20:01 -07:00
Daniel Grumberg
b67d370257 [clang] Prioritze decl comments from macro expansion site (#65481)
For declarations declared inside a macro, e.g.:
```
`#define MAKE_FUNC(suffix) \
         /// Not selected doc comment \
         void func_##suffix(void) {  }

/// Doc comment foo
MAKE_FUNC(foo)

/// Doc comment bar
MAKE_FUNC(bar)
````

Prefer the doc comment at the expansion site instead of the one defined
in the macro.

rdar://113995729
2023-10-26 17:32:36 +01:00
Kazu Hirata
f9306f6de3 [ADT] Rename llvm::erase_value to llvm::erase (NFC) (#70156)
C++20 comes with std::erase to erase a value from std::vector.  This
patch renames llvm::erase_value to llvm::erase for consistency with
C++20.

We could make llvm::erase more similar to std::erase by having it
return the number of elements removed, but I'm not doing that for now
because nobody seems to care about that in our code base.

Since there are only 50 occurrences of erase_value in our code base,
this patch replaces all of them with llvm::erase and deprecates
llvm::erase_value.
2023-10-24 23:03:13 -07:00
Vlad Serebrennikov
f0601c7569 [clang][NFC] Replace TypeAlignment with alignof(T) (#69185)
This patch replaces usages of `TypeAlignment` with `alignof(T)`, where `T` is type that will be created in allocated storage with placement-new. This is now possible, because `alignof` reports the correct alignment for `Type` and classes derived from it after #68377 was merged.

While preparing #68377 I verified via `static_assert` that there are no mismatches of alignment between `TypeAlignment` and alignment of types derived from `Type`, so no changes are expected to codegen.
2023-10-17 13:04:49 +04:00
Min-Yih Hsu
fd4f96290a [Clang][M68k] Add Clang support for the new M68k_RTD CC
This patch adds `CC_M68kRTD`, which will be used on function if either
`__attribute__((m68k_rtd))` is presented or `-mrtd` flag is given.

Differential Revision: https://reviews.llvm.org/D149867
2023-10-15 16:13:43 -07:00
Kazu Hirata
f659ef43cd [AST] Fix a warning
This patch fixes:

  clang/lib/AST/ASTContext.cpp:931:40: error: field
  'DependentBitIntTypes' will be initialized after field
  'FunctionProtoTypes' [-Werror,-Wreorder-ctor]
2023-10-03 11:08:24 -07:00
Matheus Izvekov
6d209bd436 [NFC][clang] change remaining context-dependent type nodes to ContextualFoldingSet (#67751)
With this change, we are avoiding storing one pointer per Type Node
instance, for the cost of one extra pointer per ASTContext, which is
negligible.

After we introduced `ContextualFoldingSet` a long time ago, we never
went back and updated these existing users.
This patch corrects that.
2023-10-03 19:00:10 +02:00
Jonas Hahnfeld
05137ecfca [clang-repl] Emit const variables only once (#65257)
Disable internal linkage for const variables if IncrementalExtensions
are enabled. Otherwise the variables are emitted multiple times, with
multiple constructions at unique memory locations, during every PTU.
2023-10-03 11:58:23 +02:00
Jie Fu
b191ff01dc [clang] Fix -Wunused-variable in ASTContext.cpp (NFC)
/llvm-project/clang/lib/AST/ASTContext.cpp:12938:46: error: unused variable 'DY' [-Werror,-Wunused-variable]
    const auto *DX = cast<DecltypeType>(X), *DY = cast<DecltypeType>(Y);
                                             ^
1 error generated.
2023-09-29 08:38:13 +08:00
Matheus Izvekov
06721bb8b4 [clang] implement common sugared type of inst-dependent DecltypeType (#67739)
While a DecltypeType node itself is not uniqued, an instantiation
dependent DecltypeType will have a
DependentDecltypeType as an underlying type, which is uniqued.

In that case, there can be non-identical non-sugar DecltypeTypes nodes
which nonetheless represent the same type.

Fixes https://github.com/llvm/llvm-project/issues/67603
2023-09-29 02:22:50 +02:00
Alastair Houghton
06f10b8084 [Clang][ObjC] Add optionality to property attribute strings. (#66507)
Add a new attribute, "?", to the property attribute string for
properties of protocols that are declared @optional.

(Previously https://reviews.llvm.org/D135273)

rdar://100463524
2023-09-26 08:30:31 -07:00
Bill Wendling
7d6283fd09 [NFC] Remove unneeded header includes
Use forward decls instead of #including the header files.

Differential Revision: https://reviews.llvm.org/D159421
2023-09-05 13:12:00 -07:00
Jens Massberg
c2bf9baf59 Add a concept AST node.
This patch adds a concept AST node (`ConceptLoc`) and uses it at the corresponding places.

There are three objects that might have constraints via concepts:
`TypeConstraint`,  `ConceptSpecializationExpr` and `AutoTypeLoc`.
The first two inherit from `ConceptReference` while the latter has
the information about a possible constraint directly stored in `AutoTypeLocInfo`. It would be nice if the concept information would be stored the same way in all three cases.

Moreover the current structure makes it difficult to deal with these concepts. For example in Clangd accessing the locations of constraints of a `AutoTypeLoc` can only be done with quite ugly hacks.

So we think that it makes sense to create a new AST node for such concepts.

In details we propose the following:
- Rename `ConceptReference` to `ConceptLoc` (or something else what is approriate)
and make it the new AST node.
- `TypeConstraint` and `ConceptSpecializationExpr` do not longer inherit from `ConceptReference` but store a pointer to a `ConceptLoc`.
- `AutoTypeLoc` stores a pointer to `ConceptLoc` instead of storing the concept info in `AutoTypeLocInfo`.

This patch implements a first version of this idea which compiles and where the existing tests pass.
To make this patch as small as possible we keep the existing member functions to access concept data. Later these can be replaced by directly calling the corresponding functions of the `ConceptLoc`s.

Differential Revision: https://reviews.llvm.org/D155858
2023-08-31 10:22:21 +02:00
Jennifer Yu
1d0bd8e51b [MSABI] Remove comdat attribute for inheriting ctor.
Currently, for MS, the linkage for the inheriting constructors is set to
internal.  However, the comdat attribute is also set like:

define internal noundef ptr @"??0?$B@_N@@qeaa@AEBVF@@aebua@@@z"(ptr noundef nonnull returned align 1 dereferenceable(1) %this, ptr noundef nonnull align 1 dereferenceable(1) %0, ptr noundef nonnull align 1 dereferenceable(1) %1) unnamed_addr comdat

This could cause linker to fail.

The change is to remove comdat attribute for the inheriting constructor
to make linker happy.

Differential Revision: https://reviews.llvm.org/D158538
2023-08-28 15:19:23 -07:00
Craig Topper
33af2f131d [RISCV] Check type size for lax conversions between RVV builtin types and VectorType::RVVFixedLengthDataVector.
This code was copied from SVE and modified for RVV. For SVE, there
is only one size for builtin types so they didn't need to check
the size. For RVV, due to LMUL there are 7 different sizes of builtin
types so we do need to check the size.

I'm not sure we should have lax vector conversions at all for RVV.
That appears to be contributing to https://github.com/llvm/llvm-project/issues/64404

This patch at least fixes the obvious correctness issue.
This should be backported to LLVM 17.

Reviewed By: jacquesguan

Differential Revision: https://reviews.llvm.org/D157130
2023-08-21 14:28:57 -07:00
Jianjian GUAN
28741a23c9 [clang][SVE] Rename isVLSTBuiltinType, NFC
Since we also have VLST for rvv now, it is not clear to keep using `isVLSTBuiltinType`, so I added prefix SVE to it.

Reviewed By: paulwalker-arm

Differential Revision: https://reviews.llvm.org/D158045
2023-08-17 14:18:32 +08:00
Chuanqi Xu
74258f4189 [C++20] [Modules] Allow Stmt::Profile to treat lambdas as equal conditionally
Close https://github.com/llvm/llvm-project/issues/63544.

Background: We landed std modules in libcxx recently but we haven't
landed the corresponding in-tree tests. According to @Mordante, there
are only 1% libcxx tests failing with std modules. And the major
blocking issue is the lambda expression in the require clauses.

The root cause of the issue is that previously we never consider any
lambda expression as the same. Per [temp.over.link]p5:
> Two lambda-expressions are never considered equivalent.

I thought this is an oversight at first but @rsmith explains that in the
wording, the program is as if there is only a single definition, and a
single lambda-expression. So we don't need worry about this in the spec.
The explanation makes sense. But it didn't reflect to the implementation
directly.

Here is a cycle in the implementation. If we want to merge two
definitions, we need to make sure its implementation are the same. But
according to the explanation above, we need to judge if two
lambda-expression are the same by looking at its parent definitions. So
here is the problem.

To solve the problem, I think we have to profile the lambda expressions
actually to get the accurate information. But we can't do this
universally. So in this patch I tried to modify the interface of
`Stmt::Profile` and only profile the lambda expression during the
process of merging the constraint expressions.

Differential Revision: https://reviews.llvm.org/D153957
2023-07-11 16:13:06 +08:00
Sergio Afonso
63ca93c7d1 [OpenMP][OMPIRBuilder] Rename IsEmbedded and IsTargetCodegen flags
This patch renames the `OpenMPIRBuilderConfig` flags to reduce confusion over
their meaning. `IsTargetCodegen` becomes `IsGPU`, whereas `IsEmbedded` becomes
`IsTargetDevice`. The `-fopenmp-is-device` compiler option is also renamed to
`-fopenmp-is-target-device` and the `omp.is_device` MLIR attribute is renamed
to `omp.is_target_device`. Getters and setters of all these renamed properties
are also updated accordingly. Many unit tests have been updated to use the new
names, but an alias for the `-fopenmp-is-device` option is created so that
external programs do not stop working after the name change.

`IsGPU` is set when the target triple is AMDGCN or NVIDIA PTX, and it is only
valid if `IsTargetDevice` is specified as well. `IsTargetDevice` is set by the
`-fopenmp-is-target-device` compiler frontend option, which is only added to
the OpenMP device invocation for offloading-enabled programs.

Differential Revision: https://reviews.llvm.org/D154591
2023-07-10 14:14:16 +01:00
Manna, Soumi
7372c0d46d [CLANG] Fix potential integer overflow value in getRVVTypeSize()
In getRVVTypeSize(clang::ASTContext &, clang::BuiltinType const *) potential integer overflow occurs on expression VScale->first * MinElts with type unsigned int (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type uint64_t (64 bits, unsigned).

To avoid integer overflow, this patch changes the types of variables MinElts and EltSize to uint64_t from unsigned instead of the cast.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D153146
2023-06-28 19:25:53 -07:00
Manna, Soumi
982a87ab74 [CLANG] Fix potential null pointer dereference bugs
This patch uses castAs instead of getAs which will assert if the type doesn't match and adds nullptr check if needed.

Also this patch improves the codes and passes I.getData() instead of doing a lookup in dumpVarDefinitionName()
since we're iterating over the same map in LocalVariableMap::dumpContex().

Reviewed By: aaron.ballman, aaronpuchert

Differential Revision: https://reviews.llvm.org/D153033
2023-06-22 12:58:38 -07:00
Sindhu Chittireddy
c2888cddd5 [NFC] Fix potential dereferencing of null return value.
Replace getAs with castAs and add assert if needed.
Differential Revision: https://reviews.llvm.org/D152977
2023-06-16 20:31:08 -07:00
Craig Topper
3ab9d4f479 [RISCV] Reduce alignment for __attribute__((riscv_rvv_vector_bits)) for LMUL<1 types.
Don't use an alignment larger than the vector size.
2023-06-16 16:41:15 -07:00
Craig Topper
72d23a2ec1 [RISCV] Support LMUL!=1 for __attribute__((riscv_rvv_vector_bits(N)))
The first patch supported only LMUL=1 types. This patch supports
LMUL!=1.

LMUL is length multiplier that allows multiple vector registers to
be treated as one large register or a fraction of a single vector
register. Supported values for LMUL are 1/8, 1/4, 1/2, 1, 2, 4, and 8.

An LMUL=2 type will be twice as large as an LMUL=1 type. An LMUL=1/2
type will be half the size as an LMUL=1 type.

Type name with "m2" is LMUL=2, "m4" is LMUL=4.
Type name with "mf2" is LMUL=1/2, "mf4" is LMUL=1/4.

For the LMUL!=1 types the user will need to scale __riscv_v_fixed_vlen
by the LMUL before passing to the attribute.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D150926
2023-06-08 09:13:43 -07:00
Yaxun (Sam) Liu
f2677afe91 [CUDA][HIP] Externalize device var in anonymous namespace
Device variables in an anonymous namespace may be
referenced by host code, therefore they need to
be externalized in a similar way as a static device
variables or kernels in an anonymous namespace.

Fixes: https://github.com/ROCm-Developer-Tools/HIP/issues/3246

Reviewed by: Artem Belevich

Differential Revision: https://reviews.llvm.org/D152164
2023-06-06 12:03:48 -04:00
Kazu Hirata
8dc7647845 [AST] Use DenseMapBase::lookup (NFC) 2023-06-03 09:37:36 -07:00
Caroline Concatto
fc8acb563a [Clang][SVE2.1] Add clang support for builtins using svcount_t
In this patch it is used for the prototype:
  * svptrue_c8 (and _c16/_c32/_c64)

 As described in: https://github.com/ARM-software/acle/pull/257

Patch by: Sander de Smalen <sander.desmalen@arm.com>

Reviewed By: sdesmalen, david-arm

Differential Revision: https://reviews.llvm.org/D150953
2023-05-31 15:57:44 +00:00
Vitaly Buka
4498663f3d [AST] Initialized data after TypeSourceInfo
There is no initialization of the data between allocation
and first getBeginLoc call.

allocation: llvm-project/clang/lib/AST/ASTContext.cpp:3022
use: llvm-project/clang/lib/AST/TypeLoc.cpp:222

Msan report https://reviews.llvm.org/P8306

Reviewed By: thurston

Differential Revision: https://reviews.llvm.org/D150499
2023-05-25 09:53:17 -07:00
Chuanqi Xu
52bc4b16cb [NFC] [C++20] [Modules] Refactor Sema::isModuleUnitOfCurrentTU into
Decl::isInAnotherModuleUnit

Refactor `Sema::isModuleUnitOfCurrentTU` to `Decl::isInAnotherModuleUnit`
to make code simpler a little bit. Note that although this patch
introduces a FIXME, this is an existing issue and this patch just tries
to describe it explicitly.
2023-05-23 10:52:22 +08:00
eopXD
0019226cee [3/11][POC][Clang][RISCV] Add typedef of the tuple type and define tuple type variant of vlseg2e32
For the cover letter of this patch-set, please checkout D146872.

Depends on D146873.

This is the 3rd patch of the patch-set. This patch originates from
D99593.

Note: This patch is a proof-of-concept and will be extended to full
coverage in the future. Currently, the old non-tuple unit-stride
segment load is not removed, and only signed integer unit-strided
segment load of NF=2, EEW=32 is defined here.

When replacing the old intrinsics, the extra `IsTuple` parameter under
various places will be redundant and removed.

Authored-by: eop Chen <eop.chen@sifive.com>
Co-Authored-by: Hsiangkai Wang <kai.wang@sifive.com>

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D147731
2023-05-22 02:51:14 -07:00
Craig Topper
3f43abc9e7 [RISCV] Reduce dependency on RISCV::RVVBitsPerBlock for calculating vector size for -mrvv-vector-bits.
We can use the minimum value of the BuiltinType's ElementCount and
the element size.

This needs to be done to support LMUL!=1 types anyway.

I did have to make an ordering change in the error checks in
HandleRISCVRVVVectorBitsTypeAttr to check if the type is an RVV
VLS type before checking the size.
2023-05-18 10:09:50 -07:00
Craig Topper
fa0a39113a [RISCV] Fix assertion when casting LMUL!=1 RVV types to GNU types with -mrvv-vector-bits.
We need to call isRVVVLSBuiltinType() before calling getRVVTypeSize().
2023-05-18 09:21:38 -07:00
Craig Topper
7bbe512362 [RISCV] Remove unneedded comment. NFC
This was copied from SVE, but is currently not applicable to RISC-V.
2023-05-17 22:49:28 -07:00
Chuanqi Xu
88a720d194 [NFC] [C++20] [Modules] Rename ASTContext::getNamedModuleForCodeGen to ASTContext::getCurrentNamedModule
The original name "ASTContext::getNamedModuleForCodeGen" is not properly
reflecting the usage of the interface. This interface can be used to
judge the current module unit in both sema analysis and code generation.
So the original name was not so correct.
2023-05-16 11:24:35 +08:00
Chuanqi Xu
7f37066915 Revert "[NFC] [C++20] [Modules] Refactor Sema::isModuleUnitOfCurrentTU into"
This reverts commit f109b10168 as required
in
f109b10168 (commitcomment-113477829).
2023-05-16 10:47:53 +08:00
Chuanqi Xu
40c3054389 [NFC] [C++20] [Modules] Refactoring b6c7177145 to make it not
dependent on f109b10

Given
f109b10168 (commitcomment-113477829),
we need to revert f109b10. So it will be better to make this patch not
dependent on f109b10 as much as possible.
2023-05-16 10:34:02 +08:00
Chuanqi Xu
b6c7177145 [C++20] [Modules] Don't generate unused variables in other module units
even if its initializer has side effects

Close https://github.com/llvm/llvm-project/issues/61892

The variables whose initializer has side effects will be emitted even if
it is not used. But it shouldn't be true after we introduced modules.
The variables in other modules shouldn't be emitted if it is not used
even if its initializer has size effects.

Also this patch rename `Decl::isInCurrentModuleUnit` to
`Decl::isInAnotherModuleUnit` to make it closer to the semantics.
2023-05-10 17:41:58 +08:00
Chuanqi Xu
f109b10168 [NFC] [C++20] [Modules] Refactor Sema::isModuleUnitOfCurrentTU into
Decl::isInCurrentModuleUnit

Refactor `Sema::isModuleUnitOfCurrentTU` to `Decl::isInCurrentModuleUnit`
to make code simpler a little bit. Note that although this patch
introduces a FIXME, this is an existing issue and this patch just tries
to describe it explicitly.
2023-05-10 16:01:27 +08:00
Manna, Soumi
6e0c441748 [NFC][CLANG] Fix nullptr dereference found by Coverity static analysis tool
Reported by Coverity:

  In clang::ASTContext::hasUniqueObjectRepresentations(clang::QualType, bool): Return value of function which returns null is dereferenced without checking.

  (Ty->isMemberPointerType()) {
      	//returned_null: getAs returns nullptr.
      	//var_assigned: Assigning: MPT = nullptr return value from getAs.
      const auto *MPT = Ty->getAs<MemberPointerType>();

     //dereference: Dereferencing a pointer that might be nullptr MPT when calling getMemberPointerInfo. (The virtual call resolves to
     <unnamed>::ItaniumCXXABI::getMemberPointerInfo.)
      return !ABI->getMemberPointerInfo(MPT).HasPadding;
    }

ABIs assume the parameter passed to `getMemberPointerInfo` is non-null.
This patch checks type by doing a `if (const auto *MPT = Ty->getAs<MemberPointerType>())` instead.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D149922
2023-05-05 11:57:33 -07:00