2145 Commits

Author SHA1 Message Date
Phoebe Wang
99a1d5f7fa
[X86][APX] Remove CF feature from APXF and Diamond Rapids (#153751)
Due to it results in more losses than gains.
2025-08-20 03:07:56 +00:00
Oliver Hunt
19c4e86f3e
[clang][PAC][darwin] Set correct default ptrauth features for arm64e-darwin (#153722)
This PR makes sure that when targeting arm64e on darwin platforms the
correct flags are set for the userspace platform ABI.
2025-08-19 17:31:14 -07:00
Timm Baeder
a1039c1b84
[clang][bytecode] Fix initializing float elements from #embed (#154285)
Fixes #152885
2025-08-19 11:04:21 +02:00
Oliver Hunt
624b724ca6
[clang][PAC] ptrauth_qualifier and ptrauth_intrinsic should only be available on Darwin (#153912)
For backwards compatibility reasons the `ptrauth_qualifier` and
`ptrauth_intrinsic` features need to be testable with `__has_feature()`
on Apple platforms, but for other platforms this backwards compatibility
issue does not exist.

This PR resolves these issues by making the `ptrauth_qualifier` and
`ptrauth_intrinsic` tests conditional upon a darwin target. This also
allows us to revert the ptrauth_qualifier check from an extension to a
feature test again, as is required on these platforms.

At the same time we introduce a new predefined macro `__PTRAUTH__` that
answers the same question as `__has_feature(ptrauth_qualifier)` and
`__has_feature(ptrauth_intrinsic)` as those tests are synonymous and
only exist separately for compatibility reasons.

The requirement to test for the `__PTRAUTH__` macro also resolves the
hazard presented by mixing the `ptrauth_qualifier` flag (that impacts
ABI and security policies) with `-pedantics-errors`, which makes
`__has_extension` return false for all extensions.

---------

Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2025-08-18 20:29:26 +00: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
Oleksandr T.
5544492d6a
[Clang] Fixed a crash when parsing #embed parameters with unmatched closing brackets (#152877)
Fixes #152829

--- 

This patch addresses the issue where the preprocessor could crash when
parsing `#embed` parameters containing unmatched closing brackets

```cpp
#embed "file" prefix(])
#embed "file" prefix(})
```
2025-08-11 17:08:10 +03:00
jeremyd2019
ff616b4806
[Tests] Add system-cygwin feature, and use it. (#152611)
Several Clang tests were failing on Cygwin, and were already marked as
requiring !system-windows, unsupported on system-windows, or xfail on
system-windows. Add system-cygwin to lit's llvm.config, and use it in
such tests in addition to system-windows.
2025-08-08 13:29:00 -07:00
Aiden Grossman
b7b501e54c Reapply "[clang] Remove %T from tests (#151614)"
This reverts commit 4c80193a58a5c24e2bbebe291feb406191c4e2ab.

This relands the commit. The issues have theoretically been fixed.
2025-08-02 20:08:53 +00:00
Aiden Grossman
4c80193a58 Revert "[clang] Remove %T from tests (#151614)"
This reverts commit 5a586375aa3a128dadc9473cfa196bf8588c2a82.

This breaks two buildbots with failures in
implicit-module-header-maps.cpp. No idea why these failures are
occurring.

https://lab.llvm.org/buildbot/#/builders/64/builds/5166
https://lab.llvm.org/buildbot/#/builders/13/builds/8725
2025-08-01 17:30:24 +00:00
Aiden Grossman
5a586375aa
[clang] Remove %T from tests (#151614)
This patch removes %T from clang lit tests. %T has been deprecated for
about seven years and is not reccomended as it is not unique to each
test, which can lead to races. This patch is intended to remove usage in
tree with the end goal of removing support for %T within lit.
2025-08-01 08:25:14 -07:00
Hood Chatham
8dd91996f0
[WebAssembly] Add gc target feature to addBleedingEdgeFeatures (#151294)
Also alphebetize feature list, add `-mgc` and `-mno-gc` flags, and add
some missing feature tests.

Reland of #151107.

https://github.com/llvm/llvm-project/pull/150201#discussion_r2237982637
2025-07-30 13:04:02 -07:00
ronlieb
a7e029bd0b
Revert "[WebAssembly] Add gc target feature to addBleedingEdgeFeatures" (#151268)
Reverts llvm/llvm-project#151107
2025-07-29 22:07:17 -07:00
Hood Chatham
fe25445ded
[WebAssembly] Add gc target feature to addBleedingEdgeFeatures (#151107)
See suggestion here:
https://github.com/llvm/llvm-project/pull/150201#discussion_r2237982637
2025-07-29 17:54:12 -07:00
jeremyd2019
a3228b6bf9
[Clang][Cygwin] Enable few conditions that are shared with MinGW (#149637)
The Cygwin target is generally very similar to the MinGW target. The
default auto-import behavior, the default calling convention, the
`.dll.a` import library extension, the `__GXX_TYPEINFO_EQUALITY_INLINE`
pre-define by `g++`, and the long double configuration.

Co-authored-by: Mateusz Mikuła <oss@mateuszmikula.dev>
2025-07-29 10:01:43 -07:00
jeremyd2019
28b3190053
[LLVM][Cygwin] Enable conditions that are shared with MinGW (#149638)
Cygwin and MinGW share the auto import behavior that could result in
__stack_check_guard being non-dso-local. Allow windres to assume a
Cygwin target as well as a MinGW one, so defines like _WIN32 would not
be present on Cygwin.
2025-07-29 10:01:04 -07:00
Juan Manuel Martinez Caamaño
8b020d5434
[Preprocessor] Do not expand macros if the input is already preprocessed (#137665)
Preprocessing the preprocessor output again interacts poorly with some
flag combinations when we perform a separate preprocessing stage. In our
case, `-no-integrated-cpp -dD` triggered this issue; but I guess that
other flags could also trigger problems (`-save-temps` instead of
`-no-integrated-cpp`).

Full context (which is quite weird I'll admit):

* To cache OpenCL kernel compilation results, we use the
`-no-integrated-cpp` for the driver to generate a separate preprocessing
command (`clang -E`) before the rest of the compilation.
* Some OpenCL C language features are implemented as macro definitions
(in `opencl-c-base.h`). The semantic analysis queries the preprocessor
to check if these are defined or not, for example, when we checks if a
builtin is available when using `-fdeclare-opencl-builtins`.
* To preserve these `#define` directives, on the preprocessor's output,
we use `-dD`. However, other `#define` directives are also maintained
besides OpenCL ones; which triggers the issue shown in this PR.

A better fix for our particular case could have been to move the
language features implemented as macros into some sort of a flag to be
used together with `-fdeclare-opencl-builtins`.
But I also thought that not preprocessing preprocessor outputs seemed
like something desirable. I hope to work on this on a follow up.
2025-07-29 08:49:36 +02:00
Nick Sarnie
0efcb83626
[Clang] Reland '__has_builtin should return false for aux triple builtins' (#126324)
Reland https://github.com/llvm/llvm-project/pull/121839 based on the
results of the Discourse discussion
[here](https://discourse.llvm.org/t/rfc-has-builtin-behavior-on-offloading-targets/84964).

---------

Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-07-28 17:54:52 +00:00
Jim Lin
2e71bf0133 [RISCV] Split the pre-defined macro tests for xthead* extensions to riscv-target-features-thead.c. NFC. 2025-07-28 13:08:07 +08:00
Jim Lin
ee3cf1252a [RISCV] Add pre-defined macro test for XCVmem. NFC. 2025-07-28 13:08:07 +08:00
Jim Lin
8c8b3cd28b [RISCV] Split the pre-defined macro tests for xcv* extensions to riscv-target-features-cv.c. NFC. 2025-07-28 13:08:07 +08:00
Jim Lin
024262421d [RISCV] Split the pre-defined macro tests for SiFive extensions to riscv-target-features-sifive.c. NFC. 2025-07-28 13:08:07 +08:00
Jim Lin
45104662c0
[RISCV] Add negative pre-defined macro test for XSfmm* extension. NFC. (#150596) 2025-07-28 09:31:37 +08:00
yronglin
44a6e0099b
[clang] Check empty macro name in #pragma push_macro("") or #pragma pop_macro("") (#149982)
Fixes https://github.com/llvm/llvm-project/issues/149762.

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
2025-07-22 22:57:34 +08:00
Simon Tatham
34f59d7920
[Clang][ARM] Fix __ARM_FEATURE_LDREX on Armv8-M (#149538)
The Armv8-M architecture doesn't have the LDREXD and STREXD
instructions, for exclusive load/store of a 64-bit quantity split across
two registers. But the `__ARM_FEATURE_LDREX` macro was set to a value
that claims it does, because the case for Armv8 was missing a check for
M profile.

The Armv7 case got it right, so I've just made the two cases the same.
2025-07-22 08:53:45 +01:00
Hervé Poussineau
13906724ff
[Mips] Correctly define IntPtrType (#145158)
Mips was the only architecture having PtrDiffType = SignedInt and
IntPtrType = SignedLong

This fixes a problem on mipsel-windows-gnu triple, where uintptr_t was
wrongly defined as unsigned long instead of unsigned int, leading to
problems in compiler-rt.

compiler-rt/lib/interception/interception_type_test.cpp:24:17: error:
static assertion failed due to requirement
'__sanitizer::is_same<unsigned long, unsigned int>::value':
24 | COMPILER_CHECK((__sanitizer::is_same<__sanitizer::uptr,
::uintptr_t>::value));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

compiler-rt/lib/interception/../sanitizer_common/sanitizer_internal_defs.h:369:44:
note: expanded from macro 'COMPILER_CHECK'
      369 | #define COMPILER_CHECK(pred) static_assert(pred, "")
          |                                            ^~~~
compiler-rt/lib/interception/interception_type_test.cpp:25:17: error:
static assertion failed due to requirement '__sanitizer::is_same<long,
int>::value':
25 | COMPILER_CHECK((__sanitizer::is_same<__sanitizer::sptr,
::intptr_t>::value));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

compiler-rt/lib/interception/../sanitizer_common/sanitizer_internal_defs.h:369:44:
note: expanded from macro 'COMPILER_CHECK'
      369 | #define COMPILER_CHECK(pred) static_assert(pred, "")
          |                                            ^~~~
compiler-rt/lib/interception/interception_type_test.cpp:27:17: error:
static assertion failed due to requirement '__sanitizer::is_same<long,
int>::value':
27 | COMPILER_CHECK((__sanitizer::is_same<::PTRDIFF_T,
::ptrdiff_t>::value));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

compiler-rt/lib/interception/../sanitizer_common/sanitizer_internal_defs.h:369:44:
note: expanded from macro 'COMPILER_CHECK'
      369 | #define COMPILER_CHECK(pred) static_assert(pred, "")
2025-07-21 18:17:45 +02:00
erichkeane
011d38bdac [OpenACC] Update OpenACC macro, remove override macro
As we are now Sema-complete for OpenACC 3.4 (and thus have a conforming
implementation, in all modes), we can now set the _OPENACC macro
correctly.

Additionally, we remove the temporary 'override' functionality, which
was intended to allow people to experiment with this. We aren't having a
deprecation period as OpenACC support is still considered experimental.
2025-07-17 09:12:36 -07:00
Brad Smith
0d2e11f3e8
Remove Native Client support (#133661)
Remove the Native Client support now that it has finally reached end of life.
2025-07-15 13:22:33 -04:00
Jim Lin
22707fd4a5
[RISCV] Add Andes XAndesBFHCvt (Andes Scalar BFLOAT16) extension (#148563)
The spec can be found at:

https://github.com/andestech/andes-v5-isa/releases/tag/ast-v5_4_0-release.

The extension includes only two instructions: one for converting from
f32 to f16, and another for converting from f16 to f32.

This patch only implements MC support for XAndesBFHCvt.
2025-07-15 08:59:00 +08:00
Phoebe Wang
d11fd66959
[X86] Remove WIDEKL feature from Pantherlake and Clearwaterforest (#148184)
According to Intel
[SDM088](https://cdrdv2.intel.com/v1/dl/getContent/671200) Volume 1,
Chapter 2.4, Key Locker will be removed from 2025 onwards products.
2025-07-11 21:27:42 +08:00
Mariya Podchishchaeva
28375572f6
[win][clang] Do not inject static_assert macro definition (#147030)
In ms-compatibility mode we inject static_assert macro definition if
assert macro is defined. This is done by
8da090381d567d0ec555840f6b2a651d2997e4b3
for the sake of better diagnosing, in particular to emit a compatibility
warning when static_assert keyword is used without inclusion of
<assert.h>. Unfortunately it doesn't do a good job in c99 mode adding
that macro unexpectedly for the users, so this patch removes macro
injection and the diagnostics.

---------

Co-authored-by: Corentin Jabot <corentinjabot@gmail.com>
2025-07-08 09:34:13 +02:00
Jim Lin
3f33e7ba5b
[RISCV] Add Andes XAndesVSIntLoad (Andes Vector INT4 Load) extension (#147005)
The spec can be found at:
https://github.com/andestech/andes-v5-isa/releases/tag/ast-v5_4_0-release.

This patch only implements MC support for XAndesVSIntLoad.

---------

Co-authored-by: Lino Hsing-Yu Peng <linopeng@andestech.com>
2025-07-07 13:01:22 +08:00
Tomer Shafir
65e11f600d
[Clang][AArch64] Remove redundant tune args to the backend (#146896)
This change removes unnecessary tune args to the AArch64 backend. The
AArch64 backend automatically handles `tune-cpu` and adds the necessar
y features based on the models from TableGen.

It follows this fix: https://github.com/llvm/llvm-project/pull/146260
where updating a subtarget feature didn't fail the frontend test because
both the toolchain and the test suffered from a coordinated error.
2025-07-05 09:36:13 +03:00
Jim Lin
44bed1af0f [RISCV] Add negative pre-defined macro test for XAndesVBFHCvt 2025-07-03 09:06:01 +08:00
Sander de Smalen
cd10ded697
[Clang] Remove AArch64TargetInfo::setArchFeatures (#146107)
When compiling with `-march=armv9-a+nosve` we found that Clang still
defines the `__ARM_FEATURE_SVE2` macro, which is explicitly set in
`setArchFeatures` when compiling for armv9-a.

After some experimenting, I found out that the list of features passed
into `AArch64TargetInfo::handleTargetFeatures` has already been expanded
and takes into account `+no[feature]` and has already expanded features
like `armv9-a`.

From that I conclude that `setArchFeatures` is no longer required.
2025-07-01 10:20:40 +01:00
Tomer Shafir
dd02fb3a51
[AArch64] Fix stale +zcm target feature to +zcm-gpr64 (#146260)
Replaces all the uses of `+zcm` with `+zcm-gpr64`. A fix for:
https://github.com/llvm/llvm-project/pull/146051
2025-06-29 15:01:05 +03:00
yronglin
8b0d112478
[Clang][Preprocessor] Expand UCNs in macro concatenation (#145351)
Fixs https://github.com/llvm/llvm-project/issues/145240.

The UCN in preprocessor pasted identifier not resolved to unicode, it
may cause the following issue:
```c
#define CAT(a,b) a##b

char foo\u00b5;
char*p = &CAT(foo, \u00b5); // error: use of undeclared identifier 'foo\u00b5'
```
The real identifier after paste is `fooµ`. This PR fix this issue in
`TokenLexer::pasteTokens`, if there has any UCN in pasting tokens, the
final pasted token should have a Token::HasUCN flag. Then
`Preprocessor::LookUpIdentifierInfo` will expand UCNs in this token.

Signed-off-by: yronglin <yronglin777@gmail.com>
2025-06-25 00:56:01 +08:00
no92
0f302f38b0
[clang] Add managarm support (#144791)
This is a repost of the quickly reverted #139271. The failing buildbot
tests have been fixed and pass on my machine now.
2025-06-20 02:40:20 -04:00
Phoebe Wang
5cbed34404
[X86] Remove CLDEMOTE from Arrowlake and later hybrid processors (#144833)
Decouple Arrowlake from Sierraforest because the later has CLDEMOTE
feature.
2025-06-20 08:57:37 +08:00
Phoebe Wang
5875fafdc5
[X86] Remove CLDEMOTE from Alderlake and later hybrid processors (#144662)
SDM doesn't list any hybrid processors in this feature. Besides,
physical machine also reports not supported.
2025-06-19 10:30:47 +08:00
Jim Lin
8ddada41df
[RISCV] Add Andes XAndesVBFHCvt (Andes Vector BFLOAT16 Conversion) extension (#144320)
The spec can be found at:
https://github.com/andestech/andes-v5-isa/releases/tag/ast-v5_4_0-release.

This patch only supports assembler. The instructions are similar to
`Zvfbfmin` and the only difference with `Zvfbfmin` is that
`XAndesVBFHCvt` doesn't have mask variant.
2025-06-18 09:17:46 +08:00
Aaron Ballman
3377b56338
Revert "[clang] Add managarm support" (#144514)
Reverts llvm/llvm-project#139271

There are multiple failing build bots:
https://lab.llvm.org/buildbot/#/builders/10/builds/7482
https://lab.llvm.org/buildbot/#/builders/11/builds/17473
2025-06-17 08:39:15 -04:00
no92
e86740e600
[clang] Add managarm support (#139271)
This PR is part of a series to upstream managarm support, as laid out in
the
[RFC](https://discourse.llvm.org/t/rfc-new-proposed-managarm-support-for-llvm-and-clang-87845/85884/1).
This PR is a follow-up to #87845 and #138854.
2025-06-17 01:51:46 -04:00
Martin Wehking
fbea0fc5c7
Add Macro for CSSC Feature (#143148)
Add a new __ARM_FEATURE_CSSC macro that can be utilized during the
preprocessing stage.

__ARM_FEATURE_CSSC is defined to 1 if there is hardware support for
CSSC.

Implements the ACLE change:
https://github.com/ARM-software/acle/pull/394
2025-06-13 13:33:46 +01:00
Ami-zhang
2ecbfc0beb
[LoongArch] Fix '-mno-lsx' option not disabling LASX feature (#143821)
When '-march' with LASX feature and '-mno-lsx' options are used
together, '-mno-lsx' fails to disable LASX, leaving
'HasFeatureLASX=true' and causing incorrect '__loongarch_sx/asx=1' macro
definition.

Fixes https://github.com/loongson-community/discussions/issues/95
2025-06-12 20:11:14 +08:00
macurtis-amd
2ddf0caaed
[clang][driver] Suppress gnu-line-marker when saving temps (#134621)
When passing `-save-temps` to clang, the generated preprocessed output
uses gnu line markers. This unexpectedly triggers gnu-line-marker
warnings when used with `-Weverything` or `-pedantic`. Even worse,
compilation fails if `-Werror` is used.

This change suppresses gnu-line-marker warnings when invoking clang with
input from a preprocessor job and the user has not otherwise explictly
specified `-Wgnu-line-marker` somewhere on the command line. Note that
this does apply to user provided preprocessed files.

fixes #63802
2025-06-10 11:54:50 -05:00
Tomohiro Kashiwada
e7739eb6cc
[Clang] [Cygwin] wint_t is unsigned int (#143117)
On Cygwin environment, wint_t is unsigned int as shown here:
```
$ echo | gcc -m32 -xc - -E -dM | grep WINT_T
145:#define __SIZEOF_WINT_T__ 4
315:#define __WINT_TYPE__ unsigned int
```

```
$ echo | gcc -xc - -E -dM | grep WINT_T
147:#define __SIZEOF_WINT_T__ 4
317:#define __WINT_TYPE__ unsigned int
```

```
$ LANG=C gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/15/lto-wrapper.exe
Target: x86_64-pc-cygwin
(snip)
```
2025-06-09 22:19:06 +03:00
Jim Lin
94011efe30
[RISCV] Add pre-defined macro tests for Andes vendor extension. NFC. (#141172) 2025-06-03 11:32:28 +08:00
Nathan Gauër
df5f65d22a
[SPIR-V] Only emit __spirv__ when targeting HLSL (#142401)
OpenCL translator has a `__spirv` namespace, and defining the
`__spirv__` macro causes issues downstream on the OpenCL side. This
macro is needed to keep compatibility with HLSL/DXC, but can be avoided
for other targets/languages.
2025-06-02 11:51:53 -04:00
Ying Chen
5483190216
[RISCV] Add shlcofideleg extension (#141572)
This is for `shlcofideleg` extension, that supports delegating LCOFI
interrupts to VS-mode.

Spec:
https://github.com/riscv/riscv-isa-manual/blob/main/src/hypervisor.adoc
2025-05-30 16:52:08 +08:00
CarolineConcatto
7569de5272
[Clang][AArch64]Add FP8 ACLE macros implementation (#140591)
This patch implements the macros described in the ACLE[1]

[1]
https://github.com/ARM-software/acle/blob/main/main/acle.md#modal-8-bit-floating-point-extensions
2025-05-27 10:01:38 +01:00