2023 Commits

Author SHA1 Message Date
Chuanqi Xu
7f37066915 Revert "[NFC] [C++20] [Modules] Refactor Sema::isModuleUnitOfCurrentTU into"
This reverts commit f109b1016801e2b0dbee278f3c517057c0b1d441 as required
in
f109b10168 (commitcomment-113477829).
2023-05-16 10:47:53 +08:00
Chuanqi Xu
40c3054389 [NFC] [C++20] [Modules] Refactoring b6c7177145bc 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
Craig Topper
9b1aaaf933 Revert "[RISCV] Move RISCV::RVVBitsPerBlock from TargetParser to Support/RISCVISAInfo.h."
This reverts commit ee9cbe3548cded885c6409d6dd8a616b515a06d3.

I've been told this cauess a namespace clash in lld.
2023-04-29 18:05:56 -07:00
Craig Topper
ee9cbe3548 [RISCV] Move RISCV::RVVBitsPerBlock from TargetParser to Support/RISCVISAInfo.h.
RISCVTargetParser.h has a dependency on a tablegen generated file.

Using RISCVISAInfo.h instead avoids this dependency.

We just need this constant somewhere visible to the frontend and
backend and I'm trying to avoid adding a header just for it.
2023-04-29 15:04:55 -07:00
Craig Topper
42e79d9771 [RISCV] Add attribute(riscv_rvv_vector_bits(N)) based on AArch64 arm_sve_vector_bits.
This allows the user to set the size of the scalable vector so they
can be used in structs and as the type of global variables. This works
by representing the type as a fixed vector instead of a scalable vector
in IR. Conversions to and from scalable vectors are made where necessary
like function arguments/returns and intrinsics.

This features has been requested here
https://github.com/riscv-non-isa/rvv-intrinsic-doc/issues/176
I know arm_sve_vector_bits is used by the Eigen library so this
could be used to port Eigen to RVV.

This patch adds a new preprocessor define `__riscv_v_fixed_vlen` that
is set when -mrvv_vector_bits is passed on the command line.

The code is largely based on the AArch64 code. A lot of code was
copy/pasted and then modiied to RVV. There may be some opportunities
for sharing.

This first patch only supports the LMUL=1 types. Additional changes
will be needed to support other LMULs. I have also not supported
mask vectors.

Differential Revision: https://reviews.llvm.org/D145088
2023-04-28 15:41:17 -07:00
Erich Keane
15f0491d39 [NFC] Fix a mem-sanitizer found issue in AutoType
We only need the list of constriant template arguments when we have a
valid constraint.  We give up on merging the auto-type constraints if
the template arguments don't match, but neglected to clear the
collection of template arguments.  The result was we had an AutoType
where we initialized the number of template arguments, but never
initialized the template arguments themselves.

This patch adds an assert to catch this in the future, plus ensures we
clear out the vector so we don't try to create the AutoType incorrectly.
2023-04-28 10:09:26 -07:00
Manna, Soumi
ff4d2207db [NFC][clang] Fix static analyzer concerns
Reported by Coverity:

AUTO_CAUSES_COPY
Unnecessary object copies can affect performance.

1. Inside "SemaDeclCXX.cpp" file, in <unnamed>::DiagnoseUninitializedFields(clang::Sema &, clang::CXXConstructorDecl const *): Using the auto keyword without an & causes the copy of an object of type CXXBaseSpecifier.

2. Inside "ClangAttrEmitter.cpp" file, in clang::EmitClangAttrParsedAttrImpl(llvm::RecordKeeper &, llvm::raw_ostream &): Using the auto keyword without an & causes the copy of an object of type pair.

3. Inside "Marshallers.h" file, in clang::ast_matchers::dynamic::internal::MapAnyOfBuilderDescriptor::buildMatcherCtor(clang::ast_matchers::dynamic::SourceRange, llvm::ArrayRef<clang::ast_matchers::dynamic::ParserValue>, clang::ast_matchers::dynamic::Diagnostics *): Using the auto keyword without an & causes the copy of an object of type ParserValue.

4. Inside "CGVTables.cpp" file, in clang::CodeGen::CodeGenModule::GetVCallVisibilityLevel(clang::CXXRecordDecl const *, llvm::DenseSet<clang::CXXRecordDecl const *, llvm::DenseMapInfo<clang::CXXRecordDecl const *, void>> &): Using the auto keyword without an & causes the copy of an object of type CXXBaseSpecifier.

