117390 Commits

Author SHA1 Message Date
Simon Pilgrim
1b4fe26343
[clang][x86] Add release note entries describing recent work to making SSE intrinsics generic and usable with constexpr (#154737)
I haven't created an exhaustive list of intrinsic changes, but I suppose I could if people see a strong need for it.
2025-08-22 09:59:10 +01:00
Simon Pilgrim
8d7df8bba1
[X86] Allow AVX2 per-element shift intrinsics to be used in constexpr (#154780)
This handles constant folding for the AVX2 per-element shift intrinsics, which handle out of bounds shift amounts (logical result = 0, arithmetic result = signbit splat)

AVX512 intrinsics will follow in follow up patches

First stage of #154287
2025-08-22 09:24:24 +01:00
Brad Smith
0fff460592
[Driver] DragonFly does not support C11 threads (#154886) 2025-08-22 02:02:52 -04:00
Frederik Harwath
d6fae7f921
Reapply "[Clang] Take libstdc++ into account during GCC detection" #145056 (#154487)
The Generic_GCC::GCCInstallationDetector class picks the GCC installation directory with the largest version number. Since the location of the libstdc++ include directories is tied to the GCC version, this can break C++ compilation if the libstdc++ headers for this particular GCC version are not available. Linux distributions tend to package the libstdc++ headers separately from GCC. This frequently leads to situations in which a newer version of GCC gets installed as a dependency of another package without installing the corresponding libstdc++ package. Clang then fails to compile C++ code because it cannot find the libstdc++ headers. Since libstdc++ headers are in fact installed on the system, the GCC installation continues to work, the user may not be aware of the details of the GCC detection, and the compiler does not recognize the situation and emit a warning, this behavior can be hard to understand - as witnessed by many related bug reports over the years.

The goal of this work is to change the GCC detection to prefer GCC installations that contain libstdc++ include directories over those which do not. This should happen regardless of the input language since picking different GCC installations for a build that mixes C and C++ might lead to incompatibilities.
Any change to the GCC installation detection will probably have a negative impact on some users. For instance, for a C user who relies on using the GCC installation with the largest version number, it might become necessary to use the --gcc-install-dir option to ensure that this GCC version is selected.
This seems like an acceptable trade-off given that the situation for users who do not have any special demands on the particular GCC installation directory would be improved significantly.
 
This patch does not yet change the automatic GCC installation directory choice. Instead, it does introduce a warning that informs the user about the future change if the chosen GCC installation directory differs from the one that would be chosen if the libstdc++ headers are taken into account.

See also this related Discourse discussion: https://discourse.llvm.org/t/rfc-take-libstdc-into-account-during-gcc-detection/86992.

This patch reapplies #145056. The test in the original PR did not specify a target in the clang RUN line and used a wrong way of piping to FileCheck.
2025-08-22 07:39:11 +02:00
Aiden Grossman
9d2a66fb32 [Clang] Slightly clean up __cpuidex_conflict.c
This was intended to be fixed in #154217, but given that didn't land, it
still needs to be done. I think it still makes sense to have this change
in.
2025-08-22 01:37:17 +00:00
Anthony Latsis
0bc02096f6
[clang] Upstream clang::CodeGen::getConstantSignedPointer (#154453)
This function was introduced to Swift's fork in

https://github.com/swiftlang/llvm-project/commit/a9dd959e60c32#diff-db27b2738ad84e3f1093f9174710710478f853804d995a6de2816d1caaad30d1.

The Swift compiler cannot use `CodeGenModule::getConstantSignedPointer`,
to which it forwards, because that is a private interface.
2025-08-21 17:55:57 -07:00
Kazu Hirata
67e95c6f60
[llvm] Proofread DebuggingCoroutines.rst (#154681) 2025-08-21 15:03:32 -07:00
Justin Riddell
fa67855c99
[CIR] Handle FunctionToPointerDecay casts (#153657) (#154060)
Add upstream support for handling implicit FunctionToPointerDecay casts
2025-08-21 14:40:14 -07:00
Joseph Huber
c704dabe88
[Clang] Fix incorrect return type for __builtin_shufflevector (#154817)
Summary:
The `__builtin_shufflevector` call would return a GCC vector in all
cases where the vector type was increased. Change this to preserve
whether or not this was an extended vector.

Fixes: https://github.com/llvm/llvm-project/issues/107981
2025-08-21 16:13:52 -05:00
Michael Buch
8fa55a023b
[clang][DebugInfo][test] Move debug-info tests from CodeGenObjC to DebugInfo directory (#154781)
This patch works towards consolidating all Clang debug-info into the
`clang/test/DebugInfo` directory
(https://discourse.llvm.org/t/clang-test-location-of-clang-debug-info-tests/87958).

Here we move only the `clang/test/CodeGenObjC` tests.

The list of files i came up with is:
1. searched for anything with `*debug-info*` in the filename
2. searched for occurrences of `debug-info-kind` in the tests
2025-08-21 22:09:34 +01:00
Dan Liew
09612007f1
[NFC][Diagnostics] Reformat DiagnosticIDs.h and AllDiagnostics.h (#154628)
When trying to add a new diagnostic category (e.g. #154618) I discovered
`clang-format` really wanted to reformat these files.

My initial attempt was just to suppress the reformatting with `//
clang-format (on|off)` directives but reviewers preferred just
reformatting the files so these two files have been completely
reformatted.

`clang-format` has been disabled for the enum that declares the
`DIAG_START_*` constants because its much less readable after
formatting.
2025-08-21 14:06:49 -07:00
ykhatav
38f0b9e6d9
Fix scope of typedefs present inside a template class (#146729)
When a typedef is declared within a templated class, clang incorrectly
assigns the typedef to the compilation unit (CU) scope rather than the
intended scope of the templated class. This issue arises because, during
the creation of the typedef, the context lookup in the RegionMap fails
to locate the templated class, despite its prior creation.
The problem stems from the way the context is stored in the RegionMap.
When handling templated types, the current implementation stores the
class specialization rather than the templated declaration itself. This
leads to a mismatch when attempting to retrieve the context for the
typedef.
To address this issue, the solution involves modifying the
CreatedLimitedType() function. Specifically, when a struct or class is a
templated type, we should store the actual templated declaration in the
RegionMap instead of the class specialization. This ensures that
subsequent lookups for context, such as those needed for typedef
declarations, correctly identify the templated class scope.
Fixes https://github.com/llvm/llvm-project/issues/91451
2025-08-21 16:58:25 -04:00
Tom Honermann
c80b7822e3
[NFC][SYCL] Test use of sycl_kernel_entry_point with null declarations and statements. (#154583)
The `sycl_kernel_entry_point` attribute only appertains to functions.
This change adds missing tests to validate that an appropriate
diagnostic is issued for likely unintentional application of the
attribute to a null declaration or a null statement; perhaps due to an
unintended semicolon.
2025-08-21 14:47:07 -04:00
Timm Baeder
8b091961b1
[clang][bytecode] Implement Pointer::getType() for function pointers (#154788)
Fixes #152920
2025-08-21 20:01:22 +02:00
Anchu Rajendran S
bce9b6d177
[Flang][Flang-Driver]Fix to add atomic control options in non-fc1 mode (#154638) 2025-08-21 10:15:33 -07:00
Andy Kaylor
c5466c64d4
[CIR] Add CIR vtable attribute (#154415)
This adds the #cir.vtable attribute definition and verification.
Generation of the vtable will be implemented in a later change.
2025-08-21 09:52:14 -07:00
7mile
761125f267
[CIR][Dialect] Add SourceLangAttr (#152511)
This patch upstreams `SourceLangAttr` and its CodeGen logic in the CGM,
which encodes the source language in CIR.
2025-08-21 09:51:37 -07:00
Shafik Yaghmour
436f391d1d
[Clang][Codegen][NFC] Apply rule of three to some classes (#154671)
Static analysis flagged these classes as having implemented the
destructor but not applying rule of three. This could lead to accidental
misuse and so it makes sense to apply it.
2025-08-21 09:36:25 -07:00
Andres-Salamanca
fc62990657
[CIR] Upstream GotoSolver pass (#154596)
This PR upstreams the GotoSolver pass.  
It works by walking the function and matching each label to a goto. If a
label is not matched to a goto, it is removed and not lowered.
2025-08-21 11:02:29 -05:00
Timm Baeder
3923adfa3f
[clang][bytecode] Guard strcmp against differing element types (#154777)
This can happen when casts are involved.

Fixes #154006
2025-08-21 18:02:08 +02:00
Steven Perron
a53e73e6ef
[SPIRV][HLSL] Add DXC compatibility option for extension (#151554)
The default behaviour in DXC is to allow all extesions the compiler
knows about. We did the same in clang: all extensions that clang knows
about. However, this causes the shader to use different extensions
because the two compilers have different sets of extensions.

To avoid using a new extension when moving from DXC to Clang, we add the
special DXC suboptions to `-fspv-extension`. If `-fspv-extension=DXC` is
used, then the available extensions will be those available in DXC.

---------

Co-authored-by: Chris B <beanz@abolishcrlf.org>
2025-08-21 14:43:29 +00:00
Timm Baeder
3f97736181
[clang][bytecode] Implement ia32_select* builtins (#154758) 2025-08-21 16:34:57 +02:00
Aaron Ballman
17eb05ddd3
Revert "[C++] Expose nullptr_t from stddef.h in C++ mode" (#154767)
Reverts llvm/llvm-project#154599

It seems to be causing staging failures:
    https://lab.llvm.org/staging/#/builders/192/builds/1329
    https://lab.llvm.org/staging/#/builders/192/builds/1330
2025-08-21 10:05:41 -04:00
Aaron Ballman
7d167f4564
[C++] Expose nullptr_t from stddef.h in C++ mode (#154599)
The C++ standard requires stddef.h to declare all of its contents in the
global namespace. We were only doing it when trying to be compatible
with Microsoft extensions. Now we expose in C++11 or later, in addition
to exposing it in Microsoft extensions mode.

Fixes #154577
2025-08-21 09:11:41 -04:00
Timm Baeder
f09ac1bf86
[clang][bytecode] Fix an out-of-bounds access with ia32_pmul* (#154750)
... builtins. We used to access the I'th index of the output vector, but
that doesn't work since the output vector is only half the size of the
input vector.
2025-08-21 15:09:08 +02:00
Aaron Ballman
a33e505c1a
[C99] Update documentation for scope of variables in loops; NFC (#154744)
I tracked down the document which changed the way variables are handled
in for loops for C99, it was the same document that allowed mixing code
and declarations but the editor's report made it seem like the features
came from different papers.

This is an extension we backported to C89 but it's sufficiently distinct
in the tracking page so I've added it explicitly to the backported
features documentation.
2025-08-21 12:46:57 +00:00
Timm Baeder
2ea5ec78db
[clang][bytecode] Fix a crash in Destroy op (#154695)
The local we're destroying might've been created for an expression, in
which case asDecl() on the DeclDesc returns nullptr.

Fixes #152958
2025-08-21 13:23:57 +02:00
Timm Baeder
c9bb3bdbca
[clang][bytecode] Fix a crash with typeid pointers (#154692)
That code is from a time when typeid pointers didn't exist. We can get
there for non-block, non-integral pointers, but we can't meaningfully
handle that case. Just return false.

Fixes #153712
2025-08-21 13:13:02 +02:00
Timm Baeder
21bd3a7fa8
[clang][bytecode] Check for unknown size array pointers in InitField* (#154689)
This can happen when the base pointer is an unknown size array, where
!isOnePastEnd(), but isPastEnd().

Fixes #153990
2025-08-21 13:01:45 +02:00
macurtis-amd
0c480dd4b6
[clang][CodeGen] cast addr space of ReturnValue if needed (#154380)
Fixes a bug on AMDGPU targets where a pointer was stored as address
space 5, but then loaded as address space 0.

Issue found as part of [Kokkos](https://github.com/kokkos/kokkos)
testing, specifically `hip.atomics` (see
[core/unit_test/TestAtomics.hpp](https://github.com/kokkos/kokkos/blob/develop/core/unit_test/TestAtomics.hpp)).

Issue was introduced by commit
[39ec9de7c230](https://github.com/llvm/llvm-project/commit/39ec9de7c230)
- [clang][CodeGen] sret args should always point to the alloca AS, so
use that (https://github.com/llvm/llvm-project/pull/114062).
2025-08-21 04:38:55 -05:00
Simon Pilgrim
4da69721f9 [X86] test_mm512_mask_fmadd_ps - add missing select checks 2025-08-21 10:27:06 +01:00
Ilya Biryukov
26d4e56be8 [Clang] Fix dedup-types-builtin.cpp test when -std=c++20
It was previously failing because of a warning marking a C++20 feature
as an extension.

This is a follow-up to 85043c1c146fd5658ad4c5b5138e58994333e645 that
introduced the test.
2025-08-21 11:05:02 +02:00
Michael Buch
f2aedc21f9
[clang][DebugInfo][test] Move debug-info tests from CodeGenCXX to DebugInfo directory (#154538)
This patch works towards consolidating all Clang debug-info into the
`clang/test/DebugInfo` directory
(https://discourse.llvm.org/t/clang-test-location-of-clang-debug-info-tests/87958).

Here we move only the `clang/test/CodeGenCXX` tests. I created a `CXX`
subdirectory for now because many of the tests I checked actually did
seem C++-specific. There is probably overlap between the `Generic` and
`CXX` subdirectory, but I haven't gone through and audited them all.

The list of files i came up with is:
1. searched for anything with `*debug-info*` in the filename
2. searched for occurrences of `debug-info-kind` in the tests

There's a couple of tests in `clang/test/CodeGenCXX` that still set
`-debug-info-kind`. They probably don't need to do that, but I'm not
changing that as part of this PR.
2025-08-21 09:26:08 +01:00
Simon Pilgrim
e4b110ab9f
[Headers][X86] Allow FMA3/FMA4 vector intrinsics to be used in constexpr (#154558)
Now that #152455 is done, we can make all the vector fma intrinsics that wrap __builtin_elementwise_fma to be constexpr

Fixes #154555
2025-08-21 09:09:40 +01:00
Mythreya Kuricheti
0977a6d9e7
[clang][CodeComplete] Consider qualifiers of explicit object parameters in overload suggestions (#154041)
Fixes https://github.com/llvm/llvm-project/issues/109608
2025-08-21 02:32:41 -04:00
Timm Baeder
e0acf6592b
[clang][bytecode] Call CheckFinalLoad in all language modes (#154496)
Fixes #153997
2025-08-21 08:24:09 +02:00
Carlos Galvez
3baddbbb0a
Do not trigger -Wmissing-noreturn on lambdas prior to C++23 (#154545)
Fixes #154493

Co-authored-by: Carlos Gálvez <carlos.galvez@zenseact.com>
2025-08-21 07:30:57 +02:00
Sirui Mu
91569fa030
[CIR][NFC] Use Op::create to create CIR operations in CIRGenBuilder (#154540) 2025-08-21 09:46:45 +08:00
Craig Topper
8cb6bfe05a [RISCV] Reduce ManualCodeGen for RVV intrinsics with rounding mode. NFC
Operate directly on the existing Ops vector instead of copying to
a new vector. This is similar to what the autogenerated codegen
does for other intrinsics.
2025-08-20 17:53:46 -07:00
Craig Topper
ac8f0bb070 [RISCV] Reduce ManualCodeGen for segment load/store intrinsics. NFC
Operate directly on the existing Ops vector instead of copying to
a new vector. This is similar to what the autogenerated codegen
does for other intrinsics.

This reduced the clang binary size by ~96kb on my local Release+Asserts
build.
2025-08-20 15:02:24 -07:00
Alan Zhao
904b4f5a27
[clang][timers][modules] Fix a timer being started when it's running (#154231)
`ASTReader::FinishedDeserializing()` calls
`adjustDeductedFunctionResultType(...)` [0], which in turn calls
`FunctionDecl::getMostRecentDecl()`[1]. In modules builds,
`getMostRecentDecl()` may reach out to the `ASTReader` and start
deserializing again. Starting deserialization starts `ReadTimer`;
however, `FinishedDeserializing()` doesn't call `stopTimer()` until
after it's call to `adjustDeductedFunctionResultType(...)` [2]. As a
result, we hit an assert checking that we don't start an already started
timer [3]. To fix this, we simply don't start the timer if it's already
running.

Unfortunately I don't have a test case for this yet as modules builds
are notoriously difficult to reduce.

[0]:
4d2288d318/clang/lib/Serialization/ASTReader.cpp (L11053)
[1]:
4d2288d318/clang/lib/AST/ASTContext.cpp (L3804)
[2]:
4d2288d318/clang/lib/Serialization/ASTReader.cpp (L11065-L11066)
[3]:
4d2288d318/llvm/lib/Support/Timer.cpp (L150)
2025-08-20 21:53:43 +00:00
Andy Kaylor
59b33242af
[CIR][NFC] Fix warning in MemOrder lowering (#154609)
This fixes a warning about having a default case in a fully covered enum
switch statement.
2025-08-20 14:30:22 -07:00
Isaac Nudelman
c6fa115b2d
[clang][analyzer] Relax assertion for non-default address spaces in the cstring checker (#153498)
Prevent an assertion failure in the cstring checker when library
functions like memcpy are defined with non-default address spaces.

Adds a test for this case.
2025-08-20 16:07:54 -05:00
Shafik Yaghmour
2a66ce5edb
[Clang][NFC] Clarify some SourceManager related code (#153527)
Static analysis flagged the columns - 1 code, it was correct but the
assumption was not obvious. I document the assumption w/ assertions.

While digging through related code I found getColumnNumber that looks
wrong at first inspection and adding parentheses makes it clearer.
2025-08-20 13:57:37 -07:00
Matheus Izvekov
e1dbe093c4
[clang] build UnresolvedUsingType for constructor initializers (#154592)
When building the base type for constructor initializer, the case of an
UnresolvedUsingType was not being handled.

For the non-dependent case, we are also skipping adding the UsingType,
but this is just missing information in the AST. A FIXME for this is
added.

This fixes a regression introduced in #147835, which was never released,
so there are no release notes.

Fixes #154436
2025-08-20 16:24:41 -03: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
9888f0c3c4
[Clang] Add builtins for masked vector loads / stores (#154464)
Summary:
Clang has support for boolean vectors, these builtins expose the LLVM
instruction of the same name. This differs from a manual load and select
by potentially suppressing traps from deactivated lanes.

Fixes: https://github.com/llvm/llvm-project/issues/107753
2025-08-20 13:33:32 -05:00
Joseph Huber
2f6b747997
[Clang] Add queryable feature 'ext_vector_type_boolean' for SIMD masks (#154227)
Summary:
We added boolean vectors in clang 15 and wish to extend them further in
clang-22. However, there's no way to query for their support as they are
separate to the normal extended vector type. This adds a feature so we
can check for it as a feature directly.
2025-08-20 13:33:02 -05:00
Alexandre Ganea
410a1341b5 [clang][bytecode] Silence unused variable warning 2025-08-20 14:10:05 -04:00
Yitzhak Mandelbaum
2be52f309e
[clang][dataflow] Fix uninitialized memory bug. (#154575)
Commit #3ecfc03 introduced a bug involving an uninitialized field in
`exportLogicalContext`. This patch initializes the field properly.
2025-08-20 13:36:42 -04:00