12557 Commits

Author SHA1 Message Date
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
Matheus Izvekov
6aae1047b6
[clang] ASTImporter: fix SubstNonTypeTemplateParmExpr source location (#135450)
This makes it clear which source location is imported.
2025-04-11 20:18:16 -03:00
Matheus Izvekov
7113aece4e
[clang] ItaniumMangle: fix mangling for unresolved types (#135312) 2025-04-11 11:31:26 -03:00
Dmitry Vasilyev
cbba9600ae
Revert "[clang] Improved canonicalization for template specialization types" (#135354)
Reverts llvm/llvm-project#135119 because of the assert in ASTContext.cpp, line 5619.
See #135352 for details.
2025-04-11 17:55:11 +04:00
Timm Baeder
fafeaab6d9
[clang][bytecode] Misc TypeidPointer fixes (#135322)
Fix comparing type id pointers, add mor info when print()ing them, use
the most derived type in GetTypeidPtr() and the canonically unqualified
type when we know the type statically.
2025-04-11 10:35:28 +02:00
Oliver Hunt
1cd59264aa
[RFC] Initial implementation of P2719 (#113510)
This is a basic implementation of P2719: "Type-aware allocation and
deallocation functions" described at http://wg21.link/P2719

The proposal includes some more details but the basic change in
functionality is the addition of support for an additional implicit
parameter in operators `new` and `delete` to act as a type tag. Tag is
of type `std::type_identity<T>` where T is the concrete type being
allocated. So for example, a custom type specific allocator for `int`
say can be provided by the declaration of

  void *operator new(std::type_identity<int>, size_t, std::align_val_t);
  void  operator delete(std::type_identity<int>, void*, size_t, std::align_val_t);

However this becomes more powerful by specifying templated declarations,
for example

template <typename T> void *operator new(std::type_identity<T>, size_t, std::align_val_t);
template <typename T> void operator delete(std::type_identity<T>, void*, size_t, std::align_val_t););

Where the operators being resolved will be the concrete type being
operated over (NB. A completely unconstrained global definition as above
is not recommended as it triggers many problems similar to a general
override of the global operators).

These type aware operators can be declared as either free functions or
in class, and can be specified with or without the other implicit
parameters, with overload resolution performed according to the existing
standard parameter prioritisation, only with type parameterised
operators having higher precedence than non-type aware operators. The
only exception is destroying_delete which for reasons discussed in the
paper we do not support type-aware variants by default.
2025-04-10 17:13:10 -07:00
Matheus Izvekov
3954d258a5
[clang] Improved canonicalization for template specialization types (#135119)
This changes the TemplateArgument representation to hold a flag
indicating whether a template 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. Without this
uniquing, this patch stands neutral in terms of performance impact.

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-10 14:23:02 -03:00
Nathan Gauër
a625bc60e2
[HLSL][SPIR-V] Add hlsl_private address space for SPIR-V (#133464)
This is an alternative to
https://github.com/llvm/llvm-project/pull/122103

In SPIR-V, private global variables have the Private storage class. This
PR adds a new address space which allows frontend to emit variable with
this storage class when targeting this backend.

This is covered in this proposal: llvm/wg-hlsl@4c9e11a

This PR will cause addrspacecast to show up in several cases, like class
member functions or assignment. Those will have to be handled in the
backend later on, particularly to fixup pointer storage classes in some
functions.

Before this change, global variable were emitted with the 'Function'
storage class, which was wrong.
2025-04-10 10:55:10 +02:00
Timm Baeder
02f923f8e4
[clang][bytecode] Classify function pointers as PT_Ptr (#135026)
The Pointer class already has the capability to be a function pointer,
but we still classifed function pointers as PT_FnPtr/FunctionPointer.
This means when converting from a Pointer to a FunctionPointer, we lost
the information of what the original Pointer pointed to.
2025-04-10 06:40:54 +02:00
Timm Baeder
98ea512f72
[clang][bytecode] Clear inactive union fields when copying (#134982)
When copying unions, we need to only copy the active field of the source
union, which we were already doing. However, we also need to zero out
the (now) inactive fields, so we don't end up with dangling pointers in
those inactive fields.
2025-04-10 06:12:00 +02:00
Matheus Izvekov
98feb05825
[clang] fix unresolved dependent template specialization mangling (#135111)
This fixes a regression introduced in
https://github.com/llvm/llvm-project/pull/133610 which was reported here
https://github.com/llvm/llvm-project/pull/133610#issuecomment-2787332042

When mangling a dependent template specialization appearing within an
unresolved prefix, translate the dtst back to a dependent template name
including the prefix, and mangle following the nested unresolved-type
production.

There are no release notes, since this regression was never released.
2025-04-09 23:23:52 -03:00
Matheus Izvekov
154507cf40
[clang] fix NestedNameSpecifier dependency calculation (#135067)
A NestedNameSpecifier of TypeSpec kind can be non-dependent even if its
prefix is dependent, when for example the prefix is an injected class
type but the type itself is a simple alias to a non-dependent type.

This issue was a bit hard to observe because if it is an alias to a
class type, then we (for some unknown reason) ignored that the NNS was
dependent in the first place, which wouldn't happen with an enum type.

This could have been a workaround for previous dependency bugs, and is
not relevant anymore for any of the test cases in the tree, so this
patch also removes that.

The other kinds of dependencies are still relevant. If the prefix
contains an unexpanded pack, then this NNS is still unexpanded, and
likewise for errors.

This fixes a regression reported here:
https://github.com/llvm/llvm-project/pull/133610#issuecomment-2787909829
which was introduced by https://github.com/llvm/llvm-project/pull/133610

There are no release notes since the regression was never released.
2025-04-09 19:44:40 -03:00
Timm Baeder
78c86b38b0
[clang][bytecode][NFC] Avoid implicit integer conversion (#134983)
See discussion in https://github.com/llvm/llvm-project/pull/134672
2025-04-09 13:44:24 +02:00
Erich Keane
231aa3070d
[OpenACC][CIR] Basic infrastructure for OpenACC lowering (#134717)
This is the first of a few patches that will do infrastructure work to
enable the OpenACC lowering via the OpenACC dialect.

At the moment this just gets the various function calls that will end up
generating OpenACC, plus some tests to validate that we're doing the
diagnostics in OpenACC specific locations.

Additionally, this adds Stmt and Decl files for CIRGen.
2025-04-08 10:06:28 -07:00
Aniket Lal
642481a428
[Clang][OpenCL][AMDGPU] Allow a kernel to call another kernel (#115821)
This feature is currently not supported in the compiler.
To facilitate this we emit a stub version of each kernel
function body with different name mangling scheme, and
replaces the respective kernel call-sites appropriately.
    
Fixes https://github.com/llvm/llvm-project/issues/60313
    
D120566 was an earlier attempt made to upstream a solution
for this issue.

---------

Co-authored-by: anikelal <anikelal@amd.com>
2025-04-08 10:29:30 +05:30
Timm Baeder
65cede26a6
[clang][bytecode] Fix emitting dtors of zero-sized arrays (#134672)
Desc->getNumElems() returning 0 made us underflow here.
2025-04-08 06:09:21 +02:00
Timm Baeder
fb9915a391
[clang][bytecode] Fix emitDestruction() for dummy descriptors (#134665)
This might happen if the referenced declaration is invalid and thus gets
a dummy descriptor. We ran into an assertion later on.
2025-04-08 06:00:35 +02:00
Timm Baeder
bdd087023f
[clang][bytecode] Fix various issues with multidimensional arrays (#134628)
This issue is very convoluted, but in essence, in the new version:

For a Pointer P that points to the root of a multidimensional, primitive
array:

`P.narrow()` does nothing.
`P.atIndex(0)` points `P[0]`
`P.atIndex(0).atIndex(0)` is the same as `P.atIndex(0)` (as before)
`P.atIndex(0).narrow().atIndex(0)` points to `P[0][0]`
`P.atIndex(0).narrow().narrow()` is the same as `P.atIndex(0).narrow()`.
2025-04-08 05:48:55 +02:00
Matheus Izvekov
d057811655
[clang] fix diagnostic printing of expressions ignoring LangOpts (#134693)
Currently when printing a template argument of expression type, the
expression is converted immediately into a string to be sent to the
diagnostic engine, unsing a fake LangOpts.

This makes the expression printing look incorrect for the current
language, besides being inneficient, as we don't actually need to print
the expression if the diagnostic would be ignored.

This fixes a nastiness with the TemplateArgument constructor for
expressions being implicit, and all current users just passing an
expression to a diagnostic were implicitly going through the template
argument path.

The expressions are also being printed unquoted. This will be fixed in a
subsequent patch, as the test churn is much larger.
2025-04-07 23:19:32 -03:00
Matheus Izvekov
954ccee5d5
[clang] fix partial ordering of NTTP packs (#134461)
This fixes partial ordering of pack expansions of NTTPs, by procedding
with the check using the pattern of the NTTP through the rules of the
non-pack case.

This also unifies almost all of the different versions of
FinishTemplateArgumentDeduction (except the function template case).
This makes sure they all follow the rules consistently, instantiating
the parameters and comparing those with the argument.

Fixes #132562
2025-04-07 12:30:51 -03:00
Matheus Izvekov
aef000dd43
[clang] fix serialization of SubstNonTypeTemplateParmExpr (#134560)
This fixes a couple of mistakes introduced when merging
https://github.com/llvm/llvm-project/pull/132748

Fixes msan failure reported here:
https://github.com/llvm/llvm-project/pull/132748#issuecomment-2781105225
2025-04-06 21:57:20 -03:00
erichkeane
6263de90df [OpenACC] Implement 'modifier-list' sema/AST
OpenACC 3.3-NEXT has changed the way tags for copy, copyin, copyout, and
create clauses are specified, and end up adding a few extras, and
permits them as a list.  This patch encodes these as bitmask enum so
they can be stored succinctly, but still diagnose reasonably.
2025-04-04 12:32:33 -07:00
Mariya Podchishchaeva
16a1d5d51f
[clang] Do not diagnose unused deleted operator delete[] (#134357)
For vector deleting dtors support we now also search and save operator
delete[]. Avoid diagnosing deleted operator delete[] when doing that
because vector deleting dtors are only called when delete[] is present
and whenever delete[] is present in the TU it will be diagnosed
correctly.

Fixes https://github.com/llvm/llvm-project/issues/134265
2025-04-04 14:44:44 +02:00
Mariya Podchishchaeva
22130ca486
[MS][clang] Fix crash on deletion of array of pointers (#134088)
Sometimes a non-array delete is treated as delete[] when input pointer
is pointer to array. With vector deleting destructors support we now
generate a virtual destructor call instead of simple loop over the
elements. This patch adjusts the codepath that generates virtual call to
expect the case of pointer to array.
2025-04-04 09:37:28 +02:00
Andy Kaylor
13aac46332
[clang][NFC] Refactor CodeGen's hasBooleanRepresentation (#134159)
The ClangIR upstreaming project needs the same logic for
hasBooleanRepresentation() that is currently implemented in the standard
clang codegen. In order to share this code, this change moves the
implementation of this function into the AST Type class.

No functional change is intended by this change. The ClangIR use of this
function will be added separately in a later change.
2025-04-03 14:03:25 -07:00
Matheus Izvekov
cfee056b4e
[clang] NFC: introduce UnsignedOrNone as a replacement for std::optional<unsigned> (#134142)
This introduces a new class 'UnsignedOrNone', which models a lite
version of `std::optional<unsigned>`, but has the same size as
'unsigned'.

This replaces most uses of `std::optional<unsigned>`, and similar
schemes utilizing 'int' and '-1' as sentinel.

Besides the smaller size advantage, this is simpler to serialize, as its
internal representation is a single unsigned int as well.
2025-04-03 14:27:18 -03:00
Matheus Izvekov
49fd0bf35d
[clang] support pack expansions for trailing requires clauses (#133190) 2025-04-03 12:36:15 -03:00
Alex Bradbury
2a9948f038
Revert "[CLANG-CL] ignores wpadded" (#134239)
Reverts llvm/llvm-project#130182

This is causing failures on RISC-V and ppc builders as mentioned on
https://github.com/llvm/llvm-project/pull/130182#issuecomment-2775516899

Reverting so the issue can be fixed by the path author without time pressure (as noted in that PR, it seems a value is uninitialised).
2025-04-03 13:47:59 +01:00
Ilya Biryukov
722346c7bc
[Tooling] Handle AttributedType in getFullyQualifiedType (#134228)
Before this change the code used to add extra qualifiers, e.g.
`std::unique_ptr<int> _Nonnull` became `::std::std::unique_ptr<int>
_Nonnull`
when adding a global namespace qualifier was requested.
2025-04-03 14:14:34 +02:00
Dmitry Polukhin
e1aaee7ea2
[modules] Handle friend function that was a definition but became only a declaration during AST deserialization (#132214)
Fix for regression #130917, changes in #111992 were too broad. This change reduces scope of previous fix. Added `ExternalASTSource::wasThisDeclarationADefinition` to detect cases when FunctionDecl lost body due to declaration merges.
2025-04-03 08:27:13 +01:00
Matheus Izvekov
f302f35526
[clang] Track final substitution for Subst* AST nodes (#132748) 2025-04-02 19:27:29 -03:00
Theo de Magalhaes
76fa9530c9
[clang] add support for -Wpadded on Windows (#130182)
Implements the -Wpadded warning for --target=x86_64-windows-msvc etc.

Fixes #61702 .
2025-04-02 14:46:58 -07:00
erichkeane
d7724c8ea3 [OpenACC] allow 'if' clause on 'atomic' construct
This was added in OpenACC PR #511 in the 3.4 branch.  From an AST/Sema
perspective this is pretty trivial as the infrastructure for 'if'
already exists, however the atomic construct needed to be taught to take
clauses.  This patch does that and adds some testing to do so.
2025-04-02 10:03:24 -07:00
Mariya Podchishchaeva
8a691cc615
[MS][clang] Make sure vector deleting dtor calls correct operator delete (#133950)
During additional testing I spotted that vector deleting dtor calls
operator delete, not operator delete[] when performing array deletion.
This patch fixes that.
2025-04-02 09:25:43 +02:00
Matheus Izvekov
ad1ca5f4a2
[clang] Concepts: support pack expansions for type constraints (#132626)
This reverts an earlier attempt
(adb0d8ddceb143749c519d14b8b31b481071da77 and
50e5411e4247421fd606f0a206682fcdf0303ae3) to support these expansions,
which was limited to type arguments and which subverted the purpose
of SubstTemplateTypeParmType.

This propagates the ArgumentPackSubstitutionIndex along with the
AssociatedConstraint, so that the pack expansion works, without
needing any new transforms or otherwise any changes to the template
instantiation process.

This keeps the tests from the reverted commits, and adds a few more
showing the new solution also works for NTTPs.

Fixes https://github.com/llvm/llvm-project/issues/131798
2025-04-01 21:11:56 -03:00
Matheus Izvekov
dc17429ae6
[clang] improved preservation of template keyword (#133610) 2025-04-01 17:15:18 -03:00
Timm Baeder
7267dbfe10
[clang][bytecode] Fix comparing the addresses of union members (#133852)
Union members get the same address, so we can't just use
`Pointer::getByteOffset()`.
2025-04-01 09:00:46 +02:00
Timm Baeder
a0e1e680d2
[clang][bytecode] Return Invalid() on non-constexpr builtins (#133700)
So the diagnostic output matches with the current interpreter
2025-03-31 18:53:12 +02:00
Timm Baeder
11dd7d98a6
[clang][bytecode] Reject constexpr-unknown values from comparisons (#133701) 2025-03-31 18:53:01 +02:00
Mariya Podchishchaeva
842b57b775
Reland [MS][clang] Add support for vector deleting destructors (#133451)
Whereas it is UB in terms of the standard to delete an array of objects
via pointer whose static type doesn't match its dynamic type, MSVC
supports an extension allowing to do it.
Aside from array deletion not working correctly in the mentioned case,
currently not having this extension implemented causes clang to generate
code that is not compatible with the code generated by MSVC, because
clang always puts scalar deleting destructor to the vftable. This PR
aims to resolve these problems.

It was reverted due to link time errors in chromium with sanitizer
coverage enabled,
which is fixed by https://github.com/llvm/llvm-project/pull/131929 .

The second commit of this PR also contains a fix for a runtime failure
in chromium reported
in
https://github.com/llvm/llvm-project/pull/126240#issuecomment-2730216384
.

Fixes https://github.com/llvm/llvm-project/issues/19772
2025-03-31 10:03:39 +02:00
Kazu Hirata
60199ee539
[clang] Use DenseMap::insert_range (NFC) (#133655) 2025-03-30 22:57:25 -07:00
Matheus Izvekov
976a384ba6
[clang] implement common-sugar for adjusted member-pointers (#133613) 2025-03-30 01:45:00 -03:00
Nick Sarnie
48b7530273
[clang][flang][Triple][llvm] Add isOffload function to LangOpts and isGPU function to Triple (#126956)
I'm adding support for SPIR-V, so let's consolidate these checks.

---------

Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-03-28 14:19:20 +00:00
Matheus Izvekov
89cfeeb062
[clang] fix structural comparison for dependent class member pointer (#133343)
Fixes a regression introduced in
https://github.com/llvm/llvm-project/pull/130537 and reported here
https://github.com/llvm/llvm-project/issues/133144

This fixes a crash in ASTStructuralEquivalence where the non-null
precondition for IsStructurallyEquivalent would be violated, when
comparing member pointers with a dependent class.

This also drive-by fixes the ast node traverser for member pointers so
it doesn't traverse into the qualifier in case it's not a type, or the
class declaration in case it would be equivalent to what the qualifier
refers.

This avoids printing of `<<<NULL>>>` on the text node dumper, which is
redundant.

No release notes since the regression was never released.

Fixes https://github.com/llvm/llvm-project/issues/133144
2025-03-27 22:09:36 -03:00