12600 Commits

Author SHA1 Message Date
Theo de Magalhaes
3ca2fa704e
[CLANG][MS-STRUCT] bitfield padding warning presents padding to exact bit count (#136062)
Aims to fix #131647.
2025-04-21 15:25:14 -07:00
Owen Anderson
6d765e1c91
Reapply 19c708c "FunctionDecl::getFunctionTypeLoc: ignore function type attributes (#118420)" (#136484)
Avoid using PreservesMost in the testcase as it is not supported on all
targets.

Original PR #118290.

Co-authored-by: Robert Dazi <14996868+v01dXYZ@users.noreply.github.com>
Co-authored-by: v01dxyz <v01dxyz@v01d.xyz>
2025-04-22 10:23:27 +12:00
Kazu Hirata
02b55d2b78
[AST] Call hash_combine_range with a range (NFC) (#136525) 2025-04-20 19:59:19 -07:00
Timm Baeder
ea3eb8d625
[clang][bytecode] Fix bos/bdos with non-zero offset applied (#136482)
Compute the offset from the record layout.
Unfortunately, not all the test cases from the current interpreter work.
2025-04-20 20:12:47 +02:00
Timm Baeder
90c845fb3b
[clang][bytecode] Start implementing __builtin_{,dynamic}_object_size (#136478) 2025-04-20 12:20:21 +02:00
Kazu Hirata
f2ec5e40d9
[clang] Use llvm::unique (NFC) (#136469) 2025-04-19 20:33:53 -07:00
Kazu Hirata
c2d6c7cea7
[clang] Use llvm::append_range (NFC) (#136448) 2025-04-19 12:21:14 -07:00
Kazu Hirata
0ed1c9862d
[clang] llvm::append_range (NFC) (#136440) 2025-04-19 10:37:25 -07:00
Timm Baeder
6196b4ee8c
[clang][bytecode] Don't set OnePastEnd bit for array elements (#136422)
If we refer to arr[N], don't set the OnePastEnd bit of the APValue,
since that is already encoded in the array index.
2025-04-19 16:48:49 +02:00
Owen Anderson
a15ef95de4 Revert "FunctionDecl::getFunctionTypeLoc: ignore function type attributes (#118420)"
This reverts commit 19c708c18963ac24822564824cb5401e71a49943 because it caused test failures on non-x86 targets.
2025-04-20 00:01:53 +12:00
Robert Dazi
19c708c189
FunctionDecl::getFunctionTypeLoc: ignore function type attributes (#118420)
Related to #118290.

---------

Co-authored-by: v01dxyz <v01dxyz@v01d.xyz>
Co-authored-by: Owen Anderson <resistor@mac.com>
2025-04-19 23:39:18 +12:00
Timm Baeder
f91df0d58d
[clang][bytecode] Diagnose failed MemberPtrPtr casts differently (#136407)
Return Invalid() here instead of just false to match the diagnostic
output of the current interpreter.
2025-04-19 11:34:25 +02:00
Dan Liew
59eafd1bdc
[BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (#106321)
Previously using the `counted_by` or `counted_by_or_null` attribute on a
pointer with an incomplete pointee type was forbidden. Unfortunately
this prevented a situation like the following from being allowed.

Header file:

```
struct EltTy; // Incomplete type
struct Buffer {
  size_t count;
  struct EltTy* __counted_by(count) buffer; // error before this patch
};
```

Implementation file:

```
struct EltTy {
  // definition
};

void allocBuffer(struct Buffer* b) {
  b->buffer = malloc(sizeof(EltTy)* b->count);
}
```

To allow code like the above but still enforce that the pointee
type size is known in locations where `-fbounds-safety` needs to
emit bounds checks the following scheme is used.

* For incomplete pointee types that can never be completed (e.g. `void`)
  these are treated as error where the attribute is written (just like
  before this patch).
* For incomplete pointee types that might be completable later on
  (struct, union, and enum forward declarations)
  in the translation unit, writing the attribute on the incomplete
  pointee type is allowed on the FieldDecl declaration but "uses" of the
  declared pointer are forbidden if at the point of "use" the pointee
  type is still incomplete.

For this patch a "use" of a FieldDecl covers:

* Explicit and Implicit initialization (note see **Tentative Definition
  Initialization** for an exception to this)
* Assignment
* Conversion to an lvalue (e.g. for use in an expression)

In the swift lang fork of Clang the `counted_by` and
`counted_by_or_null` attribute are allowed in many more contexts. That
isn't the case for upstream Clang so the "use" checks for the attribute
on VarDecl, ParamVarDecl, and function return type have been omitted
from this patch because they can't be tested. However, the
`BoundsSafetyCheckAssignmentToCountAttrPtrWithIncompletePointeeTy` and
`BoundsSafetyCheckUseOfCountAttrPtrWithIncompletePointeeTy` functions
retain the ability to emit diagnostics for these other contexts to avoid
unnecessary divergence between upstream Clang and Apple's internal fork.
Support for checking "uses" will be upstreamed when upstream Clang
allows the `counted_by` and `counted_by_or_null` attribute in additional
contexts.

This patch has a few limitations:

** 1. Tentative Defition Initialization **

This patch currently allows something like:

```
struct IncompleteTy;
struct Buffer {
  int count;
  struct IncompleteTy* __counted_by(count) buf;
};

// Tentative definition
struct Buffer GlobalBuf;
```

The Tentative definition in this example becomes an actual definition
whose initialization **should be checked** but it currently isn't.
Addressing this problem will be done in a subseqent patch.

** 2. When the incomplete pointee type is a typedef diagnostics are slightly misleading **

For this situation:

```

struct IncompleteTy;
typedef struct IncompleteTy Incomplete_t;

struct Buffer {
  int count;
  struct IncompleteTy* __counted_by(count) buf;
};

void use(struct Buffer b) {
  b.buf = 0x0;
}
```

This code emits `note: forward declaration of 'Incomplete_t' (aka
'struct IncompleteTy')` but the location is on the `struct
IncompleteTy;` forward declaration.  This is misleading because
`Incomplete_t` isn't actually forward declared there (instead the
underlying type is). This could be resolved by additional diagnostics
that walk the chain of typedefs and explain each step of the walk.
However, that would be very verbose and didn't seem like a direction
worth pursuing.

rdar://133600117
2025-04-18 15:26:04 -07:00
Erich Keane
d1cce66469
[OpenACC] Switch Clang to use the Flang 'appertainment' rules for cla… (#135372)
…uses

The Flang implemenation of OpenACC uses a .td file in the llvm/Frontend
directory to determine appertainment in 4 categories:

-Required: If this list has items in it, the directive requires at least
1 of these be present.

-AllowedExclusive: Items on this list are all allowed, but only 1 from
the list may be here (That is, they are exclusive of eachother).

-AllowedOnce: Items on this list are all allowed, but may not be
duplicated.

Allowed: Items on this list are allowed. Note th at the actual list of
'allowed' is all 4 of these lists together.

This is a draft patch to swtich Clang over to use those tables. Surgery
to get this to happen in Clang Sema was somewhat reasonable. However,
some gaps in the implementations are obvious, the existing clang
implementation disagrees with the Flang interpretation of it. SO, we're
keeping a task list here based on what gets discovered.

Changes to Clang:
- [x] Switch 'directive-kind' enum conversions to use tablegen See
ff1a7bddd9435b6ae2890c07eae60bb07898bbf5
- [x] Switch 'clause-kind' enum conversions to use tablegen See
ff1a7bddd9435b6ae2890c07eae60bb07898bbf5
- [x] Investigate 'parse' test differences to see if any new
disagreements arise.
- [x] Clang/Flang disagree as to whether 'collapse' can be multiple
times on a loop. Further research showed no prose to limit this, and the
comment on the clang implementation said "no good reason to allow", so
no standards justification.
- [x] Clang/Flang disagree whether 'num_gangs' can appear >1 on a
compute/combined construct. This ended up being an unjustified
restriction.
- [x] Clang/Flang disagree as to the list of required clauses on a 'set'
construct. My research shows that Clang mistakenly included 'if' in the
list, and that it should be just 'default_async', 'device_num', and
'device_type'.
- [x] Order of 'at least one of' diagnostic has changed. Tests were
updated.
- [x] Ensure we are properly 'de-aliasing' clause names in appertainment
checks?
- [x] What is 'shortloop'? 'shortloop' seems to be an old non-standard
extension that isn't supported by flang, but is parsed for backward
compat reasons. Clang won't parse, but we at least have a spot for it in
the clause list.
- [x] Implemented proposed change for 'routine' gang/worker/vector/seq.
(see issue 539)
- [x] Implement init/shutdown can only have 1 'if' (see issue 540)
- [x] Clang/Flang disagree as to whether 'tile' is permitted more than
once on a 'loop' or combined constructs (Flang prohibits >1). I see no
justification for this in the standard. EDIT: I found a comment in clang
that I did this to make SOMETHING around duplicate checks easier.
Discussion showed we should actually have a better behavior around
'device_type' and duplicates, so I've since implemented that.
- [x] Clang/Flang disagree whether 'gang', 'worker', or 'vector' may
appear on the same construct as a 'seq' on a 'loop' or 'combined'. There
is prose for this in 2022: (a gang, worker, or vector clause may not
appear if a 'seq' clause appears). EDIT: These don't actually disagree,
but aren't in the .td file, so I restored the existing code to do this.
- [x] Clang/Flang disagree on whether 'bind' can appear >1 on a
'routine'. I believe line 3096 (A bind clause may not bind to a routine
name that has a visible bind clause) makes this limitation (Flang
permits >1 bind). we discussed and decided this should have the same
rules as worker/vector/etc, except without the 'exactly 1 of' rule (so
no dupes in individual sections).
- [x] Clang/Flang disagree on whether 'init'/'shutdown' can have
multiple 'device_num' clauses. I believe there is no supporting prose
for this limitation., We decided that `device_num` should only happen
1x.
- [x] Clang/Flang disagree whether 'num_gangs' can appear >1 on a
'kernels' construct. Line 1173 (On a kernels construct, the num_gangs
clause must have a single argument) justifies limiting on a
per-arguement basis, but doesn't do so for multiple num_gangs clauses.
WE decided to do this with the '1-per-device-type' region for num_gangs,
num_workers, and vector_length, see openacc bug here:
https://github.com/OpenACC/openacc-spec/issues/541

Changes to Flang:
- [x] Clang/Flang disgree on whether 'atomic' can take an 'if' clause.
This was added in OpenACC3.3_Next See #135451
- [x] Clang/Flang disagree on whether 'finalize' can be allowed >1 times
on a 'exit_data' construct. see #135415.
- [x] Clang/Flang disagree whether 'if_present' should be allowed >1
times on a 'host_data'/'update' construct. see #135422
- [x] Clang/Flang disagree on whether 'init'/'shutdown' can have
multiple 'device_type' clauses. I believe there is no supporting prose
for this limitation.
- [ ] SEE change for num_gangs/etc above.


Changes that need discussion/research:
2025-04-18 14:54:21 -07:00
Erich Keane
f5947ba5a6
Revert "[clang] Handle instantiated members to determine visibility" (#136317)
Reverts llvm/llvm-project#136128

See discussion here:
https://github.com/llvm/llvm-project/pull/136128#issuecomment-2815648110
and :
https://github.com/llvm/llvm-project/pull/136128#issuecomment-2815652846

@asavonic can re-submit once the examples provided by @jplehr and/or
@DKLoehr are fixed.
2025-04-18 10:06:52 -07:00
Andrew Savonichev
a8fe21f3f5
[clang] Handle instantiated members to determine visibility (#136128)
As reported in issue #103477, visibility of instantiated member
functions used to be ignored when calculating visibility of a
specialization.

This patch modifies `getLVForClassMember` to look up for a source
template for an instantiated member, and changes `mergeTemplateLV` to
apply it.

A similar issue was reported in #31462, but it seems that `extern`
declaration with visibility prevents the function from being emitted as
hidden. This behavior seems correct, even though GCC emits it as with
default visibility instead.

Both tests from #103477 and #31462 are added as LIT tests `test72` and
`test73` respectively.
2025-04-18 20:29:19 +09:00
Timm Baeder
c5d59723cb
[clang][bytecode] Reject constexpr-unknown values in CheckStore (#136279) 2025-04-18 12:48:16 +02:00
Harald van Dijk
ca9ec7dfc3
[ARM, AArch64] Fix passing of structures with aligned base classes (#135564)
RecordLayout::UnadjustedAlignment was documented as "Maximum of the
alignments of the record members in characters", but
RecordLayout::getUnadjustedAlignment(), which just returns
UnadjustedAlignment, was documented as getting "the record alignment in
characters, before alignment adjustement." These are not the same thing:
the former excludes alignment of base classes, the latter takes it into
account. ItaniumRecordLayoutBuilder::LayoutBase was setting it according
to the former, but the AAPCS calling convention handling, currently the
only user, relies on it being set according to the latter.

Fixes #135551.
2025-04-18 02:11:02 +01:00
Matheus Izvekov
209d8c8fa4
[clang] fix unresolved dependent template specialization mangling (#136201)
This fixes a regression introduced in #133610 which was reported here
#133610 (comment) and in #136119

This redoes previous attempt in #135111

When mangling a DTST which appears in the prefix,
the template name is not actually relevant, as its prefix is part of the
nested name anyway, and a
substitution is not allowed at that position in any case.

Fixes #136119
2025-04-17 18:40:18 -03:00
Timm Baeder
70e2acf0c5
[clang][bytecode] Check if operator delete calls are in the right frame (#136141)
This is only permitted in a std::allocator::deallocate frame.
2025-04-17 17:30:22 +02:00
Timm Baeder
ecbd2d5e14
[clang][ExprConst] Diagnose ptr subs with non-zero offset (#135938)
The attached test case was missing the note.
2025-04-17 17:27:19 +02:00
yronglin
d83b639b4c
Reland [clang] Unify SourceLocation and IdentifierInfo* pair-like data structures to IdentifierLoc (#136077)
This PR reland https://github.com/llvm/llvm-project/pull/135808, fixed
some missed changes in LLDB.
I found this issue when I working on
https://github.com/llvm/llvm-project/pull/107168.

Currently we have many similiar data structures like:
- std::pair<IdentifierInfo *, SourceLocation>.
- Element type of ModuleIdPath.
- IdentifierLocPair.
- IdentifierLoc.

This PR unify these data structures to IdentifierLoc, moved
IdentifierLoc definition to SourceLocation.h, and deleted other similer
data structures.

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
2025-04-17 22:40:47 +08:00
Mariya Podchishchaeva
40417915a1
[clang] Implement StmtPrinter for EmbedExpr (#135957)
Tries to avoid memory leaks previously caused by saving filename by
allocating memory in the preprocessor.

Fixes https://github.com/llvm/llvm-project/issues/132641
Fixes https://github.com/llvm/llvm-project/issues/107869

---------

Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2025-04-17 15:15:07 +02:00
Tom Honermann
0348ff5158
[SYCL] Basic code generation for SYCL kernel caller offload entry point functions. (#133030)
A function declared with the `sycl_kernel_entry_point` attribute,
sometimes called a SYCL kernel entry point function, specifies a pattern
from which the parameters and body of an offload entry point function,
sometimes called a SYCL kernel caller function, are derived.

SYCL kernel caller functions are emitted during SYCL device compilation.
Their parameters and body are derived from the `SYCLKernelCallStmt`
statement and `OutlinedFunctionDecl` declaration associated with their
corresponding SYCL kernel entry point function. A distinct SYCL kernel
caller function is generated for each SYCL kernel entry point function
defined as a non-inline function or ODR-used in the translation unit.

The name of each SYCL kernel caller function is parameterized by the
SYCL kernel name type specified by the `sycl_kernel_entry_point`
attribute attached to the corresponding SYCL kernel entry point
function. For the moment, the Itanium ABI mangled name for typeinfo data
(`_ZTS<type>`) is used to name these functions; a future change will
switch to a more appropriate naming scheme.

The calling convention used for a SYCL kernel caller function is target
dependent. Support for AMDGCN, NVPTX, and SPIR targets is currently
provided. These functions are required to observe the language
restrictions for SYCL devices as specified by the SYCL 2020
specification; this includes a forward progress guarantee and prohibits
recursion.

Only SYCL kernel caller functions, functions declared as
`SYCL_EXTERNAL`, and functions directly or indirectly referenced from
those functions should be emitted during device compilation. Pruning of
other declarations has not yet been implemented.

---------

Co-authored-by: Elizabeth Andrews <elizabeth.andrews@intel.com>
2025-04-17 09:14:45 -04:00
Timm Baeder
fb00fa56b5
[clang] Implement dump() for MemberPointer APValues (#136130)
Print the member pointer decl and the path.
2025-04-17 14:52:23 +02:00
Timm Baeder
51295d6d56
[clang][bytecode] Reject assignments in C (#136126)
Similar to what the current interpreter does.
2025-04-17 13:39:27 +02:00
Timm Baeder
90ddb54440
[clang][bytecode] Enter a non-constant context when revisiting (#136104)
Otherwise, things like __builtin_is_constant_evaluated() return the
wrong value.
2025-04-17 12:50:28 +02:00
Timm Baeder
adba24aa3c
[clang][bytecode] Add missing __builtin_memcpy checks (#135975)
Add a test for type punning and tests and the necessary checks for
non-trivially-copyable types and incomplete types.
2025-04-17 06:19:37 +02:00
Matheus Izvekov
fe94f11407
[clang] Fix elaborated keyword canonicalization (#135916) 2025-04-16 16:27:24 -03:00
Timm Baeder
ab7e0c0fc0
[clang][bytecode] Implement __builtin_wmem{cpy,move} (#135969) 2025-04-16 17:08:10 +02:00
Michael Buch
99c08ff1cb
Revert "[clang] Unify SourceLocation and IdentifierInfo* pair-like data structures to IdentifierLoc" (#135974)
Reverts llvm/llvm-project#135808

Example from the LLDB macOS CI:
https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/24084/execution/node/54/log/?consoleFull
```
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/lldb/source/Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.cpp:360:49: error: no viable conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'clang::ModuleIdPath' (aka 'ArrayRef<IdentifierLoc>')
  clang::Module *top_level_module = DoGetModule(clang_path.front(), false);
                                                ^~~~~~~~~~~~~~~~~~
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:41:40: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'const llvm::ArrayRef<clang::IdentifierLoc> &' for 1st argument
  class LLVM_GSL_POINTER [[nodiscard]] ArrayRef {
                                       ^
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:41:40: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'llvm::ArrayRef<clang::IdentifierLoc> &&' for 1st argument
/Users/ec2-user/jenkins/workspace/llvm.org/as-lldb-cmake/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:70:18: note: candidate constructor not viable: no known conversion from 'std::pair<clang::IdentifierInfo *, clang::SourceLocation>' to 'std::nullopt_t' for 1st argument
    /*implicit*/ ArrayRef(std::nullopt_t) {}
```
2025-04-16 17:05:53 +02:00
yronglin
d3153ad66c
[clang] Unify SourceLocation and IdentifierInfo* pair-like data structures to IdentifierLoc (#135808)
I found this issue when I working on
https://github.com/llvm/llvm-project/pull/107168.

Currently we have many similiar data structures like:
 - `std::pair<IdentifierInfo *, SourceLocation>`.
 - Element type of `ModuleIdPath`.
 - `IdentifierLocPair`.
 - `IdentifierLoc`.
 
This PR unify these data structures to `IdentifierLoc`, moved
`IdentifierLoc` definition to SourceLocation.h, and deleted other
similer data structures.

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
2025-04-16 20:53:25 +08:00
Timm Baeder
38ca73db22
[clang][bytecode] Give typeinfo APValues an LValuePath (#135948)
That's what the current interpreter does as well.
2025-04-16 13:37:03 +02:00
Timm Baeder
2d63faead4
[clang][bytecode][NFC] Remove PT_FnPtr (#135947)
We don't need this anymore since we don't return it from classify()
anymore.
2025-04-16 13:21:25 +02:00
Timm Baeder
559df834df
[clang][bytecode] Fix subtracting zero-sized pointers (#135929)
Add the appropriate diagnostic and fix the d-d case.
2025-04-16 10:48:42 +02:00
Timm Baeder
05eafd9f2b
[clang][bytecode] Explicitly mark constexpr-unknown variables as such (#135806)
Instead of trying to figure out what's constexpr-unknown later on.
2025-04-16 09:00:52 +02:00
Matheus Izvekov
2a02404621
[clang] fix a crash in error recovery in expressions resolving to templates (#135893)
We were using AssumedTemplate incorrectly for error recovery.

Fixes #135621
2025-04-16 02:09:32 -03:00
Aaron Puchert
9c73eba8aa
Merge similar Clang Thread Safety attributes (#135561)
Some of the old lock-based and new capability-based spellings behave
basically in the same way, so merging them simplifies the code
significantly.

There are two minor functional changes: we only warn (instead of an
error) when the try_acquire_capability attribute is used on something
else than a function. The alternative would have been to produce an
error for the old spelling, but we seem to only warn for all function
attributes, so this is arguably more consistent.

The second change is that we also check the first argument (which is the
value returned for a successful try-acquire) for `this`. But from what I
can tell, this code is defunct anyway at the moment (see #31414).
2025-04-15 23:21:34 +02:00
Akira Hatanaka
a3283a92ae
[PAC] Add support for __ptrauth type qualifier (#100830)
The qualifier allows programmer to directly control how pointers are
signed when they are stored in a particular variable.

The qualifier takes three arguments: the signing key, a flag specifying
whether address discrimination should be used, and a non-negative
integer that is used for additional discrimination.

```
typedef void (*my_callback)(const void*);
my_callback __ptrauth(ptrauth_key_process_dependent_code, 1, 0xe27a) callback;
```

Co-Authored-By: John McCall rjmccall@apple.com
2025-04-15 12:54:25 -07:00
Nathan Ridge
289baf1f42
[clang][AST] Handle implicit first argument in CallExpr::getBeginLoc() (#135757)
Fixes https://github.com/llvm/llvm-project/issues/135522
2025-04-15 12:04:35 -04:00
YLChenZ
9a6c001b12
[clang][ast]: Add DynamicAllocLValue and TypeInfoLValue support to APValue::dump(). (#135178)
Closes #134996.
The crash about `TypeInfoLValue` is https://godbolt.org/z/73WY31s55. 
After the patch:
```cpp
//test.cpp
#include <typeinfo>
constexpr const std::type_info* val = &typeid(int);
```
```
lambda@ubuntu22:~/test$ clang++ -std=c++20 -Xclang -ast-dump -fsyntax-only test.cpp
LValue Base=TypeInfoLValue typeid(int), Null=0, Offset=0, HasPath=1, PathLength=0, Path=()
```

```cpp
//DAtest.cpp
constexpr int *m = new int(42);
```
```
lambda@ubuntu22:~/test$ clang++ -std=c++20 -Xclang -ast-dump -fsyntax-only DAtest.cpp
LValue Base=DynamicAllocLValue 'int', Null=0, Offset=0, HasPath=1, PathLength=0, Path=()
```
2025-04-15 14:16:09 +02:00
Matheus Izvekov
fceb9cecdf
[clang] consistently quote expressions in diagnostics (#134769) 2025-04-15 04:18:23 -03:00
Theo de Magalhaes
41892fc435
[CLANG-CL] ignores Wpadded (#134426)
[clang] add support for -Wpadded on Windows

Implements the -Wpadded warning for --target=x86_64-windows-msvc etc.

Fixes #61702 .
2025-04-14 14:17:49 -07:00
Matheus Izvekov
13b55ad3bb
[clang] implement printing of canonical expressions (#135133)
This patch extends the canonicalization printing policy to cover
expressions
and template names, and wires that up to the template argument printer,
covering expressions, and to the expression within a dependent decltype.

This is helpful for debugging, or if these expressions somehow end up
in diagnostics, as without this patch they can print as completely
unrelated
expressions, which can be quite confusing.

This is because expressions are not uniqued, unlike types, and
when a template specialization containing an expression is the first to
be
canonicalized, the expression ends up appearing in the canonical type of
subsequent equivalent specializations.

Fixes https://github.com/llvm/llvm-project/issues/92292
2025-04-14 12:59:36 -03:00
Matheus Izvekov
10a1502421
[clang] AST: remove source locations from [Variable/Dependent]SizedArrayType (#135511) 2025-04-14 10:44:25 -03:00
Mariya Podchishchaeva
88d0b0835d
[MS][clang] Revert vector deleting destructors support (#135611)
Finding operator delete[] is still problematic, without it the extension
is a security hazard, so reverting until the problem with operator
delete[] is figured out.

This reverts the following PRs:
Reland [MS][clang] Add support for vector deleting destructors (llvm#133451)
[MS][clang] Make sure vector deleting dtor calls correct operator delete (llvm#133950)
[MS][clang] Fix crash on deletion of array of pointers (llvm#134088)
[clang] Do not diagnose unused deleted operator delete[] (llvm#134357)
[MS][clang] Error about ambiguous operator delete[] only when required (llvm#135041)
2025-04-14 14:17:36 +02:00
Timm Baeder
974bda8f61
[clang][bytecode] Reject constexpr-unknown pointers from Inc ops (#135548)
We used to accept c++ as a known value here, causing wrong codegen.
2025-04-13 18:57:55 +02:00
Timm Baeder
578ca5e469
[clang][bytecode] Print jump lines in Function::dump() (#135482)
E.g. for
```c++
constexpr int foo(int b) {
  int a = 1+1;

  for (int i = 0; i < b; ++i) {
    ++a;
  }
  return a;
}
```

we now print:
```
foo 0x7cc8d4bf0580
frame size: 128
arg size:   8
rvo:        0
this arg:   0
0      InitScope         0
16     ConstSint32       1
32     ConstSint32       1
48     AddSint32
56     SetLocalSint32    40
72     ConstSint32       0
88     SetLocalSint32    104
104    GetPtrLocal       104         <-+
120    LoadPopSint32                   |
128    GetPtrParam       0             |
144    LoadPopSint32                   |
152    LTSint32                        |
160    Jf                80     --+    |
176    GetPtrLocal       40       |    |
192    IncPopSint32      1        |    |
208    GetPtrLocal       104      |    |
224    IncPopSint32      1        |    |
240    Jmp               -152     |  --+
256    GetPtrLocal       40     <-+
272    LoadPopSint32
280    Destroy           0
296    RetSint32
304    Destroy           0
320    NoRet
```
2025-04-13 15:46:01 +02:00
Timm Baeder
09588e93bb
[clang][bytecode] Fix an inconsistency with loop condition jumps (#135530)
When emitting the jump for e.g. a for loop condition, we used to jump
out of the CondScope, leaving the scope initialized, because we skipped
the corresponding Destroy opcode. If that loop was in a loop itself,
that outer loop could then iterate once more, leading to us initializing
a scope that was still initialized.
Fix this by also destroying the scope after the EndLabel.
2025-04-13 12:25:29 +02:00
Matheus Izvekov
761787d425
Reland: [clang] Improved canonicalization for template specialization types (#135414)
This relands https://github.com/llvm/llvm-project/pull/135119, after
fixing crashes seen in LLDB CI reported here:
https://github.com/llvm/llvm-project/pull/135119#issuecomment-2794910840

Fixes https://github.com/llvm/llvm-project/pull/135119

This changes the TemplateArgument representation to hold a flag
indicating whether a tempalte argument of expression type is supposed to
be canonical or not.

This gets one step closer to solving
https://github.com/llvm/llvm-project/issues/92292

This still doesn't try to unique as-written TSTs. While this would
increase the amount of memory savings and make code dealing with the AST
more well-behaved, profiling template argument lists is still too
expensive for this to be worthwhile, at least for now.

This also fixes the context creation of TSTs, so that they don't in some
cases get incorrectly flagged as sugar over their own canonical form.
This is captured in the test expectation change of some AST dumps.

This fixes some places which were unnecessarily canonicalizing these
TSTs.
2025-04-12 14:26:30 -03:00