57621 Commits

Author SHA1 Message Date
Orlando Cazalet-Hyams
375ca9f7b7 [KeyInstr][Clang] For stmt atom
This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
2025-04-07 14:17:35 +01:00
Orlando Cazalet-Hyams
38f3eec43e [KeyInstr][Clang] While stmt atom
See test comment for possible future improvement.

This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
2025-04-07 14:17:35 +01:00
Orlando Cazalet-Hyams
2ee4d451f7 [KeyInstr][Clang] Do stmt atom
See test comment for possible future improvement.

This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
2025-04-07 14:17:35 +01:00
Orlando Cazalet-Hyams
eeee08d6d9 [KeyInstr][Clang] Switch stmt atom
This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
2025-04-07 14:17:34 +01:00
Orlando Cazalet-Hyams
98ea64f7a1 [KeyInstr][Clang] If stmt atom
This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
2025-04-07 14:17:34 +01:00
Orlando Cazalet-Hyams
638b319d13 [KeyInstr][Clang] Catch variable init atom
This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
2025-04-07 14:17:34 +01:00
Orlando Cazalet-Hyams
c25359bdeb [KeyInstr][Clang] Member initalization atom
This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
2025-04-07 14:17:34 +01:00
Orlando Cazalet-Hyams
77f91f53a7 [KeyInstr][Clang] Agg copy atom 2025-04-07 14:17:33 +01:00
Orlando Cazalet-Hyams
c1ec75f22a [KeyInstr][Clang] Aggregate init + copy
This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
2025-04-07 14:17:33 +01:00
Orlando Cazalet-Hyams
8ce070ebdd [KeyInstr] Complex assignment atoms
This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
2025-04-07 14:17:33 +01:00
Orlando Cazalet-Hyams
678876993d Rename test & run C & C++ 2025-04-07 14:17:33 +01:00
Orlando Cazalet-Hyams
800fde97f2 Pre/Post Inc/Dec 2025-04-07 14:17:32 +01:00
Orlando Cazalet-Hyams
e92a5d1b0f Compound assign 2025-04-07 14:17:32 +01:00
Orlando Cazalet-Hyams
b6f42ab8be [KeyInstr][Clang] Multiple assignment (x = y = z) 2025-04-07 14:17:32 +01:00
Orlando Cazalet-Hyams
cdf3eef4a2 [KeyInstr][Clang] Assignment atom group
This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
2025-04-07 14:17:31 +01:00
Orlando Cazalet-Hyams
a92afbf589 [KeyInstr][Clang] Static variable init atom
This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
2025-04-07 14:17:31 +01:00
Orlando Cazalet-Hyams
eef73d31b6 [KeyInstr][Clang] Init pattern atom 2025-04-07 14:17:31 +01:00
Orlando Cazalet-Hyams
3eae9188c3 [KeyInstr] init-agg pattern 2025-04-07 14:17:31 +01:00
Orlando Cazalet-Hyams
1f1f1d5d88 shouldUseBZeroPlusStoresToInitialize 2025-04-07 14:17:30 +01:00
Orlando Cazalet-Hyams
06b9688ecb [KeyInstr][Clang] Agg init atom
This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
2025-04-07 14:17:30 +01:00
Orlando Cazalet-Hyams
29d5428307 [KeyInstr][Clang] Scalar init atom
This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
2025-04-07 14:17:30 +01:00
Orlando Cazalet-Hyams
7132dd30a1 [KeyInstr][Clang] Add Clang option -g[no-]key-instructions
This needs to be driver level to pass an -mllvm flag to LLVM.

Keep the flag help-hidden as the feature is under development.

---