5. Inside "ASTContext.cpp" file, in hasTemplateSpecializationInEncodedString(clang::Type const *, bool): Using the auto keyword without an & causes the copy of an object of type CXXBaseSpecifier.

6. Inside "ComputeDependence.cpp" file, in clang::computeDependence(clang::DependentScopeDeclRefExpr *): Using the auto keyword without an & causes the copy of an object of type TemplateArgumentLoc.

Reviewed By: tahonermann, erichkeane

Differential Revision: https://reviews.llvm.org/D148812
2023-04-23 18:19:55 -04:00
Nikolas Klauser
e98776a180 [clang] Add __is_trivially_equality_comparable
This patch adds a new trait to allow standard libraries to forward `std::equal` calls to `memcmp` in more cases.

Reviewed By: aaron.ballman

Spies: Mordante, shafik, xbolva00, libcxx-commits, cfe-commits, ldionne

Differential Revision: https://reviews.llvm.org/D147175
2023-04-17 15:36:21 +02:00
Akira Hatanaka
2ba88443b3 Fix an assertion failure in unwrapSugar
An assertion in Qualifiers::addObjCLifetime fails when the ObjC lifetime
bits are already set.

Instead of calling operator+=, call addConsistentQualifiers, which
allows the lifetime bits to be set again as long the new value doesn't
conflict with the old value.

This fixes https://github.com/llvm/llvm-project/issues/61419.

Differential Revision: https://reviews.llvm.org/D147263
2023-04-12 16:45:56 -07:00
Roy Jacobson
016970d079 [Clang] Fix cast to BigIntType in hasUniqueObjectRepresentations
A bad QualType cast caused us not to detect _BigInt types if they were wrapped inside sugar types like SubstTemplateTypeParm.
Fix https://github.com/llvm/llvm-project/issues/62019

Reviewed By: cjdb

Differential Revision: https://reviews.llvm.org/D147904
2023-04-10 22:11:57 +03:00
Richard Smith
aeee4ebd68 Stop modifying trailing return types.
This change reverts the functional change from D144626 but retains its
test. Instead of dealing with the possibility that a trailing requires
clause might have been rewritten into some other incorrect form, just
stop rewriting it.

No functionality changes intended.

Reviewed By: erichkeane, ChuanqiXu

Differential Revision: https://reviews.llvm.org/D147281
2023-04-02 01:41:49 -07:00
Roy Jacobson
1d4d21e2e0 [Clang][AST] Fix __has_unique_object_representations computation for unnamed bitfields.
As pointed out in https://github.com/llvm/llvm-project/issues/61336, objects with
unnamed bitfields aren't be uniquely representable.

Reviewed By: shafik, Endill

Differential Revision: https://reviews.llvm.org/D145852
2023-04-02 00:54:45 +03:00
Richard Smith
3524a9f84a Retain constraints in the canonical form of an auto type.
This is necessary in order for type equality checking, for example
across redeclarations, to require constraints to match. This is also a
prerequisite for including the constraints in manglings.

In passing, fix a bug where TemplateArgument::Profile would produce the
same profile for two structurally different template names, which caused
this change to re-expose the crash previously addressed by D133072,
which it turns out had not quite addressed all problematic cases.
2023-03-30 17:00:16 -07:00
Richard Smith
bc62fb9e17 Ignore constraints when determining a canonical template parameter.
This follows C++ [temp.over.link]/6, which says that constraints are not
part of what determines whether two template parameters are equivalent.
This allows templates that have different constraints on nested template
template parameters to be ordered by their constraints.
2023-03-30 17:00:16 -07:00
Richard Smith
a07abe27b4 Factor out helper to determine whether a function is a "member-like
constrained friend".

When a friend declaration has a requires-clause, and either it's a
non-template function or it's a function template whose requires-clause
depends on an enclosing template parameter, it is member-like for the
purpose of redeclaration checking. Specifically, the lexically enclosing
class becomes part of its signature, so it can only be redeclared by
another declaration within the same class. In this change, we call such
functions "member-like constrained friends".

No functional change intended.
2023-03-30 17:00:16 -07:00
Richard Smith
bc73ef0031 PR60985: Fix merging of lambda closure types across modules.
Previously, distinct lambdas would get merged, and multiple definitions
of the same lambda would not get merged, because we attempted to
identify lambdas by their ordinal position within their lexical
DeclContext. This failed for lambdas within namespace-scope variables
and within variable templates, where the lexical position in the context
containing the variable didn't uniquely identify the lambda.

