22399 Commits

Author SHA1 Message Date
Eli Friedman
f2d2c99866
[clang] Remove separate evaluation step for static class member init. (#142713)
We already evaluate the initializers for all global variables, as
required by the standard. Leverage that evaluation instead of trying to
separately validate static class members.

This has a few benefits:

- Improved diagnostics; we now get notes explaining what failed to
evaluate.
- Improved correctness: is_constant_evaluated is handled correctly.

The behavior follows the proposed resolution for CWG1721.

Fixes #88462. Fixes #99680.
2025-06-17 16:43:55 -07:00
Ashley Coleman
73f307a5ca
[HLSL] Use ExtVector for firstbit intrinsics (#142679)
Fixes https://github.com/llvm/llvm-project/issues/142430

firstbit intrinsics were using the wrong vector type which causes some
conversions to fail. This PR switches them to ExtVector which resolves
the issue
2025-06-17 14:32:11 -06:00
Finn Plummer
8cd05b88ec
[NFC][HLSL] Move Sema work from ParseMicrosoftRootSignatureAttributeArgs (#143184)
This separates semantic analysis from parsing by moving `RootSignatureDecl` creation, scope storage, and lookup logic into
`SemaHLSL`.

For more context see:
https://github.com/llvm/llvm-project/issues/142834.

- Define `ActOnStartRootSignatureDecl` and `ActOnFinishRootSignatureDecl` on `SemaHLSL`
- NFC so no test changes.

Resolves: https://github.com/llvm/llvm-project/issues/142834

---------

Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2025-06-17 11:27:35 -07:00
Vincent
977d8a4bcd
[clang][Sema] Fixed Compound Literal is not Constant Expression (#143852)
Added a check for a compound literal hiding inside a function.

fixes #87867
2025-06-17 09:20:41 -04:00
Oliver Hunt
eddab9b757
[clang] Fix PointerAuth semantics of cpp_trivially_relocatable (#143969)
This adds a number of functions to ASTContext to query whether a
type contains data protected with address discriminated pointer
authentication, and whether the protected values are just vtable
pointers, or if there are other address discriminated types included.

For the standardized version, __builtin_is_cpp_trivially_relocatable
this means accepting types where the only address discriminated
values are vtable pointers. Other address discriminated types are
not considered relocatable. In addition to that any union containing
any address discriminated data, including vtable pointers, is not
relocatable.

For the old deprecated __builtin_is_trivially_relocatable we reject
any type containing any address discriminated value, as it is
semantically intended as being a "is this memcopyable" which is
not true for anything with address discrimination.

This PR does not update the codegen for __builtin_trivially_relocate,
that will be in a follow on PR that is much more complex.
2025-06-16 12:12:22 +03:00
Kazu Hirata
c01532177f
[clang] Remove unused includes (NFC) (#144285)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-06-15 21:00:36 -07:00
Kazu Hirata
f71fb2dc01
[clang] Use StringRef in range-based for loops (NFC) (#144242)
When we iterate over std::vector<std::string>, we can directly assign
each element to StringRef.  We do not need to go through separate
statements.
2025-06-15 21:00:22 -07:00
Kazu Hirata
8f5c338b89
[Sema] Use a range-based for loop (NFC) (#144252)
Note that LLVM Coding Standards discourages for_each.
2025-06-15 10:32:52 -07:00
Oleksandr T.
0ff95c9eb1
[Clang] add fix-it hints for unknown attributes (#141305)
This patch adds fix-it hints for unknown attribute names when Clang
suggests a correction
2025-06-15 00:01:25 +03:00
Zhikai Zeng
892513e518
[clang] fix infinite recursion (#143244)
fix https://github.com/llvm/llvm-project/issues/141789

The direct cause of infinite recursion is that `T` is changing from
`struct X` and `S<X>` infinitely, this pr add a check that if `T`
visited before then return false directly.

```plaintext
/home/backlight/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:7196] FD->getType().getAsString()=struct X, T.getAsString()=S<X>, FD->getType().getCanonicalType().getUnqualifiedType().getAsString()=struct X, CanUnqualT.getAsString()=struct S<struct X>, 
/home/backlight/llvm-project/clang/lib/Sema/SemaDeclCXX.cpp:7196] FD->getType().getAsString()=S<X>, T.getAsString()=struct X, FD->getType().getCanonicalType().getUnqualifiedType().getAsString()=struct S<struct X>, CanUnqualT.getAsString()=struct X,
```

https://github.com/llvm/llvm-project/pull/104829 fix similar infinite
recursion, but I think it is no longer needed so I kind of revert it.
2025-06-14 17:14:16 +08:00
Corentin Jabot
90d98a38b2
Revert "[Clang] Added explanation why is_constructible evaluated to false. " (#144127)
Reverts llvm/llvm-project#143309

Someone needs to go through the libc++ tests and update the diagnostics
checks in those tests (ie, i don't believe there was anything wrong with
the PR, but it impacts libc++ tests nonetheless
2025-06-13 21:05:44 +02:00
Devon Loehr
9670e09d0e
Enable unique-object-duplication warning for windows (#143537)
Followup to #125526. This expands the logic of the
unique-object-duplication warning so that it also works for windows
code.

For the most part, the logic is unchanged, merely substituting "has no
import/export annotation" in place of "has hidden visibility". However,
there are some small inconsistencies between the two; namely, visibility
is propagated through nested classes, while import/export annotations
aren't.

This PR:
1. Updates the logic for the warning to account for the differences
between posix and windows
2. Changes the warning message and documentation appropriately
3. Updates the tests to cover windows, and adds new test cases for the
places where behavior differs.

This PR was tested by building chromium (cross compiling linux->windows)
with the changes in place. After accounting for the differences in
semantics, no new warnings were discovered.
2025-06-13 10:29:42 -04:00
Aaron Ballman
30725efe67 Fix build after removing delayed typo expression
This addresses issues found by:
  https://lab.llvm.org/buildbot/#/builders/64/builds/4220
  https://lab.llvm.org/buildbot/#/builders/51/builds/17890
2025-06-13 07:12:41 -04:00
Aaron Ballman
9eef4d1c5f
Remove delayed typo expressions (#143423)
This removes the delayed typo correction functionality from Clang
(regular typo correction still remains) due to fragility of the
solution.

An RFC was posted here:
https://discourse.llvm.org/t/rfc-removing-support-for-delayed-typo-correction/86631
and while that RFC was asking for folks to consider stepping up to be
maintainers, and we did have a few new contributors show some interest,
experiments show that it's likely worth it to remove this functionality
entirely and focus efforts on improving regular typo correction.

This removal fixes ~20 open issues (quite possibly more), improves
compile time performance by roughly .3-.4%
(https://llvm-compile-time-tracker.com/?config=Overview&stat=instructions%3Au&remote=AaronBallman&sortBy=date),
and does not appear to regress diagnostic behavior in a way we wouldn't
find acceptable.

Fixes #142457
Fixes #139913
Fixes #138850
Fixes #137867
Fixes #137860
Fixes #107840
Fixes #93308
Fixes #69470
Fixes #59391
Fixes #58172
Fixes #46215
Fixes #45915
Fixes #45891
Fixes #44490
Fixes #36703
Fixes #32903
Fixes #23312
Fixes #69874
2025-06-13 06:45:40 -04:00
Shamshura Egor
02b6ed0bf1
[Clang] Added explanation why is_constructible evaluated to false. (#143309)
Added explanation why a is constructible evaluated to false. Also fixed
problem with ```ExtractTypeTraitFromExpression```. In case
```std::is_xxx_v<>``` with variadic pack it tries to get template
argument, but fails in expression ```Arg.getAsType()``` due to
```Arg.getKind() == TemplateArgument::ArgKind::Pack```, but not
```TemplateArgument::ArgKind::Type```.
2025-06-13 09:53:15 +02:00
Chuanqi Xu
1d1f9afe91 [C++20] [Modules] Treat directly imported internal partition unit as reachable
Close https://github.com/llvm/llvm-project/issues/143788

See the discussion for details.
2025-06-12 17:46:33 +08:00
Mikael Holmen
77062244ed Fix two instances of -Wparentheses warnings [NFC]
Add parentheses around the assert conditions.

Without this gcc warned like
 ../lib/Target/AMDGPU/GCNSchedStrategy.cpp:2250: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
  2250 |          NewMI != RegionBounds.second && "cannot remove at region end");
and
 ../../clang/lib/Sema/SemaOverload.cpp:11326:39: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
 11326 |          DeferredCandidatesCount == 0 &&
       |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
 11327 |              "Unexpected deferred template candidates");
       |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2025-06-12 09:43:30 +02:00
Fazlay Rabbi
02550da932
[OpenMP 60] Initial parsing/sema for need_device_addr modifier on adjust_args clause (#143442)
Adds initial parsing and semantic analysis for `need_device_addr`
modifier on `adjust_args` clause.
2025-06-11 22:06:11 -07:00
Brandon Wu
5f231db764
[RISCV] Use StringRef for RequiredExtensions in RVVIntrinsicDef (#143503)
This prevents many duplicated copies of required extensions string.
2025-06-12 11:41:52 +08:00
Abhinav Gaba
02b6849cf1
[Clang][OpenMP] Fix mapping of arrays of structs with members with mappers (#142511)
This builds upon #101101 from @jyu2-git, which used compiler-generated
mappers when mapping an array-section of structs with members that have
user-defined default mappers.

Now we do the same when mapping arrays of structs.
2025-06-11 19:03:55 +00:00
Corentin Jabot
6b0cb762af
[Clang] _default-movable_ should be based on the first declaration (#143661)
When the definition of a special member function was defaulted we would
not consider it user-provided, even when the first declaration was not
defaulted.

Fixes #143599
2025-06-11 15:39:41 +02:00
Nathan Gauër
50f534e21c
[HLSL][SPIR-V] Handle SV_Position builtin in PS (#141759)
This commit is using the same mechanism as vk::ext_builtin_input to
implement the SV_Position semantic input.
The HLSL signature is not yet ready for DXIL, hence this commit only
implements the SPIR-V side.

This is incomplete as it doesn't allow the semantic on hull/domain and
other shaders, but it's a first step to validate the overall
input/output
semantic logic.

Fixes https://github.com/llvm/llvm-project/issues/136969
2025-06-11 14:22:54 +02:00
CHANDRA GHALE
afbcf9529a
[OpenMP 6.0 ]Codegen for Reduction over private variables with reduction clause (#134709)
Codegen support for reduction over private variable with reduction
clause. Section 7.6.10 in in OpenMP 6.0 spec.
- An internal shared copy is initialized with an initializer value.
- The shared copy is updated by combining its value with the values from
the private copies created by the clause.
- Once an encountering thread verifies that all updates are complete,
its original list item is updated by merging its value with that of the
shared copy and then broadcast to all threads.

Sample Test Case from OpenMP 6.0 Example 
```
#include <assert.h>
#include <omp.h>
#define N 10

void do_red(int n, int *v, int &sum_v)
{
    sum_v = 0; // sum_v is private
    #pragma omp for reduction(original(private),+: sum_v)
    for (int i = 0; i < n; i++) 
    {
        sum_v += v[i];
    }
}

int main(void)
{
    int v[N];
    for (int i = 0; i < N; i++)
        v[i] = i;
    #pragma omp parallel num_threads(4)
    {
        int s_v; // s_v is private
        do_red(N, v, s_v);
        assert(s_v == 45);
    }
    return 0;
}
```
Expected Codegen:
```
 // A shared global/static variable is introduced for the reduction result.
 // This variable is initialized (e.g., using memset or a UDR initializer)
 // e.g., .omp.reduction.internal_private_var

 // Barrier before any thread performs combination
  call void @__kmpc_barrier(...)

 // Initialization block (executed by thread 0)
 // e.g., call void @llvm.memset.p0.i64(...) or call @udr_initializer(...)

  call void @__kmpc_critical(...)
    // Inside critical section:
    // Load the current value from the shared variable
    // Load the thread-local private variable's value
    // Perform the reduction operation 
    // Store the result back to the shared variable

  call void @__kmpc_end_critical(...)
  // Barrier after all threads complete their combinations

  call void @__kmpc_barrier(...)
 // Broadcast phase:
 // Load the final result from the shared variable)
 // Store the final result to the original private variable in each thread
 // Final barrier after broadcast

  call void @__kmpc_barrier(...)
```

---------

Co-authored-by: Chandra Ghale <ghale@pe31.hpc.amslabs.hpecorp.net>
2025-06-11 14:01:31 +05:30
Shafik Yaghmour
c2cb571c6c
[Clang][NFC] Move UntypedParameters instead of copy (#143646)
Static analysis flagged that UntypedParameters could be moved instead of
copied. This would avoid copying a large object.
2025-06-10 23:41:41 -07:00
Zhikai Zeng
46b7a88548
fix access checking about function overloading (#107768)
fix https://github.com/llvm/llvm-project/issues/107629

After some more debugging, I find out that we will check access here at
8e010ac5a1/clang/lib/Sema/SemaInit.cpp (L7807)

And for `f()` inside code below, `Found.getAccess()` is `AS_none` hence
`CheckAddressOfMemberAccess` return `AR_accessible` directly.

```cpp
struct Base {
public:
  int f(int);
private:
  int f();  // expect-note {{declared private here}}
};

struct Derived : public Base {};

void f() {
  int(Derived::* public_f)(int) = &Derived::f;
  int(Derived::* private_f)() = &Derived::f;  // expect-error {{'f' is a private member of 'Base'}}
}
```

I think the `Found.getAccess()` is intended to be `AS_none` so I just
add one more access check for the `UnresolvedLookupExpr` when
`Found.getAccess()` is `AS_none`. If add the check unconditionally clang
will report lots of duplicate errors and cause several unit tests to
fail.

I also test the UB mentioned in
https://github.com/llvm/llvm-project/issues/107629 and clang now display
4 `false` as expecetd.

Co-authored-by: Erich Keane <ekeane@nvidia.com>
2025-06-10 11:50:22 -07:00
Cyndy Ishida
88f041f3e0
[clang][Darwin] Align all OS Versions for 26 (#143548)
* Translate the following versions to 26.
  * watchOS 12 -> 26
  * visionOS 3 -> 26
  * macos 16 -> 26
  * iOS 19 -> 26
  * tvOS 19 -> 26

* Emit diagnostics, but allow conversion when clients attempt to use
invalid gaps in OS versioning in availability.

* For target-triples, only allow "valid" versions for implicit
conversions.
2025-06-10 09:50:46 -07:00
Brandon Wu
9312d5beb3
[llvm][RISCV] Handle required features of intrinsic correctly (#143062)
Current approach generates intrinsic records when users specify
corresponding required features by using command line option.
However it's not able to handle features passed by using target
attributes correctly where each function might have different
features.
This patch resolves this by generating all of intrinsic records which
carry the required features in their function declaration using
attribute and check the required extensions in CheckBuiltinFunctionCall.

This should fix
[56592](https://github.com/llvm/llvm-project/issues/56592),
[134962](https://github.com/llvm/llvm-project/issues/134962) and
[121603](https://github.com/llvm/llvm-project/issues/121603)
2025-06-10 15:59:15 +08:00
Corentin Jabot
d56ce312d0
[Clang] Non-polymorphic trivially relocatable types can have [[trivial_abi]] (#143111)
Use the definition of trivially relocatable types to short-circuit some
checks for trivial_abi.

Note that this is mostly a no-op as there is a lot of overlap between
trivial_abi and trivial relocatability (ie, I can't envision a scenario
in which there would be a trivially relocatable type that would not be
eligible for trivial_abi based on its special member function... which
is good!)

Note that for bases and members, we need to check CanPassInRegister
rather than just relocation. So we do these checks first, which leads to
better diagnostics.
2025-06-10 07:30:06 +02:00
Shafik Yaghmour
28b753b185
[Clang][NFC] Add nullptr check in InitializationSequence::InitializeFrom (#143067)
Static analysis flagged that Var could be nullptr but we were not
checking in the branch and unconditionally dereferences the pointer.

Note, code was added by 576161cb6069
2025-06-09 14:28:47 -07:00
Corentin Jabot
c8009797d3
[Clang] Implement CWG2496 (#142975)
https://cplusplus.github.io/CWG/issues/2496.html

We failed to diagnose the following in C++23 mode

```
struct S {
    virtual void f(); // expected-note {{previous declaration is here}}
};

struct T : S {
    virtual void f() &;
};
```
2025-06-09 21:16:57 +02:00
Artem Belevich
59ef2c34a1
[CUDA] Disallow use of address_space(N) on CUDA device variables. (#142857)
The variables have implicit host-side shadow instances and explicit
address space attribute breaks them on the host.
2025-06-09 10:39:04 -07:00
Corentin Jabot
02f0f5c3ec
[Clang] Explain why a type is not replaceable. (#143265)
As a drive by fix the definition of replaceable, that did not correctly
implement https://eel.is/c++draft/class.prop#6.3
2025-06-09 17:05:25 +02:00
Corentin Jabot
62c9b0cab6
[Clang] Fix a crash when diagnosing a non relocatable with no copy ctr (#143350)
If lookup did not find a copy constructor, it would return nulll,
leading to an assert in `cast`.

Fixes #143325
2025-06-09 10:29:05 +02:00
Corentin Jabot
5c76ae2894
[Clang] Support constexpr asm at global scope. (#143268)
I previously failed to realize this feature existed...

Fixes #137459
Fixes #143242
2025-06-08 09:16:57 +02:00
Imad Aldij
bc931318a2
[Clang] Implement CWG2517 Useless restriction on use of parameter in constraint-expression (#132919)
Remove `[expr.prim.req.nested]` check which restrict that local
parameters in constraint-expressions can only appear as unevaluated
operands. This change makes the treatment of examples like `requires`
expressions and other constant expression contexts uniform, consistent
with the adoption of P2280.

References: https://cplusplus.github.io/CWG/issues/2517.html
Fixes  #132825

---------

Co-authored-by: cor3ntin <corentinjabot@gmail.com>
2025-06-07 11:31:04 +02:00
Shamshura Egor
eec9431d37
[Clang] Added explanation why a is trivial copyable evaluated to false. (#142341) 2025-06-07 09:55:40 +02:00
Kazu Hirata
4f304e2e72
[clang] Use llvm::count (NFC) (#143228) 2025-06-06 22:55:42 -07:00
Kazu Hirata
0ef1e69f22
[clang] Strip away lambdas (NFC) (#143226)
We don't need lambdas here.
2025-06-06 22:55:26 -07:00
Kazu Hirata
d953ca5659
[Sema] Drop const from a return type (NFC) (#143224) 2025-06-06 22:55:11 -07:00
Kazu Hirata
6ab6321d03
[clang] Use range-based for loops (NFC) (#143153)
Note that use of llvm::for_each is discouraged unless we have functors
readily available.
2025-06-06 09:16:41 -07:00
Haojian Wu
b6364ab955
[clang] Reduce TemplateDeclInstantiator size. (#142983)
This gives us another ~1.85% improvement (1617->1647 for the
`instantiation-depth-default.cpp`) on clang's template instantiation
depths,

No performance regressions have been observed:
https://llvm-compile-time-tracker.com/compare.php?from=702e228249906d43687952d9a2f3d2f90d8024c6&to=61be4bfea92d52cfc3e48a3cabb1bc80cbebb7fa&stat=instructions:u
2025-06-06 16:25:36 +02:00
Joe Nash
7ae6c4319e
[Sema] Fix bug in builtin AS override (#138141)
Fix the logic in rewriteBuiltinFunctionDecl to work when the builtin
has a pointer parameter with an address space and one without a fixed
address space. A builtin fitting these criteria was recently added.
Change the attribute string to perform type checking on it, so without
the sema change compilation would fail with a wrong number of arguments
error.
2025-06-06 09:31:32 -04:00
Younan Zhang
c3b870eb3f
[Clang] Fail the constraint substitution early after CWG2369 (#143096)
CWG2369 revealed another case where we were SFINAE'ing out the invalid
result of substitution, but the expression now makes the way into evaluation.

We switch to the concept specialization's context before we check it.
This ensures that we're able to realize the invalid expression earlier,
so we can avoid evaluating invalid expression, which is a hard error.

This also fixes #115838
2025-06-06 19:13:59 +08:00
Alexander Kornienko
f53216793e
Fix an error introduced in #138518 (#142988)
CXXParenListInitExpr arguments would lose casts leading to incorrect types being used (e.g. only 32 bits of a 64 bit value being initialized). See https://github.com/llvm/llvm-project/pull/138518#issuecomment-2906276916 and https://github.com/llvm/llvm-project/pull/138518#issuecomment-2944538713 for details and context.
2025-06-05 20:57:12 +02:00
Nick Sarnie
3b9ebe9201
[clang] Simplify device kernel attributes (#137882)
We have multiple different attributes in clang representing device
kernels for specific targets/languages. Refactor them into one attribute
with different spellings to make it more easily scalable for new
languages/targets.

---------

Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-06-05 14:15:38 +00:00
PiJoules
b194cf1e40
[clang] Function type attribute to prevent CFI instrumentation (#135836)
This introduces the attribute discussed in

https://discourse.llvm.org/t/rfc-function-type-attribute-to-prevent-cfi-instrumentation/85458.

The proposed name has been changed from `no_cfi` to
`cfi_unchecked_callee` to help differentiate from `no_sanitize("cfi")`
more easily. The proposed attribute has the following semantics:

1. Indirect calls to a function type with this attribute will not be
instrumented with CFI. That is, the indirect call will not be checked.
Note that this only changes the behavior for indirect calls on pointers
to function types having this attribute. It does not prevent all
indirect function calls for a given type from being checked.
2. All direct references to a function whose type has this attribute
will always reference the true function definition rather than an entry
in the CFI jump table.
3. When a pointer to a function with this attribute is implicitly cast
to a pointer to a function without this attribute, the compiler will
give a warning saying this attribute is discarded. This warning can be
silenced with an explicit C-style cast or C++ static_cast.
2025-06-04 11:19:26 -07:00
Nick Sarnie
a7f0b29733
[clang][ARM][AArch64] Reapply "Define intrinsics guarded by __has_builtin on all platforms (#128222)" (#140910)
The original change caused issues on MSVC due to a new warning thrown
inside MSVC headers. That was fixed
[here](https://github.com/llvm/llvm-project/pull/142019), so reapply
this commit. Original description below.

Instead of defining ARM ACLE intrinsics only on MSVC and guarding
wrapper functions in headers with __has_builtin, universally define the
intrinsics as target header builtins.
2025-06-04 14:41:59 +00:00
Nathan Gauër
20d70196c9
[HLSL][SPIR-V] Implement vk::ext_builtin_input attribute (#138530)
This variable attribute is used in HLSL to add Vulkan specific builtins
in a shader.
The attribute is documented here:

17727e88fd/proposals/0011-inline-spirv.md

Those variable, even if marked as `static` are externally initialized by
the pipeline/driver/GPU. This is handled by moving them to a specific
address space `hlsl_input`, also added by this commit.

The design for input variables in Clang can be found here:
355771361e/proposals/0019-spirv-input-builtin.md


Co-authored-by: Justin Bogner <mail@justinbogner.com>
2025-06-04 13:22:37 +02:00
Oliver Hunt
93314bd946
[clang][PAC] Add __builtin_get_vtable_pointer (#139790)
With pointer authentication it becomes non-trivial to correctly load the
vtable pointer of a polymorphic object.

__builtin_get_vtable_pointer is a function that performs the load and
performs the appropriate authentication operations if necessary.
2025-06-04 00:21:20 -07:00
Oliver Hunt
f72054a0cc
[clang] Correct FixIt ranges for unused capture warnings (#141148)
Fixes #106445 by using the lexer to find the correct range for the
removal FixIts. Previously the ranges that were generated assuming no
unsurprising formatting, which for the most part works. Being correct in
all cases requires using the lexer to find the bounding tokens for the
region to remove.

As part of this it adds Sema::getRangeForNextToken to wrap
Lexer::findNextToken.
2025-06-03 17:57:01 -07:00