This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
2025-04-07 14:17:29 +01:00
Cassandra Beckley
9ce77255b9
[HLSL] Add __spirv__ macro (#132848)
This macro can be used by HLSL code to detect that it is being compiled
for the SPIR-V target.
2025-03-28 10:49:19 -04:00
Daniel Chen
316bb89c94
[Driver] Enable LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON on AIX. (#132821)
In the wake of discussion in PR #131200 and internal discussion after,
we will add support for `LLVM_ENABLE_PER_TARGET_RUNTIME=ON` for AIX
instead of disable it. I already reverted the change in PR #131200.

The default value of the option is still OFF on AIX.
2025-03-28 09:22:02 -04:00
Joseph Huber
772173f548
[Clang][AMDGPU] Remove special handling for COV4 libraries (#132870)
Summary:
When we were first porting to COV5, this lead to some ABI issues due to
a change in how we looked up the work group size. Bitcode libraries
relied on the builtins to emit code, but this was changed between
versions. This prevented the bitcode libraries, like OpenMP or libc,
from being used for both COV4 and COV5. The solution was to have this
'none' functionality which effectively emitted code that branched off of
a global to resolve to either version.

This isn't a great solution because it forced every TU to have this
variable in it. The patch in
https://github.com/llvm/llvm-project/pull/131033 removed support for
COV4 from OpenMP, which was the only consumer of this functionality.
Other users like HIP and OpenCL did not use this because they linked the
ROCm Device Library directly which has its own handling (The name was
borrowed from it after all).

So, now that we don't need to worry about backward compatibility with
COV4, we can remove this special handling. Users can still emit COV4
code, this simply removes the special handling used to make the OpenMP
device runtime bitcode version agnostic.
2025-03-28 07:35:16 -05:00
Nico Weber
c4bc1b1d81
[clang] Update Mach-O ptrauth driver defaults (#132834)
Xcode clang default-enables a bunch of ptrauth flags when targeting
arm64e. Let's match that.
2025-03-28 08:34:25 -04:00
Paul Schwabauer
8a3fe30a0a
[PATCH] [clang][frontend] Fix serialization for CXXConstructorDecl (refs llvm#132794) (#133077)
When retrieving the ExplicitSpecifier from a CXXConstructorDecl, one of
its canonical declarations is returned. To correctly write the
declaration record the ExplicitSpecifier of the current declaration must
be used.

Failing to do so results in a crash during deserialization.
2025-03-28 11:34:24 +01:00
Balázs Benics
319045d8c4
[analyzer] Add metrics tracking time spent in Z3 solver (#133236)
These metrics would turn out to be useful for verifying an upgrade of Z3.
2025-03-28 11:26:28 +01:00
Donát Nagy
50d4ae4a62
[analyzer] Fix format attribute handling in GenericTaintChecker (#132765)
Previously `optin.taint.GenericTaint` misinterpreted the parameter
indices and produced false positives in situations when a [format
attribute](https://clang.llvm.org/docs/AttributeReference.html#format)
is applied on a non-static method. This commit fixes this bug
2025-03-28 10:20:26 +01:00
Mallikarjuna Gouda
1318a7bb09
Reland [MIPS] Define SubTargetFeature for i6500 cpu (#132907) (#133366)
Relands #132907 with a fix in the testcase:
clang/test/CodeGen/Mips/subtarget-feature-test.c
enable this test for only mips64 target

PR #130587 defined same SubTargetFeature for CPUs i6400 and i6500 which
resulted into following warning when -mcpu=i6500 was used:

+i6500' is not a recognized feature for this target (ignoring feature)

This PR fixes above issue by defining separate SubTargetFeature for
i6500.
2025-03-28 09:49:38 +01: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
Ryosuke Niwa
a285be320a
[WebKit Checkers] Recognize Objective-C and CF pointer conversion functions. (#132784)
Recognize dynamic_objc_cast, checked_objc_cast, dynamic_cf_cast, and
checked_cf_cast.
2025-03-27 15:47:38 -07:00
Joseph Huber
e9d517d183
[Clang] Handle -flto-partitions generically and forward it properly (#133283)
Summary:
The https://github.com/llvm/llvm-project/pull/128509 patch introduced
`--flto-partitions`. This was marked as a HIP only argument, and was
also spelled and handled incorrectly for an `-f` option. This patch
makes the handling generic for `ld.lld` consumers.

This also fixes some issues with emitting the flags being put after the
default arguments, preventing users from overriding them. Also, forwards
things properly for the new driver so we can test this.
2025-03-27 14:31:35 -05:00
Ariel-Burton
fb993cd229
Add guard to for loop test clang/test/Sema/for.c (#133169)
Commit 20b7f5982622f includes a case that checks diagnostics for for
loops using thread locals.
This fails on platforms which do not support TLS.
This change adds guards to run this part of the test iff the feature is
supported.
2025-03-27 14:26:06 -04:00
Aaron Ballman
4480f26e93 Fix failing test case for _Countof
Test just needs an explicit triple that was missed.
2025-03-27 14:07:57 -04:00
cor3ntin
ae54f476f7
[Clang] Improve subsumption. (#132849)
The main goal of this patch is to improve the
performance of concept subsumption by

- Making sure literal (atomic) clauses are de-duplicated (Whether 2
atomic constraint is established during the initial normal form
production).
 - Eagerly removing duplicated clauses.

This should minimize the risks of exponentially large formulas that can
be produced by a naive {C,D}NF transformation.

While at it, I restructured that part of the code to be a bit clearer.

Subsumption of fold expanded constraint is also cached.

---

Note that removing duplicated clauses seems to be necessary and
sufficient to have acceptable performance on anything that could be
construed as reasonable code.

Ultimately, the number of clauses is always going to be fairly small
(but $2^{fairly\ small}$ is quickly *fairly large*..).

I went too far in the rabbit hole of Tseitin transformations etc, which
was much faster but would then require to check satisfiabiliy to
establish subsumption between some constraints (although it was good
enough to pass all but ones of our tests...).

It doesn't help that the C++ standard has a very specific definition of
subsumption that is really more of an implication...

While that sort of musing is fascinating, it was ultimately a fool's
errand, at least until such time that there is more motivation for a SAT
solver in clang (clang-tidy can after all use z3!).

Here be dragons.

Fixes #122581
2025-03-27 18:23:58 +01:00
Aaron Ballman
00c43ae235
[C2y] Implement WG14 N3369 and N3469 (_Countof) (#133125)
C2y adds the `_Countof` operator which returns the number of elements in
an array. As with `sizeof`, `_Countof` either accepts a parenthesized
type name or an expression. Its operand must be (of) an array type. When
passed a constant-size array operand, the operator is a constant
expression which is valid for use as an integer constant expression.

This is being exposed as an extension in earlier C language modes, but
not in C++. C++ already has `std::extent` and `std::size` to cover these
needs, so the operator doesn't seem to get the user enough benefit to
warrant carrying this as an extension.

Fixes #102836
2025-03-27 13:23:16 -04:00
Sarah Spall
f612d70525
[HLSL] Add new int overloads for math builtins (#133162)
Add int overloads which cast the various ints to a float and call the
float builtin.
These overloads are conditional on hlsl version 202x or earlier.
Add tests and puts tests in own files, including some of the tests added
for double overloads.
Closes #128229
2025-03-27 09:34:25 -07:00
Joseph Huber
d0aa1f9c43
[Clang] Make --lto-partitions only default for HIP (#133164)
Summary:
The default behavior for LTO on other targets does not specify the
number of LTO partitions. Recent changes made this default to 8 on
AMDGPU which had some issues with the `libc` project. The option to
disable this is HIP only so I think for now we should restrict this just
to HIP.

I'm definitely on board with getting some more parallelism here, but I
think it should probably be restricted to just offloading languages. The
new driver goes through the `--target=amdgcn-amd-amdhsa` for its output,
which means we'd need to forward the default somehow.
2025-03-27 07:34:57 -05:00
Younan Zhang
a9672515ce
[Clang] Correct the DeclRefExpr's Type after the initializer gets instantiated (#133212)
The instantiation of a VarDecl's initializer might be deferred until the
variable is actually used. However, we were still building the
DeclRefExpr with a type that could later be changed by the initializer's
instantiation, which is incorrect when incomplete arrays are involved.

Fixes #79750
Fixes #113936
Fixes #133047
2025-03-27 19:40:02 +08:00
Ryotaro Kasuga
6c56a842b7
[clang][CodeGen] Generate follow-up metadata for loops in correct format (#131985)
When pragma of loop transformations is specified, follow-up metadata for
loops is generated after each transformation. On the LLVM side,
follow-up metadata is expected to be a list of properties, such as the
following:

```
!followup = !{!"llvm.loop.vectorize.followup_all", !mp, !isvectorized}
!mp = !{!"llvm.loop.mustprogress"}
!isvectorized = !{"llvm.loop.isvectorized"}
```

However, on the clang side, the generated metadata contains an MDNode
that has those properties, as shown below:

```
!followup = !{!"llvm.loop.vectorize.followup_all", !loop_id}
!loop_id = distinct !{!loop_id, !mp, !isvectorized}
!mp = !{!"llvm.loop.mustprogress"}
!isvectorized = !{"llvm.loop.isvectorized"}
```
According to the
[LangRef](https://llvm.org/docs/TransformMetadata.html#transformation-metadata-structure),
the LLVM side is correct. Due to this inconsistency, follow-up metadata
was not interpreted correctly, e.g., only one transformation is applied
when multiple pragmas are used.

This patch fixes clang side to emit followup metadata in correct format.
2025-03-27 20:29:37 +09:00
Djordje Todorovic
58a0c9570c
Revert "[MIPS] Define SubTargetFeature for i6500 cpu" (#133215)
Reverts llvm/llvm-project#132907 due to some test failures.
2025-03-27 09:06:02 +01:00
Mallikarjuna Gouda
6294325a53
[MIPS] Define SubTargetFeature for i6500 cpu (#132907)
PR #130587 defined same SubTargetFeature for CPUs i6400 and i6500 which
resulted into following warning when -mcpu=i6500 was used:

+i6500' is not a recognized feature for this target (ignoring feature)

This PR fixes above issue by defining separate SubTargetFeature for
i6500.
2025-03-27 08:48:34 +01:00
Chuanqi Xu
80f216db53 [C++20] [Modules] Add a test
A test from a regression in the downstream.

The test should be always good.
2025-03-27 14:04:41 +08:00
Craig Topper
16d1942c06 [RISCV] Drop '-x c' from riscv-target-features.c. NFC 2025-03-26 21:20:04 -07:00
Ryosuke Niwa
2b43ecd27b
[webkit.RefCntblBaseVirtualDtor] Add support for NoVirtualDestructorBase. (#132497)
This PR adds the support for WTF::NoVirtualDestructorBase, which
signifies to the checker that the class is exempt from having a virtual
destructor.
2025-03-26 16:57:49 -07:00
QuietMisdreavus
3386156b1e
[clang][ExtractAPI] fix a couple crashes when used via libclang (#132297)
This PR fixes two crashes in ExtractAPI that occur when decls are
requested via libclang:

- A null-dereference would sometimes happen in
`DeclarationFragmentsBuilder::getFragmentsForClassTemplateSpecialization`
when the template being processed was loaded indirectly via a typedef,
with parameters filled in. The first commit loads the template parameter
locations ahead of time to perform a null check before dereferencing.
- An assertion (or another null-dereference) was happening in
`CXXRecordDecl::bases` when processing a forward-declaration (i.e. a
record without a definition). The second commit guards the use of
`bases` in `ExtractAPIVisitorBase::getBases` by first checking that the
decl in question has a complete definition.

The added test `extract-api-cursor-cpp` adds tests for these two
scenarios to protect against the crash in the future.

Fixes rdar://140592475, fixes rdar://123430367
2025-03-26 17:46:21 -06:00
Hans Wennborg
304454f9e7
[clang-cl] Accept the --warning-suppression-mappings= option (#133092) 2025-03-26 15:31:10 -04:00
Matheus Izvekov
a942d7f810
[clang] fix deduction of member pointers with dependent named classes (#133113)
This fixes a regression when interpreting a nested name specifier for
deduction purposes in member pointers.

This introduces a helper for fully translating a nested name specifier
into a type.

This regression was introduced here:
https://github.com/llvm/llvm-project/pull/130537
and was reported here:
https://github.com/llvm/llvm-project/pull/132401#issuecomment-2751489581

No release notes, since this regression was never released.
2025-03-26 15:51:41 -03:00
Andy Kaylor
7563e31127
[CIR] Implement lowering of int-to-bool casts (#132996)
Lowering of int-to-bool casts had been left as NYI because the incubator
implemented it by lowering to cir.cmp, which hasn't been upstreamed yet,
but there is no reason this cast can't be lowered directly to LLVM's
compare operation when we're lowering directly to the LLVM dialect.

This change lowers the cast directly to an LLVM compare to zero.
2025-03-26 09:44:05 -07:00