In this patch, we instead identify lambda closure types by index within
their context declaration, which does uniquely identify them in a way
that's consistent across modules.

This change causes a deserialization cycle between the type of a
variable with deduced type and a lambda appearing as the initializer of
the variable -- reading the variable's type requires reading and merging
the lambda, and reading the lambda requires reading and merging the
variable. This is addressed by deferring loading the deduced type of a
variable until after we finish recursive deserialization.

This also exposes a pre-existing subtle issue where loading a
variable declaration would trigger immediate loading of its initializer,
which could recursively refer back to properties of the variable. This
particularly causes problems if the initializer contains a
lambda-expression, but can be problematic in general. That is addressed
by switching to lazily loading the initializers of variables rather than
always loading them with the variable declaration. As well as fixing a
deserialization cycle, that should improve laziness of deserialization
in general.

LambdaDefinitionData had 63 spare bits in it, presumably caused by an
off-by-one-error in some previous change. This change claims 32 of those bits
as a counter for the lambda within its context. We could probably move the
numbering to separate storage, like we do for the device-side mangling number,
to optimize the likely-common case where all three numbers (host-side mangling
number, device-side mangling number, and index within the context declaration)
are zero, but that's not done in this change.

Fixes #60985.

Reviewed By: #clang-language-wg, aaron.ballman

Differential Revision: https://reviews.llvm.org/D145737
2023-03-30 14:22:40 -07:00
Walter Gray
1f48a1fce2 Fix ArgsAsWritten being null for ConceptSpecializationExpr in certain
circumstances when parsing ASTs

Fix ArgsAsWritten being null for ConceptSpecializationExpr in certain
circumstances when parsing ASTs

ASTStmtWriter::VisitConceptSpecializationExpr specifically expects
getTemplateArgsAsWritten() to return true, which it wasn't when parsed
by ASTContext.cpp in certain edge cases.

Fixes: #61486

Differential Revision: https://reviews.llvm.org/D146678
2023-03-29 09:44:01 -07:00
Kazu Hirata
8bdf387858 Use *{Map,Set}::contains (NFC)
Differential Revision: https://reviews.llvm.org/D146104
2023-03-15 08:46:32 -07:00
Matt Devereau
a1fae98ba9 [AArch64] Add svboolx2_t and svboolx4_t tuple types
https://reviews.llvm.org/D145505
2023-03-14 10:16:51 +00:00
Pavel Iliin
124b46a897 [NFC][AArch64] Document and improve FMV code.
Differential Revision: https://reviews.llvm.org/D145538
2023-03-08 23:22:46 +00:00
Sander de Smalen
07158c54ad [Clang] Create opaque type for AArch64 SVE2p1/SME2 svcount_t.
This patch adds the builtin type __SVCount_t to Clang, which is an opaque
scalable type defined in the SME2 C and C++ Language Extensions.

The type maps to the `target("aarch64.svcount")` LLVM IR type.

Reviewed By: paulwalker-arm

Differential Revision: https://reviews.llvm.org/D136864
2023-03-07 14:43:50 +00:00
Chuanqi Xu
6ceb32a66f [C++20] [Modules] Handle the linkage of defaulted friend function
definition correctly

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

Previously we will only handle the defaulted member functions as
discardable ODR. But we need to handle defaulted friend function in this
way too. Otherwise we may run into the problems the above issue report
mentions.
2023-03-07 15:34:33 +08:00
Chuanqi Xu
2408f97652 Recommit [C++20] [Modules] Trying to compare the trailing require clause from the primary template function
Close https://github.com/llvm/llvm-project/issues/60890.

For the following example:

```
export module a;

export template<typename T>
struct a {
	friend void aa(a) requires(true) {
	}
};
```

```
export module b;

import a;

struct b {
	a<int> m;
};
```

```
export module c;

import a;

struct c {
	void f() const {
		aa(a<int>());
	}
};
```

```
import a;
import b;
import c;

void d() {
	aa(a<int>());
}
```

The current clang will reject this incorrectly. The reason is that the
require clause  will be replaced with the evaluated version
(efae3174f0/clang/lib/Sema/SemaConcept.cpp (L664-L665)).
In module 'b', the friend function is instantiated but not used so the
require clause of the friend function is `(true)`. However, in module
'c', the friend function is used so the require clause is `true`. So
deserializer classify these two function to two different functions
instead of one. Then here is the bug report.

