59714 Commits

Author SHA1 Message Date
Craig Topper
e67ec12640
[RISCV] Remove experimental from Smctr and Ssctr. (#153903)
These extensions were ratified in November 2024.
2025-08-15 17:18:09 -07:00
Peter Collingbourne
568c23bbd3
Frontend: Define __SANITIZE_*__ macros for certain sanitizers.
Per discussion with @ojhunt and @AaronBallman we are moving towards
predefined macros and away from __has_feature and __has_extension
for detecting sanitizers and other similar features. The rationale
is that __has_feature is only really meant for standardized features
(see the comment at the top of clang/include/clang/Basic/Features.def),
and __has_extension has the issues discovered as part of #153104.

Let's start by defining macros for ASan, HWASan and TSan, consistently
with gcc.

Reviewers: vitalybuka, ojhunt, AaronBallman, fmayer

Reviewed By: fmayer, vitalybuka

Pull Request: https://github.com/llvm/llvm-project/pull/153888
2025-08-15 16:13:23 -07:00
Morris Hafner
df0e9f3a2d
[CIR] Implement __builtin_return_address and __builtin_frame_address (#153698)
This adds ReturnAddrOp and FrameAddrOp that represent
__builtin_return_address and __builtin_frame_address and the respective
lowering to LLVM parts.

---------

Co-authored-by: Andy Kaylor <akaylor@nvidia.com>
2025-08-16 00:47:04 +02:00
Andy Kaylor
0cd35e7afd
[CIR] Add cir.vtable.get_vptr operation (#153630)
This adds support for the cir.vtable.get_vptr operation and uses it to
initialize the vptr member during constructors of dynamic classes.
2025-08-15 15:14:51 -07:00
Matheus Izvekov
5c51a88f19
[clang] fix DependentNameType -> UnresolvedUsingType transforms (#153862) 2025-08-15 17:21:55 -03:00
Simon Pilgrim
92cb0414ca [X86] avx512vnni-builtins.c / avx512vlvnni-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-15 17:55:33 +01:00
keinflue
af96ed6bf6
[clang] Inject IndirectFieldDecl even if name conflicts. (#153140)
This modifies InjectAnonymousStructOrUnionMembers to inject an
IndirectFieldDecl and mark it invalid even if its name conflicts with
another name in the scope.

This resolves a crash on a further diagnostic
diag::err_multiple_mem_union_initialization which via
findDefaultInitializer relies on these declarations being present.

Fixes #149985
2025-08-15 09:43:29 -07:00
Simon Pilgrim
2c20a9bfb3 [X86] avx512bf16-builtins.c / avx512vlbf16-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-15 17:38:43 +01:00
Simon Pilgrim
38eb14f27c [X86] avx512vbmi2-builtins.c / avx512vlvbmi2-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-15 16:35:16 +01:00
Simon Pilgrim
7df862818e [X86] avx512vbmi-builtins.c / avx512vbmivl-builtin.c - add C/C++ and 32/64-bit test coverage 2025-08-15 16:35:15 +01:00
Simon Pilgrim
09267f6720 [X86] avx512vp2intersect-builtins.c / avx512vlvp2intersect-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-15 15:39:12 +01:00
Simon Pilgrim
17dd57b00e [X86] avxvnni-builtins.c / avxvnniint8-builtins.c / avxvnniint16-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-15 15:17:15 +01:00
Simon Pilgrim
6ad39bc866 [X86] avxifma-builtins.c / avx512ifma-builtins.c / avx512ifmavl-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-15 12:09:54 +01:00
Simon Pilgrim
b014d10ed7 [X86] avx512cd-builtins.c + avx512vlcd-builtins.c - add C/C++ and 32/64-bit test coverage 2025-08-15 09:44:18 +01:00
Doug Gregor
ae90b60fc8
[APINotes] Add SwiftDestroyOp API note to map to the "destroy" function (#153261)
Like retain/release for reference types, "destroy" lets us specify an
operation that is used to deinitialize an instance of a noncopyable
type.
2025-08-15 08:02:14 +01:00
Ami-zhang
a1b6e7ff39
[clang][LoongArch] Ensure target("lasx") implies LSX support (#153542)
Currently, `__attribute__((target("lasx")))` does not automatically
enable LSX support, causing Clang to fail with `-mno-lsx`. Since
LASX depends on LSX, enabling LASX should implicitly enable LSX to
avoid clang error.
    
Fixes #149512.

Depends on #153541
2025-08-15 09:53:08 +08:00
Ami-zhang
793a6b4fd4
[NFC] Precommit test for issue #149512 (#153541) 2025-08-15 09:15:15 +08:00
Oliver Hunt
fb14f91305
[clang][Obj-C][PAC] Make block descriptor pointer signing configurable (#153700)
Pointer auth protection of the block descriptor pointer is only
supported in some constrained environments so we do actually need it to
be configurable.

We had made it non configurable in the first PR to protect block
metadata because we believed that was an option but subsequently
realised it does need to remain configurable.

This PR revives the flags that permit this.
2025-08-14 17:20:27 -07:00
Daniel Paoliello
fc4df2c917
[win][arm64ec] XFAIL x64 intrinsic tests on Arm64EC (#153474)
Clang defines the x64 preprocessor macro (`__x86_64__`) when building
Arm64EC, however the tests for x64 built-ins and intrinsics are
currently failing since the relevant functions don't exist, resulting in
errors like:

```
Line 165: invalid conversion between vector type '__v2di' (vector of 2 'long long' values) and integer type 'int' of different size
```

(Clang doesn't know the intrinsics being called, and so treats it like
an undefined function, which makes it assume the return type is `int`)

For now, expect these tests to fail until someone decides to implement
these intrinsics.
2025-08-14 15:29:20 -07:00
Stanislav Mekhanoshin
57c1e01e48
[AMDGPU] Don't allow wgp mode on gfx1250 (#153680)
- gfx1250 only supports cu mode
2025-08-14 15:16:56 -07:00
Andy Kaylor
a1529cd85a
[CIR] Add index support for global_view (#153254)
The #cir.global_view attribute was initially added without support for
the optional index list. This change adds index list support. This is
used when the address of an array or structure member is used as an
initializer.

This patch does not include support for taking the address of a
structure or class member. That will be added later.
2025-08-14 15:14:12 -07:00
Bill Wendling
1e9fc8edd0 [Clang][attr] Add '-std=c11' to allow for typedef redefinition 2025-08-14 13:51:58 -07:00
Bill Wendling
aa4805a090
[Clang][attr] Add 'cfi_salt' attribute (#141846)
The 'cfi_salt' attribute specifies a string literal that is used as a
"salt" for Control-Flow Integrity (CFI) checks to distinguish between
functions with the same type signature. This attribute can be applied
to function declarations, function definitions, and function pointer
typedefs.

This attribute prevents function pointers from being replaced with
pointers to functions that have a compatible type, which can be a CFI
bypass vector.

The attribute affects type compatibility during compilation and CFI
hash generation during code generation.

  Attribute syntax: [[clang::cfi_salt("<salt_string>")]]
  GNU-style syntax: __attribute__((cfi_salt("<salt_string>")))

- The attribute takes a single string of non-NULL ASCII characters.
- It only applies to function types; using it on a non-function type
  will generate an error.
- All function declarations and the function definition must include
  the attribute and use identical salt values.

Example usage:

  // Header file:
  #define __cfi_salt(S) __attribute__((cfi_salt(S)))

  // Convenient typedefs to avoid nested declarator syntax.
  typedef int (*fp_unsalted_t)(void);
  typedef int (*fp_salted_t)(void) __cfi_salt("pepper");

  struct widget_ops {
    fp_unsalted_t init;     // Regular CFI.
    fp_salted_t exec;       // Salted CFI.
    fp_unsalted_t teardown; // Regular CFI.
  };

  // bar.c file:
  static int bar_init(void) { ... }
  static int bar_salted_exec(void) __cfi_salt("pepper") { ... }
  static int bar_teardown(void) { ... }

  static struct widget_generator _generator = {
    .init = bar_init,
    .exec = bar_salted_exec,
    .teardown = bar_teardown,
  };

  struct widget_generator *widget_gen = _generator;

  // 2nd .c file:
  int generate_a_widget(void) {
    int ret;

    // Called with non-salted CFI.
    ret = widget_gen.init();
    if (ret)
      return ret;

    // Called with salted CFI.
    ret = widget_gen.exec();
    if (ret)
      return ret;

    // Called with non-salted CFI.
    return widget_gen.teardown();
  }

Link: https://github.com/ClangBuiltLinux/linux/issues/1736
Link: https://github.com/KSPP/linux/issues/365

---------

Signed-off-by: Bill Wendling <morbo@google.com>
Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2025-08-14 13:07:38 -07:00
Matheus Izvekov
eeada0d30f
[clang] fix source range computation for DeducedTemplateSpecializationType (#153646)
This was a regression introduced in
https://github.com/llvm/llvm-project/pull/147835

Since this regression was never released, there are no release notes.

Fixes https://github.com/llvm/llvm-project/issues/153540
2025-08-14 16:42:34 -03:00
Iris Shi
dc0becc4d0
[CIR] Add InlineAsmOp lowering to LLVM (#153387)
- Part of #153267

Added support for lowering `InlineAsmOp` directly to LLVM IR

---------
Co-authored-by: Morris Hafner <mhafner@nvidia.com>
2025-08-14 17:48:14 +00:00
Iris Shi
9a28783f5d
[CIR] Add InlineAsmOp (#153362)
- Part of #153267

---------

Co-authored-by: Andy Kaylor <akaylor@nvidia.com>
Co-authored-by: Morris Hafner <mmha@users.noreply.github.com>
2025-08-14 17:34:38 +00:00
Andy Kaylor
45066c2937
[CIR] Add lowering for the cir.vtable.address_point operation (#153243)
This adds support for lowering the cir.vtable.address_point operation to
the LLVM dialect, as well as type converter support for the cir.vptr
type.
2025-08-14 10:07:54 -07:00
Mikołaj Piróg
768eae72cd
[Clang] Honor -flax-vector-conversions=none on some tests (#153433)
As in title. This is done as a step towards enabling the
`-flax-vector-conversions=none` globally as a default
2025-08-14 17:02:52 +02:00
Simon Pilgrim
179698a0fb [X86] ssse3-builtins.c - add -fno-signed-char test coverage 2025-08-14 14:20:35 +01: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
Vincent
d3bbdc7bde
[clang] constexpr __builtin_elementwise_abs support (#152497)
Added constant evaluation support for `__builtin_elementwise_abs` on integer, float and vector type.

fixes #152276

---------

Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-08-14 12:34:23 +01:00
mdenson
f5b36eb3a4
[clang] fix comment lexing of command names with underscore (#152943)
Comment lexer fails to parse non-alphanumeric names.

fixes #33296

---------

Co-authored-by: Brock Denson <brock.denson@virscient.com>
2025-08-14 13:03:55 +02:00
Corentin Jabot
186176de45
[Clang] Do not consider a variadic function ellipsis part of a default arg (#153496)
When stashing the tokens of a parameter of a member function, we would
munch an ellipsis, as the only considered terminal conditions were `,`
and `)`.

Fixes #153445
2025-08-14 12:51:58 +02:00
Matheus Izvekov
9255580a3a
[clang] fix skipped parsing of late parsed attributes (#153558) 2025-08-14 06:42:55 -03:00
TianYe
44e6bc6fc0
[Headers][X86] Allow AVX2/AVX512 broadcast intrinsics to be used in Constexpr (#153363)
Fix [issue](https://github.com/llvm/llvm-project/issues/152499)
This patch adds support for the following broadcast intrinsics
by wrapping them around existing generic shuffle implementations:
```
_mm_broadcastb_epi8
_mm_broadcastw_epi16
_mm_broadcastd_epi32
_mm_broadcastq_epi64
_mm_broadcastss_ps
_mm_broadcastsd_pd

_mm256_broadcastb_epi8
_mm256_broadcastw_epi16
_mm256_broadcastd_epi32
_mm256_broadcastq_epi64
_mm256_broadcastss_ps
_mm256_broadcastsd_pd

_mm256_broadcastsi128_si256

_mm512_broadcastb_epi8
_mm512_broadcastw_epi16
_mm512_broadcastd_epi32
_mm512_broadcastq_epi64
_mm512_broadcastss_ps
_mm512_broadcastsd_pd

_mm512_broadcast_f32x2 _mm256_broadcast_f32x2
_mm512_broadcast_i32x2 _mm256_broadcast_i32x2 _mm_broadcast_i32x2
_mm512_broadcast_f32x4 _mm256_broadcast_f32x4
_mm512_broadcast_i32x4 _mm256_broadcast_i32x4
_mm512_broadcast_f32x8
_mm512_broadcast_i32x8
_mm512_broadcast_f64x2 _mm256_broadcast_f64x2
_mm512_broadcast_i64x2 _mm256_broadcast_i64x2
_mm512_broadcast_f64x4
_mm512_broadcast_i64x4
```

Co-authored-by: Simon Pilgrim <llvm-dev@redking.me.uk>
2025-08-14 09:40:11 +01:00
Chuanqi Xu
ab5a5a90c0 [C++20] [Modules] Fix incorrect diagnostic for using befriend target
Close https://github.com/llvm/llvm-project/issues/138558

The compiler failed to understand the redeclaration-relationship when
performing checks when MergeFunctionDecl. This seemed to be a complex
circular problem (how can we know the redeclaration relationship before
performing merging?). But the fix seems to be easy and safe. It is fine
to only perform the check only if the using decl is a local decl.
2025-08-14 14:23:14 +08:00
Oliver Hunt
d8850ee6c0
[clang][Obj-C][PAC] Add support for authenticating block metadata (#152978)
Introduces the use of pointer authentication to protect the invocation,
copy and dispose, reference, and descriptor pointers in Objective-C
block objects.

Resolves #141176
2025-08-13 22:01:24 -07:00
Andy Kaylor
f2d76b58f8
[CIR] Use a loop for array initialization (#153499)
This updates the array initialization loop to use a do..while loop
rather than a fully serialized initialization. It also allows the
initialization of destructed objects when exception handling is not
enabled.

Array initialization when exception handling is enabled remains
unimplemented, but more precise messages are now emitted.
2025-08-13 16:14:32 -07:00
Jasmine Tang
da422daea9
Fix wrong function signature for #153102 (#153473)
- Fixes wrong function signature for #153102
2025-08-13 13:58:52 -07:00
Joseph Huber
dedc5916a5
[LinkerWrapper] Remove special handling for archives (#114843)
Summary:
Previously we extracted archives and did special symbol resolution on
them, this was mostly done because the nvlink executable couldn't handle
archives natively. Since I have added a wrapper around it that handles
that, we can now remove a lot of this complexity and just create a new
archive and pass it to the device linker.

The one issue here is that for offloading code, we often have references
to kernels that do not come from the device link job, but from the host
that wishes to call them. Under normal circumstances we would ignore
them because they are not referenced, but we need them. For now I am
just passing `--whole-archive`. In a future patch I will likely add some
logic to create a linker script that will tell the linker which symbols
we want to be extracted. That won't work for NVPTX but it's the most
canonical solution.

Also some ugliness in this patch where I need to juggle whether or not
the input is an archive and throw pairs around, I may merge that into
the `OffloadFile` struct in a later patch.
2025-08-13 14:24:47 -05:00
Martin Storsjö
ddd4974297
[clang] [test] Improve XFAIL patterns for aarch64 msvc (#153397)
Unless relevant (which it very seldom is), avoid checking specifically
for the "pc" vendor field; mingw environments often use "w64" as vendor
- but not always.

In this case, this test has been passing in mingw configurations lately;
the previous XFAIL pattern would cause the test to unexpectedly succeed
if running with a triple with a "pc" vendor field.

Instead reinstate the checking for an -msvc environment here; this
essentially reverts 8e029d9e35092d1440dafc8991e73fb8c3b323d7 (and the
related typo fix 301f3da5162499965287338a0cd52309fb28e8b8).

I'm not sure how 8e029d9e35092d1440dafc8991e73fb8c3b323d7 concluded that
this issue affected the gnu ABI (mingw) as well; I rechecked building
that commit, and at that point, this test did pass for an aarch64 mingw
target. (Due to the -pc- triple, the false positive XFAIL match hasn't
been noticed before.)
2025-08-13 21:57:00 +03:00
Jasmine Tang
be5554d610
[Headers][X86] Allow SSE/AVX/AVX512 unpck intrinsics to be used in constexpr (#153102)
Fixes https://github.com/llvm/llvm-project/issues/153028
2025-08-13 09:42:41 -07:00
Morris Hafner
0045bfca9c
[CIR} Add support for static member variable instantiation (#153200)
This patch handles both implicit and explicit template instantiations of
template class static member variables.
2025-08-13 18:03:05 +02:00
Amr Hesham
dc84f3aea8
[CIR] Upstream builtin FAbs op (#151750)
Upstreaming FAbsOp as a prerequisite for upstreaming ComplexDivOp
2025-08-13 17:57:06 +02:00
DeanSturtevant1
4cdc3388b3
Fix Clang bug that -Wformat-signedness is not reported properly. (#150962)
The goal is to correctly identify diagnostics that are emitted by virtue
of -Wformat-signedness.

Before this change, diagnostic messages triggered by -Wformat-signedness
might look like:
format specifies type 'unsigned int' but the argument has type 'int'
[-Wformat]
signedness of format specifier 'u' is incompatible with 'c' [-Wformat]
With this change:
format specifies type 'unsigned int' but the argument has type 'int',
which differs in signedness [-Wformat-signedness]
signedness of format specifier 'u' is incompatible with 'c'
[-Wformat-signedness]

Fix:
- handleFormatSignedness can now return NoMatchSignedness. Callers
handle this.
- warn_format_conversion_argument_type extends the message it used to
emit by a string that
  mentions "signedness".
- warn_format_cmp_specifier_sign_mismatch is now correctly categorized
as a
  diagnostic controlled by -Wformat-signedness.
2025-08-13 08:03:28 -07:00
Andres-Salamanca
4b112d23a5
[CIR] Upstream LabelOp (#152802)
This PR introduces the `LabelOp`, which is required for implementing
`GotoOp` lowering in the future.
Lowering to LLVM IR is **not** included in this patch, since it depends
on the upcoming `GotoSolver`.

The `GotoSolver` traverses the function body, and if it finds a
`LabelOp` without a matching `GotoOp`, it erases the label.
This means our implementation differs from the classic codegen approach,
where labels may be retained even if unused.

Example:
https://godbolt.org/z/37Mvr4MMr
2025-08-13 09:52:00 -05:00
erichkeane
9a698a67e2 [OpenACC] Implement new OpenACC device_type restriction
The OpenACC standard is going to change to clarify that init, shutdown,
    and set should only have a single architecture in each 'device_type'
    clause.  This patch implements that restriction.

    See: https://github.com/OpenACC/openacc-spec/pull/550
2025-08-13 07:47:39 -07:00
Jongmyeong Choi
385f83c774
[clang] Fix assertion failure with explicit(bool) in pre-C++11 modes (#152985)
Allow CCEKind::ExplicitBool in BuildConvertedConstantExpression for
pre-C++11 contexts, similar to the existing TempArgStrict exception.
This enables explicit(bool) to work as a C++20 extension in earlier
language modes without triggering assertion failures.

Fixes #152729

---------

Co-authored-by: Jongmyeong Choi <cheesechoi@gmail.com>
2025-08-13 07:03:09 -07:00
Simon Pilgrim
9ce3aff0c3 [X86] avx512bw-builtins.c - add C/C++ test coverage
Catches a typo in the _mm512_adds_epu8 constexpr test
2025-08-13 13:54:18 +01:00
Simon Pilgrim
5c95b83644 [X86] builtin_test_helpers.h - ensure the match_v*qi matchers work with -fno-signed-char tests
Work with explicit signed char types to avoid signed/unsigned char truncation out of bounds warnings
2025-08-13 13:54:17 +01:00