3663 Commits

Author SHA1 Message Date
Vlad Serebrennikov
9dd5542a34
[clang][NFC] Replace includes of "Attrs.inc" with "Attr.h" (#180356)
"clang/AST/Attrs.inc" is not a self-contained header and is not intended
to be included directly. Instead, "clang/AST/Attr.h" is the header that
users need.
2026-02-07 17:32:56 +00:00
Vigneshwar Jayakumar
f1d8d03837
[HIP][Sema] Fix incorrect CK_NoOp for lvalue-to-rvalue conversion in … (#180314)
…builtin args

The HIP implicit address space cast for builtin pointer arguments used
CK_NoOp to convert lvalue args to rvalues.

This caused an assertion failure in LifetimeSafety analysis:
  Assertion `Dst->getLength() == Src->getLength()` failed
in FactsGenerator::flow() in some cases.

Use DefaultLvalueConversion which correctly emits CK_LValueToRValue.
2026-02-07 11:09:23 -06:00
Farzon Lotfi
5f4543fbaf
[HLSL][Matrix] introduce MatrixElementExpr as accessor and swizzle operator (#171225)
fixes #159438

This patch adds `MatrixElementExpr`, a new AST node for HLSL matrix
element and swizzle access (e.g. M._m00, M._11_22_33).

It introduces a shared `ElementAccessExprBase` used by both matrix and
vector swizzle expressions, updates Sema to parse and validate
zero-based and one-based accessors, detects duplicates for l-value
checks, and emits improved diagnostics. CodeGen is updated to lower
scalar and multi-element accesses consistently, and full AST
serialization, dumping, and tooling support is included. This
implementation reflects the updated
[RFC](https://github.com/llvm/wg-hlsl/pull/357/files) for HLSL matrix
accessor semantics.
2026-02-06 13:16:49 -05:00
Nhat Nguyen
1171450d56
[clang]: reflection operator parsing for primitive types (#164692)
(After changing the scope) This PR implements parsing the reflection
operator (^^) for primitive types. The goal is to keep the first PR
simple. In subsequent PRs, parsing for the remaining requirements will
be introduced.

This implementation is based on the fork of @katzdm.

Class `CXXReflectExpr` is introduced to represent the operand of the
reflection operator. For now, in this PR, the type std::meta::info is
not implemented yet, so when we construct an AST node CXXReflectExpr,
`VoidTy` is used as placeholder type for now.

The file `ParseReflect.cpp` is introduced, which for now only has the
function `ParseCXXReflectExpression`. It parses the operand of the
reflection operator.

---------

Co-authored-by: Shafik Yaghmour <shafik.yaghmour@intel.com>
Co-authored-by: Hubert Tong <hubert.reinterpretcast@gmail.com>
Co-authored-by: Sirraide <aeternalmail@gmail.com>
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
Co-authored-by: Erich Keane <ekeane@nvidia.com>
2026-02-06 11:32:17 -05:00
David Stone
584a589965
[clang][NFC] #include "clang/AST/StmtVisitor.h" where necessary (#172538) 2026-01-16 11:17:03 -07:00
Deric C.
6212c87ab9
[HLSL][Matrix] Add Matrix splat support for booleans (#175809)
Fixes #175808

This PR adds support for boolean matrix splats by adding tests and
fixing a bug in `CodeGenFunction::EmitToMemory` when the type of a
boolean matrix already matches the type expected of a load/store.

This PR also addresses the todo comment in `clang/lib/Sema/SemaExpr.cpp`
regarding support for boolean matrix splats by removing the comment
altogether since it is not necessary.

---------

Co-authored-by: Farzon Lotfi <farzonlotfi@microsoft.com>
2026-01-14 10:17:13 -08:00
Oleksandr T.
b4e1ab8bc1
[Clang] prevent assertion failure for instantiation-dependent expressions in vector conversions (#173498)
Fixes #173347

---

This patch resolves an assertion failure that occurs when
instantiation-dependent expressions are constant-evaluated during vector
conversions.
2026-01-07 18:44:32 +08:00
Farzon Lotfi
cb56a910f8
[HLSL][Matrix] Add OR and AND logical operator support for matrix (#172384)
fixes #172341

This change adds the `or` and `and` HLSL builtins with overloads for the
matrix types.

It also disables the logical operators from being used for HLSL 2021. To
keep this code from getting too complicated HLSL 2018 and lower logical
operator support was not added.
2025-12-20 17:20:32 -05:00
Farzon Lotfi
60b6c53f25
[HLSL][Matrix] Add support for single subscript accessor (#170779)
fixes #166206

- Add swizzle support if row index is constant
- Add test cases
- Add new AST type
- Add new LValue for Matrix Row Type
- TODO: Make the new LValue a dynamic index version of ExtVectorElt
2025-12-17 17:04:28 -05:00
Farzon Lotfi
0d53746eaa
[HLSL][Matrix] Add support for ICK_HLSL_Matrix_Splat to add splat cast of scalars (#170885)
fixes #168960

Adds `ICK_HLSL_Matrix_Splat` and hooks it up to
`PerformImplicitConversion` and `IsMatrixConversion`. Map these to
`CK_HLSLAggregateSplatCast`.
2025-12-12 15:29:19 -05:00
Sirraide
71bfdd1304
[Clang] Add support for the C _Defer TS (#162848)
This implements WG14 N3734 (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3734.pdf),
aka `_Defer`; it is currently only supported in C if `-fdefer-ts` is passed.
2025-12-11 05:54:09 +01:00
Rana Pratap Reddy
b32a2f418a
[Clang][OpenCL][AMDGPU] Allow _Float16 and half vector type compatibility (#170605)
## Summary
Allowing implicit compatibility between `_Float16` vector types and
`half` vector types in OpenCL mode. This enables AMDGPU builtins to work
correctly across OpenCL, HIP, and C++ without requiring separate builtin
definitions.
## Problem Statement
When using AMDGPU image builtins that return half-precision vectors in
OpenCL, users encounter type incompatibility errors:
**Builtin Definition:**
`TARGET_BUILTIN(__builtin_amdgcn_image_load_1d_v4f16_i32, "V4xiiQtii",
"nc", "image-insts")`

**Test Case:**
```
typedef half half4 __attribute__((ext_vector_type(4)));
half4 test_builtin_image_load_1d_2(half4 v4f16, int i32, __amdgpu_texture_t tex) {
  return __builtin_amdgcn_image_load_1d_v4f16_i32(100, i32, tex, 120, i32);
}
```
**Error:**
```
error: returning '__attribute__((__vector_size__(4 * sizeof(_Float16)))) _Float16' 
(vector of 4 '_Float16' values) from a function with incompatible result type 
'half4' (vector of 4 'half' values)
```
## Solution
In OpenCL, allow implicit compatibility between `_Float16` vector types
and `half` vector types. This is needed for AMDGPU builtins that may
return _Float16 vectors to work correctly with OpenCL half vector types.
2025-12-08 21:56:35 +05:30
Juan Manuel Martinez Caamaño
0a35f44f58
[HIP] Perform implicit pointer cast when compiling HIP, not when -fcuda-is-device (#165387)
When compiling HIP device code, we add implicit casts for the pointer arguments passed to built-in calls.

When compiling for the host, apply the same casts, since the device side of the source (device functions and kernels) should still pass type checks.
2025-11-26 14:02:58 +01:00
Paul Walker
6bf3249fe9
[Clang][Sema] Emit diagnostic for __builtin_vectorelements(<SVEType>) when SVE is not available. (#168097)
As is done for other targets, I've moved the target type checking code
into SemaARM and migrated existing uses.

Fixes https://github.com/llvm/llvm-project/issues/155736
2025-11-25 13:14:10 +00:00
Zahira Ammarguellat
999deef63d
Desugar complex element types for promoted complex division (#168943)
This patch fixes a crash in Clang that occurs when the compiler
retrieves the element type of a complex type but receives a sugared
type. See example here: https://godbolt.org/z/cdbdeMcaT
This patch fixes the crash.
2025-11-24 07:51:55 -05:00
Justin Stitt
cf6b443c68
[Clang] Consider reachability for file-scope warnings on initializers (#163885)
Co-authored-by: Nathan Huckleberry <nhuck@google.com>
2025-11-11 10:22:40 -08:00
KaiWeng
d9c7c76269
Revert "Ignore trailing NullStmts in StmtExprs for GCC compatibility." (#166036)
This reverts commit b1e511bf5a4c702ace445848b30070ac2e021241.

https://github.com/llvm/llvm-project/issues/160243
Reverting because the GCC C front end is incorrect.

---------

Co-authored-by: Jim Lin <jim@andestech.com>
2025-11-07 09:30:53 -05:00
Matheus Izvekov
d2f75f2fe3
[clang] SFINAE context refactor (#164703)
This teases the SFINAE handling bits out of the CodeSynthesisContext,
and moves that functionality into SFINAETrap and a new class.

There is also a small performance benefit here:
<img width="1460" height="20" alt="image"
src="https://github.com/user-attachments/assets/aeb446e3-04c3-418e-83de-c80904c83574"
/>
2025-11-06 09:39:18 -10:00
Jakub Kuderski
d86da4efee
[ADT] Prepare for deprecation of StringSwitch cases with 4+ args. NFC. (#164173)
Update `.Cases` and `.CasesLower` with 4+ args to use the
`initializer_list` overload. The deprecation of these functions will
come in a separate PR.

For more context, see: https://github.com/llvm/llvm-project/pull/163405.
2025-10-20 12:03:46 -04:00
Chris B
f3cd6b749c
[HLSL] Convert vectors to bool for unary ! (#163857)
HLSL extends C++'s requirement that unary `!` apply to boolean arguments
and produces boolean results to apply to vectors. This change implements
implicit conversion for non-boolean vector operands to boolean vectors.

I've noted this behavior in the issue tracking writing the HLSL
specification section on unary operators
(https://github.com/microsoft/hlsl-specs/issues/686).

Fixes #162913

---------

Co-authored-by: Farzon Lotfi <farzonl@gmail.com>
Co-authored-by: Erich Keane <ekeane@nvidia.com>
2025-10-17 08:42:00 -05:00
Matheus Izvekov
b516dcc998
[clang] NFC: rename TagType::getOriginalDecl back to getDecl (#163271)
This rename was made as part of
https://github.com/llvm/llvm-project/pull/147835 in order to ease
rebasing the PR, and give a nice window for other patches to get rebased
as well.

It has been a while already, so lets go ahead and rename it back.
2025-10-15 16:11:17 -03:00
Aaron Ballman
8e60adcaaf
[C2y] Implement WG14 N3622 static used in an inline (#162877)
This paper removes the constraint that a static variable or function
cannot be used within an extern inline function. The diagnostic is still
being produced in earlier language modes for conformance reasons but has
always been accepted as an extension.
2025-10-10 14:02:17 -04:00
Bruno De Fraine
a03aef4fae
[Clang] [Sema] Fix incomplete C mode incompatible ExtInfo/ExtProtoInfo conversion diagnostic (#160477)
To raise -Wincompatible-function-pointer-type for extended function type
information conversions in C mode, checkPointerTypesForAssignment
contained an invocation of IsFunctionConversion that is quite dubious:
it verifies the conversion from LHS to RHS, while we are converting from
RHS to LHS. Presumably, this was done because result and argument types
don't have to match exactly in C mode (compatible types is sufficient),
while IsFunctionConversion checks that an exact match in function types
can be obtained by transforming extended function type information. As a
result of the dubious invocation, the diagnostic for incompatible
extended function type changes was incomplete and would illogically
disappear when other changes to the function type were involved (this
was already raised in 2019 but left unsolved). Newer additions of
extended function type information such as "cfi_unchecked_callee", ARM
CMSE attributes, ARM SME attributes, and function effect attributes,
worked around the issue by introducing either holes or additional checks
which complicates the logic.

Here, we solve this longstanding issue by using IsFunctionConversion to
verify the extended function type information conversion in the correct
direction (from RHS to LHS), after first removing other differences in
the function type (argument and result type mismatch, prototype vs. no
prototype) to allow IsFunctionConversion to obtain an exact match. The
complications introduced for checking newer attributes are removed.

Fixes #41465
Fixes #85415
2025-10-09 17:30:25 +02:00
Corentin Jabot
39d0e41a5f
[NFC][Clang Improve performance of DoMarkVarDeclReferenced (#161648)
Address post commit feedback from #161231
2025-10-02 13:27:57 +02:00
Luo, Yuanke
d96c32cdaf
[CUDA] Enable variadic argument support in front-end (#161305)
Variadice argument for NVPTX as been support in

486d00eca6
We can enable it in front-end.

Co-authored-by: Yuanke Luo <ykluo@birentech.com>
2025-09-29 21:48:14 -05:00
Corentin Jabot
7e4678270f
[Clang] Instantiate variables referenced in decltype with an undeduced type. (#161231)
Fixes #160497
Fixes #56652
Fixes #116319
Fixes #161196
2025-09-29 21:30:07 +02:00
Helena Kotas
9f5b02311a
[HLSL] Make sure global resources and resource arrays cannot be assigned to (#157772)
Global resources are read-only. The compiler needs to report an error when somebody attempts to assign a value to a global resource, a global resource array element or the whole array.

Test update in `static-local-ctor.hlsl` includes the use of the llvm-cxxfilt tool which takes care of demangling of function names for a more readable test baseline.

Closes #154390
2025-09-18 14:36:28 -07:00
Corentin Jabot
ce5124856e
[Clang] Fix an incorrect assertion in Sema::CheckAddressOfOperand (#159314)
Not all non-type template arguments are modeled as
NonTypeTemplateParmDecl.

Fixes #151531
2025-09-17 14:38:08 +02:00
Joseph Huber
134a58adff
[Clang] Permit implicit conversion from integral to boolean vectors (#158369)
Summary:
Clang supports boolean vectors as an extension to the vector model.
These are commonly used to represent mask vectors in many vector ISAs.
Currently, using these is quite difficult because all of the vector
comparison operations use integral bitmasks. C / C++ has a long history
of allowing implicit conversions to bool, and I think that we should be
able to do the same here, especially because boolean vectors often work
as wrappers around a bitfield.

This patch adds the minimal changes to enable integral to boolean
conversions for vectors. Because LLVM already handles comparison to zero
for vectors natively, minimal changes are required. We are not bound to
the OpenCL standard at all here because it explicitly forbids boolean
vectors anyway, so these are simply clang extensions.
2025-09-15 10:09:10 -05:00
Matheus Izvekov
ba9d1c41c4
[clang] AST: remove DependentTemplateSpecializationType (#158109)
A DependentTemplateSpecializationType (DTST) is basically just a
TemplateSpecializationType (TST) with a hardcoded DependentTemplateName
(DTN) as its TemplateName.

This removes the DTST and replaces all uses of it with a TST, removing a
lot of duplication in the implementation.

Technically the hardcoded DTN is an optimization for a most common case,
but the TST implementation is in better shape overall and with other
optimizations, so this patch ends up being an overall performance
positive:
<img width="1465" height="38" alt="image"
src="https://github.com/user-attachments/assets/084b0694-2839-427a-b664-eff400f780b5"
/>

A DTST also didn't allow a template name representing a DTN that was
substituted, such as from an alias template, while the TST does allow it
by the simple fact it can hold an arbitrary TemplateName, so this patch
also increases the amount of sugar retained, while still being faster
overall.

Example (from included test case):
```C++
template<template<class> class TT> using T1 = TT<int>;
template<class T> using T2 = T1<T::template X>;
```

Here we can now represent in the AST that `TT` was substituted for the
dependent template name `T::template X`.
2025-09-12 13:55:38 -03:00
Andrew Savonichev
3ade8746ee
[clang] Look through parens around reinterpret_cast to emit a warning (#157033)
Clang warns about UB when a `reinterpret_cast` is dereferenced as an
incompatible type:
```
  long l;
  *reinterpret_cast<double*>(&l) // UB
```
However, the code was too strict and did not handle extra parens around
a `reinterpret_cast`, so the following case was not diagnosed:
```
  long l;
  *(reinterpret_cast<double*>(&l)) // UB, but no warning
```
The patch now skips ParenExpr when looking for a CXXReinterpretCastExpr
to enable a diagnostic for the second case.
2025-09-12 10:25:58 +09:00
comex
28c9452420
[clang] Fix side effects resolving overloads of builtin functions (#138651) (#154034)
When parsing `__builtin_addressof(Value)`, where `Value` is a constexpr
variable of primitive type, we will run through
`rewriteBuiltinFunctionDecl`.

`rewriteBuiltinFunctionDecl` is meant to handle a special case which is
not applicable here. (It only applies when a builtin function's type has
a parameter with pointer type, which is not true for
`__builtin_addressof`, not even if the actual argument is a pointer.)
Therefore, `rewriteBuiltinFunctionDecl` returns `nullptr` and things go
on as usual.

But `rewriteBuiltinFunctionDecl` accidentally has a side effect. It
calls `DefaultFunctionArrayLvalueConversion` ->
`DefaultLvalueConversion` -> `CheckLValueToRValueConversionOperand` ->
`rebuildPotentialResultsAsNonOdrUsed` -> `MarkNotOdrUsed`, which removes
the expression from `S.MaybeODRUseExprs`.

This would be correct if `Value` were actually going through an
lvalue-to-rvalue conversion, because it's a constant expression:

https://eel.is/c++draft/basic.def.odr#5.2.2.2

But in this case the conversion is only hypothetical, as part of
`rewriteBuiltinFunctionDecl`'s pseudo-overload-resolution logic.

Fix the side effect by pushing an `ExpressionEvaluationContext`, like we
do for real overload resolution.

Similarly, push a `SFINAETrap` to suppress diagnostics emitted during
`DefaultFunctionArrayLvalueConversion`. This fixes a false-positive
compile error when applying `__builtin_addressof` to certain volatile
union variables, and fixes a duplicated compile error when applying
`__builtin_get_vtable_pointer` to an overloaded function name.

---------

Co-authored-by: Corentin Jabot <corentinjabot@gmail.com>
2025-09-09 06:26:10 +00:00
Erich Keane
15e9306f6d
[OpenACC] Fix crash because of miscalculated dependence. (#156745)
We were causing ANY dependence to cause the return type of the array
section to be dependent, when in reality it should only be so if one of
its Bounds/Base are dependent. This patch fixes that.
2025-09-03 20:27:40 +00:00
Vladimir Vuksanovic
5f38548c86
[Sema] Allow zero-size allocations for -Walloc-size (#155793)
Allocations of size zero are usually done intentionally and then
reallocated before use.

Fixes #155633
2025-09-02 08:18:56 -07:00
nfrmtk
78e3a58d21
[Clang] correct error message when assigning to const reference captured in lambda (#105647)
Fixes #98772
2025-09-01 13:49:31 +00:00
Matheus Izvekov
249167a898
[clang] NFC: reintroduce clang/include/clang/AST/Type.h (#155050)
This reintroduces `Type.h`, having earlier been renamed to `TypeBase.h`,
as a redirection to `TypeBase.h`, and redirects most users to include
the former instead.

This is a preparatory patch for being able to provide inline definitions
for `Type` methods which would otherwise cause a circular dependency
with `Decl{,CXX}.h`.

Doing these operations into their own NFC patch helps the git rename
detection logic work, preserving the history.

This patch makes clang just a little slower to build (~0.17%), just
because it makes more code indirectly include `DeclCXX.h`.
2025-08-27 13:11:34 -03:00
Matheus Izvekov
bcd1530836
[clang] NFC: rename clang/include/clang/AST/Type.h to TypeBase.h (#155049)
This is a preparatory patch, to be able to provide inline definitions
for `Type` functions which depend on `Decl{,CXX}.h`. As the latter also
depends on `Type.h`, this would not be possible without some
reorganizing.

Splitting this rename into its own patch allows git to track this as a
rename, and preserve all git history, and not force any code
reformatting.

A later NFC patch will reintroduce `Type.h` as redirection to
`TypeBase.h`, rewriting most places back to directly including `Type.h`
instead of `TypeBase.h`, leaving only a handful of places where this is
necessary.

Then yet a later patch will exploit this by making more stuff inline.
2025-08-27 13:09:48 -03:00
Matheus Izvekov
88438ba1f3
[clang] AST: fix getAs canonicalization of leaf types (#155028) 2025-08-27 06:20:14 -03:00
Timm Baeder
b424207cdd
[clang] Post-commit review for #150028 (#155351)
1) Return `std::nullopt` instead of `{}`.
 2) Rename the new function to evaluate*, it's not a simple getter.
2025-08-27 09:48:57 +02:00
Matheus Izvekov
2ec71d93ad
[clang] NFC: introduce Type::getAsEnumDecl, and cast variants for all TagDecls (#155463)
And make use of those.

These changes are split from prior PR #155028, in order to decrease the
size of that PR and facilitate review.
2025-08-26 16:05:59 -03:00
Matheus Izvekov
dc8596d548
[clang] NFC: change more places to use Type::getAsTagDecl and friends (#155313)
This changes a bunch of places which use getAs<TagType>, including
derived types, just to obtain the tag definition.

This is preparation for #155028, offloading all the changes that PR used
to introduce which don't depend on any new helpers.
2025-08-25 20:18:56 -03:00
Vladimir Vuksanovic
6dc188d4eb
[clang] Implement -Walloc-size diagnostic option (#150028)
Warns about calls to functions decorated with attribute `alloc_size`
that specify insufficient size for the type they are cast to. Matches
the behavior of the GCC option of the same name.

Closes #138973

---------

Co-authored-by: Vladimir Vuksanovic <vvuksano@cisco.com>
2025-08-25 07:46:08 -07:00
Timothy Choi
66eaa80c39
[Clang] Remove redundant check for scoped enums in shift operators (#152865)
This check, introduced in 0bf3140424a0a13a928a4e6bf0f112e6167a5636, has
not been necessary since 21673c4e7ec08457b53798b9879b7cc9a5909eb8
2025-08-23 15:31:02 +02:00
Timothy Choi
8b5503d9b1
[Clang] Add diagnostic when scoped enumeration requires an explicit conversion for binary operations (#152698)
```diff
 main.cpp:4:8: error: invalid operands to binary expression ('E' and 'int')
     4 |   E::e + 0;
       |   ~~~~ ^ ~
+main.cpp:4:3: note: no implicit conversion for scoped enum; consider casting to underlying type
+    4 |   E::e + 0;
+      |   ^  
+      |   static_cast<int>( )
```

Resolves #24265
2025-08-23 09:14:16 +00:00
Tom Honermann
8ed9c6101f
[NFC] Remove unneeded forward declaration of diagnoseUncapturableValueReferenceOrBinding() (#154591)
The only (remaining) use of this forward declaration was removed in
commit 127bf44385424891eb04cff8e52d3f157fc2cb7c.
2025-08-20 14:57:53 -04:00
Joseph Huber
5a929a4249
[Clang] Support using boolean vectors in ternary operators (#154145)
Summary:
It's extremely common to conditionally blend two vectors. Previously
this was done with mask registers, which is what the normal ternary code
generation does when used on a vector. However, since Clang 15 we have
supported boolean vector types in the compiler. These are useful in
general for checking the mask registers, but are currently limited
because they do not map to an LLVM-IR select instruction.

This patch simply relaxes these checks, which are technically forbidden
by
the OpenCL standard. However, general vector support should be able to
handle these. We already support this for Arm SVE types, so this should
be make more consistent with the clang vector type.
2025-08-20 07:49:26 -05:00
Aaron Ballman
ae434cdd0b
[C] Fix issue with -Wimplicit-void-ptr-cast (#154351)
The changes from https://github.com/llvm/llvm-project/pull/136855 missed
a change with atomic assignment constraints. This fixes a bug where we'd
accidentally drop a non-atomic-to-atomic conversion step.

Fixes #154157

co-authored-by: @ahatanak
2025-08-19 12:55:03 -04:00
Vladimir Vuksanovic
9d1dd9a264
[Sema] Fix false positive warnings for misaligned member access (#150025)
These warnings are reported on a per expression basis, however some
potential misaligned accesses are discarded before that happens. The
problem is when a new expression starts while processing another
expression. The new expression will end first and emit all potential
misaligned accesses collected up to that point. That includes candidates
that were found in the parent expression, even though they might have
gotten discarded later.

Fixed by checking if the candidate is located withing the currently
processed expression.

Fixes #144729
2025-08-14 06:14:43 -07:00
Matheus Izvekov
91cdd35008
[clang] Improve nested name specifier AST representation (#147835)
This is a major change on how we represent nested name qualifications in
the AST.

* The nested name specifier itself and how it's stored is changed. The
prefixes for types are handled within the type hierarchy, which makes
canonicalization for them super cheap, no memory allocation required.
Also translating a type into nested name specifier form becomes a no-op.
An identifier is stored as a DependentNameType. The nested name
specifier gains a lightweight handle class, to be used instead of
passing around pointers, which is similar to what is implemented for
TemplateName. There is still one free bit available, and this handle can
be used within a PointerUnion and PointerIntPair, which should keep
bit-packing aficionados happy.
* The ElaboratedType node is removed, all type nodes in which it could
previously apply to can now store the elaborated keyword and name
qualifier, tail allocating when present.
* TagTypes can now point to the exact declaration found when producing
these, as opposed to the previous situation of there only existing one
TagType per entity. This increases the amount of type sugar retained,
and can have several applications, for example in tracking module
ownership, and other tools which care about source file origins, such as
IWYU. These TagTypes are lazily allocated, in order to limit the
increase in AST size.

This patch offers a great performance benefit.

It greatly improves compilation time for
[stdexec](https://github.com/NVIDIA/stdexec). For one datapoint, for
`test_on2.cpp` in that project, which is the slowest compiling test,
this patch improves `-c` compilation time by about 7.2%, with the
`-fsyntax-only` improvement being at ~12%.

This has great results on compile-time-tracker as well:

![image](https://github.com/user-attachments/assets/700dce98-2cab-4aa8-97d1-b038c0bee831)

This patch also further enables other optimziations in the future, and
will reduce the performance impact of template specialization resugaring
when that lands.

It has some other miscelaneous drive-by fixes.

About the review: Yes the patch is huge, sorry about that. Part of the
reason is that I started by the nested name specifier part, before the
ElaboratedType part, but that had a huge performance downside, as
ElaboratedType is a big performance hog. I didn't have the steam to go
back and change the patch after the fact.

There is also a lot of internal API changes, and it made sense to remove
ElaboratedType in one go, versus removing it from one type at a time, as
that would present much more churn to the users. Also, the nested name
specifier having a different API avoids missing changes related to how
prefixes work now, which could make existing code compile but not work.

How to review: The important changes are all in
`clang/include/clang/AST` and `clang/lib/AST`, with also important
changes in `clang/lib/Sema/TreeTransform.h`.

The rest and bulk of the changes are mostly consequences of the changes
in API.

PS: TagType::getDecl is renamed to `getOriginalDecl` in this patch, just
for easier to rebasing. I plan to rename it back after this lands.

Fixes #136624
Fixes https://github.com/llvm/llvm-project/issues/43179
Fixes https://github.com/llvm/llvm-project/issues/68670
Fixes https://github.com/llvm/llvm-project/issues/92757
2025-08-09 05:06:53 -03:00
Corentin Jabot
28ed57eda8
[Clang] Initial support for P2841 (Variable template and concept template parameters) (#150823)
This is a first pass at implementing
[P2841R7](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2025/p2841r7.pdf).

The implementation is far from complete; however, I'm aiming to do that
in chunks, to make our lives easier.

In particular, this does not implement
 - Subsumption
 - Mangling
- Satisfaction checking is minimal as we should focus on #141776 first
(note that I'm currently very stuck)

FTM, release notes, status page, etc, will be updated once the feature
is more mature. Given the state of the feature, it is not yet allowed in
older language modes.

Of note: 
- Mismatches between template template arguments and template template
parameters are a bit wonky. This is addressed by #130603
- We use `UnresolvedLookupExpr` to model template-id. While this is
pre-existing, I have been wondering if we want to introduce a different
OverloadExpr subclass for that. I did not make the change in this patch.
2025-08-04 08:51:22 +02:00