The proposed solution is to try to compare the trailing require clause
of the primary template when performing ODR checking.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D144626
2023-03-03 17:27:37 +08:00
Chuanqi Xu
db1b827ecf Revert "[Modules] Don't check [temp.friend]p9 in ASTContext::isSameEntity"
This reverts commit 74565c3add6d683559618973863e78a5e6836e48.

Since it looks like this one causes the modular libcxx build fails.
2023-03-01 11:19:10 +08:00
Chuanqi Xu
5bb3253cf5 Revert "[C++20] [Modules] Trying to compare the trailing require clause from the primary template function"
This reverts commit 9e50578ba43c49ee13ac3bb7d4868565824f9b29. Since it
looks like this one prevents us to fix the modular build for libcxx.
2023-03-01 11:04:20 +08:00
Mark de Wever
33e18cb6ce Revert "Revert "[Modules] Don't check [temp.friend]p9 in ASTContext::isSameEntity""
This fixes the Clang modular CI, but breaks other CIs.

This reverts commit 2ae39902506f38d6368a7dbe3d64109f57ad6f99.
2023-02-28 20:03:54 +01:00
Mark de Wever
2ae3990250 Revert "[Modules] Don't check [temp.friend]p9 in ASTContext::isSameEntity"
This commits breaks the libc++ modular build in the precommit CI.

This reverts commit 74565c3add6d683559618973863e78a5e6836e48.
2023-02-28 19:36:56 +01:00
Chuanqi Xu
9e50578ba4 [C++20] [Modules] Trying to compare the trailing require clause from the primary template function
Close https://github.com/llvm/llvm-project/issues/60890.

For the following example:

```
export module a;

export template<typename T>
struct a {
	friend void aa(a) requires(true) {
	}
};
```

```
export module b;

import a;

struct b {
	a<int> m;
};
```

```
export module c;

import a;

struct c {
	void f() const {
		aa(a<int>());
	}
};
```

```
import a;
import b;
import c;

void d() {
	aa(a<int>());
}
```

The current clang will reject this incorrectly. The reason is that the
require clause  will be replaced with the evaluated version
(efae3174f0/clang/lib/Sema/SemaConcept.cpp (L664-L665)).
In module 'b', the friend function is instantiated but not used so the
require clause of the friend function is `(true)`. However, in module
'c', the friend function is used so the require clause is `true`. So
deserializer classify these two function to two different functions
instead of one. Then here is the bug report.

The proposed solution is to try to compare the trailing require clause
of the primary template when performing ODR checking.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D144626
2023-02-28 23:41:48 +08:00
Craig Topper
2e73111702 [Sema] Use isSVESizelessBuiltinType instead of isSizelessBuiltinType to prevent crashing on RISC-V.
These 2 spots are protecting calls to SVE specific functions. If RISC-V
sizeless types end up in there we trigger assertions.

Use the more specific isSVESizelessBuiltinType() to avoid letting
RISC-V vectors through.

Reviewed By: asb, c-rhodes

Differential Revision: https://reviews.llvm.org/D144772
2023-02-27 09:19:27 -08:00
Chuanqi Xu
74565c3add [Modules] Don't check [temp.friend]p9 in ASTContext::isSameEntity
[temp.friend]p9 says

> Such a constrained friend function or function template declaration does
not declare the same function or function template as a declaration in
any other scope.

But the friend declaration in the same scope shouldn't fall into this
catagory. Although the logic is handled in 'FriendsDifferByConstraints',
the compiler may haven't merged the lexcial declcontext in time.
Also the code removed is not covered by test too.

Let's handle the logic in sema as we've done now.
2023-02-23 17:09:38 +08:00
Kugan Vivekanandarajah
d604c57164 [NFC] Use find_last_of when seraching for code in getRawCommentForDeclNoCacheImpl
ASTContext::getRawCommentForDeclNoCacheImpl in this case, extracts the text between
the comment and declaration to make sure if there are  no other declarations or preprocessor
directives between  comment or declarations.

While using Text.find_first_of or Text.find_last_of  is functionally the same,
 using Text.find_last_of terminates fast in the presence of such.

Especially in generated code with sparse comments, it takes longer
to bailout when there is code in-between. Searching from last
(with find_last_of) bails out faster.

This shows up in perf profiles with clangd in some auto-generated code.
ASTContext::getRawCommentForDeclNoCacheImpl showing as much as 18.2% in this
case. With find_last_of, this drops to 2.8%.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D141950
2023-02-21 16:25:46 +00:00
Benjamin Kramer
7ac658a07b [WebAssembly] assert(false) -> llvm_unreachable
Avoids warnings in -asserts builds.

ASTContext.cpp:4098:1: error: non-void function does not return a value in all control paths [-Werror,-Wreturn-type]
}
^
2023-02-18 09:38:18 +01:00
Paulo Matos
890146b192 [WebAssembly] Initial support for reference type externref in clang
This patch introduces a new type __externref_t that denotes a WebAssembly opaque
reference type. It also implements builtin __builtin_wasm_ref_null_extern(),
that returns a null value of __externref_t. This lays the ground work
for further builtins and reference types.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D122215
2023-02-17 18:48:48 -08:00
Chuanqi Xu
1ba93c3c30 [Modules] Don't re-generate template specialization in the importer
Close https://github.com/llvm/llvm-project/issues/60693.

In this issue, we can find that the importer will try to generate the
template specialization again in the importer, which is not good and
wastes time. This patch tries to address the problem.
2023-02-14 17:15:33 +08:00
Dominik Adamski
baca3c1507 Move SIMD alignment calculation to LLVM Frontend
Currently default simd alignment is defined by Clang specific TargetInfo class.
This class cannot be reused for LLVM Flang. That's why default simd alignment
calculation has been moved to OMPIRBuilder which is common for Flang and Clang.

Previous attempt: https://reviews.llvm.org/D138496 was wrong because
the default alignment depended on the number of built LLVM targets.

If we wanted to calculate the default alignment for PPC and we hadn't specified
PPC LLVM target to build, then we would get 0 as the alignment because
OMPIRBuilder couldn't create PPCTargetMachine object and it returned 0 as
the default value.

If PPC LLVM target had been built earlier, then OMPIRBuilder could have created
PPCTargetMachine object and it would have returned 128.

Differential Revision: https://reviews.llvm.org/D141910

Reviewed By: jdoerfert
2023-02-10 04:11:54 -06:00
Archibald Elliott
62c7f035b4 [NFC][TargetParser] Remove llvm/ADT/Triple.h
I also ran `git clang-format` to get the headers in the right order for
the new location, which has changed the order of other headers in two
files.
2023-02-07 12:39:46 +00:00
Vitaly Buka
bccf5999d3 Revert "[clang][WebAssembly] Initial support for reference type externref in clang"
Very likely breaks stage 3 of msan build bot.
Good: 764c88a50ac76a2df2d051a0eb5badc6867aabb6 https://lab.llvm.org/buildbot/#/builders/74/builds/17058
Looks unrelated: 48b5a06dfcab12cf093a1a3df42cb5b684e2be4c
Bad: 48b5a06dfcab12cf093a1a3df42cb5b684e2be4c https://lab.llvm.org/buildbot/#/builders/74/builds/17059

This reverts commit eb66833d19573df97034a81279eda31b8d19815b.
2023-02-05 21:41:48 -08:00
Argyrios Kyrtzidis
4de51483ef Revert "[OpenMP][OMPIRBuilder]Move SIMD alignment calculation to LLVM Frontend"
Causes clang build failures, see https://reviews.llvm.org/D141910#4089465 for details.

This reverts commit ca446037af019d1aa01b1352a30a18df33038359.
2023-01-31 12:11:57 -08:00
Benjamin Kramer
d8982f7228 [AST] assert(false) -> llvm_unreachable
Has the advantage of not triggering missing return warnings even in
NDEBUG builds.
2023-01-31 18:57:01 +01:00
Paulo Matos
eb66833d19 [clang][WebAssembly] Initial support for reference type externref in clang
This patch introduces a new type __externref_t that denotes a WebAssembly opaque
reference type. It also implements builtin __builtin_wasm_ref_null_extern(),
that returns a null value of __externref_t. This lays the ground work
for further builtins and reference types.

Differential Revision: https://reviews.llvm.org/D122215
2023-01-31 17:34:01 +01:00
Kazu Hirata
7a063c1a13 [AST] Use llvm::bit_ceil (NFC)
For nonzero X that is not a power of 2, NextPowerOf2(X) is equivalent
to llvm::bit_ceil(X).
2023-01-29 15:39:46 -08:00
Kazu Hirata
3d25896bd9 [AST] Use std::clamp (NFC) 2023-01-29 09:43:36 -08:00
Kazu Hirata
526966d07d Use llvm::bit_ceil (NFC)
Note that:

  std::has_single_bit(X) ? X : llvm::NextPowerOf2(X);

is equivalent to:

  std::bit_ceil(X)

even for input 0.
2023-01-28 16:13:09 -08:00
Michael Buch
8b4279b66f [clang][TemplateBase] Add IsDefaulted bit to TemplateArgument
**Summary**

This patch adds a `IsDefaulted` field to `clang::TemplateArgument`.

To prevent memory footprint increase we still 1 bit from `ArgKind`.

**Changes**

1. `getIsDefaulted`/`setIsDefaulted` to allow clients to communicate
   an argument's defaulted-ness to the TypePrinter
2. The `TemplateArgument` properties description had to be changed
   to make sure we correctly mark the defaulted-ness of arguments
   that came from a deserialized AST (caught by the HLSL test-suite)
3. The `TemplateArgument` constructors now accept a `IsDefaulted`
   parameter to simplify construction from the tablegen description.
   Though if people don't want to clutter the constructors we can
   instead call `setIsDefaulted` from tablegen
4. When `clang::Sema` checks the template arguments against template
   parameters we now call `setIsDefaulted`. This makes sure that
   whenever a specialization decl gets constructed, the defaulted-ness
   of the associated `TemplateArgument`s has already been deduced.
   This preserves the immutability of `TemplateArgumentList`s

**Background**

In LLDB we construct ASTs from debug-info and hand it to clang
to perform actions such as printing/formatting a typenames.
Some debug formats, specifically DWARF, may only encode information
about class template instantiations, losing the structure of the generic
class definition. However, the `clang::TypePrinter` needs a properly
constructed `ClassTemplateDecl` with generic default argument decls
to be able to deduce whether a `ClassTemplateSpecializationDecl` was
instantiatiated with `TemplateArgument`s that correspond to the
defaults. LLDB does know whether a particular template argument was
defaulted, but can't currently tell clang about it.

This patch allows LLDB to set the defaulted-ness of a `TemplateArgument`
and thus benefit more from `clang::TypePrinter`.

See discussion in https://reviews.llvm.org/D140423

**Testing**

* Added unit-test
* LLDB/clang/llvm test-suite passes

Differential Revision: https://reviews.llvm.org/D141826
2023-01-27 02:24:33 +00:00
Dominik Adamski
ca446037af [OpenMP][OMPIRBuilder]Move SIMD alignment calculation to LLVM Frontend
Currently default simd alignment is defined by Clang specific TargetInfo class.
This class cannot be reused for LLVM Flang. That's why default simd alignment
calculation has been moved to OMPIRBuilder which is common for Flang and Clang.

Previous attempt: https://reviews.llvm.org/D138496 was wrong because
the default alignment depended on the number of built LLVM targets.

If we wanted to calculate the default alignment for PPC and we hadn't specified
PPC LLVM target to build, then we would get 0 as the alignment because
OMPIRBuilder couldn't create PPCTargetMachine object and it returned 0 as
the default value.

If PPC LLVM target had been built earlier, then OMPIRBuilder could have created
PPCTargetMachine object and it would have returned 128.

Differential Revision: https://reviews.llvm.org/D141910

Reviewed By: jdoerfert
2023-01-26 15:10:19 -06:00
Mariya Podchishchaeva
d4f4b2fe21 [clang] Fix sizeof of boolean vector
Ensure it is at least 8 bits.

Fixes #59801

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D142550
2023-01-26 10:44:15 -05:00
Dana Jansens
8bb54da5da Allow getRawCommentForDecl to find comments in macros
The key part of getRawCommentForDecl() required to find a comment
is determining where to look for it. The location of the decl
itself is usually right, except when macros get involved. The
comment in the macro is stored in RawCommentList at the spelling
location of the decl, not at the place where the decl comes into
being as the macro is instantiated.

getDeclLocForCommentSearch() already contained to branches to try
handle comments inside macros, and we are able to replace them
and handle more cases as well, by returning the spelling location
of the decl's begin location. That is:
  SourceMgr.getSpellingLoc(D->getBeginLoc())

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D142560
2023-01-26 10:12:57 +01:00