5407 Commits

Author SHA1 Message Date
Ami-zhang
b359422eeb
[Clang][LoongArch] Support target attribute for function (#140700)
This adds support under LoongArch for the target("..") attributes.

The supported formats are:
- "arch=<arch>" strings, that specify the architecture features for a
function as per the -march=arch option.
- "tune=<cpu>" strings, that specify the tune-cpu cpu for a function as
per -mtune.
- "<feature>", "no-<feature>" enabled/disables the specific feature.
2025-05-29 19:54:48 +08:00
Qinkun Bao
45b874bc57
[UBSan] Support src:*=sanitize for multiple ignorelists. (#141640)
See: https://github.com/llvm/llvm-project/issues/139128 and
https://github.com/llvm/llvm-project/pull/140529 for the background.

The introduction of these new tests (ubsan-src-ignorelist-category.test)
`-fsanitize-ignorelist=%t/src.ignorelist
-fsanitize-ignorelist=%t/src.ignorelist.contradict9` in this PR will not
lead to failures in the previous implementation (without this PR). This
is because the existing logic distinguishes between Sections in
different ignorelists, even if their names are identical. The order of
these Sections is preserved using a `vector`.
2025-05-28 11:12:53 -04:00
Steven Perron
5584020d8a
[HLSL][SPIRV] Implement the SPIR-V target type for cbuffers. (#140061)
This change implement the type used to represent cbuffer for SPIR-V.

Fixes https://github.com/llvm/llvm-project/issues/138274.
2025-05-28 07:51:03 -04:00
Qinkun Bao
4f1291e484
[UBSan] Implement src:*=sanitize for UBSan (#140529)
Background: https://github.com/llvm/llvm-project/issues/139128

It is a draft implementation for "src:*=sanitize". It should be applied
to all sanitizers.

Any srcs assigned to the sanitize category will have their sanitizer
instrumentation remained ignored by "src:". For example,

```
src:*
src:*/test1.cc=sanitize
```

`test1.cc` will still have the UBSan instrumented.

Conflicting entries are resolved by the latest entry, which takes
precedence.

```
src:*
src:*/mylib/*=sanitize
src:*/mylib/test.cc
```
`test.cc` does not have the UBSan check (In this case,
`src:*/mylib/test.cc` overrides `src:*/mylib/*=sanitize` for `test.cc`).

```
src:*
src:*/mylib/test.cc
src:*/mylib/*=sanitize
```

`test1.cc` has the UBSan instrumented (In this case,
`src:*/mylib/*=sanitize` overrides `src:*/mylib/test.cc`).

Documents update will be in a new PR.
2025-05-27 19:19:25 -07: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
Qinkun Bao
e9dbf31be5
[NFCI][Sanitizer] Convert Matcher::Globs from StringMap to vector. (#140964)
As discussed in https://github.com/llvm/llvm-project/pull/139772 and
https://github.com/llvm/llvm-project/pull/140529, Matcher::Globs can
keep the order when parsing the case list.
2025-05-23 20:23:13 -04:00
hev
689342de25
[Clang][LoongArch] Add inline asm support for the q constraint (#141037)
This patch adds support for the `q` constraint:
a general-purpose register except for $r0 and $r1 (for the csrxchg
instruction)

Link: https://gcc.gnu.org/pipermail/gcc-patches/2025-May/684339.html
2025-05-23 11:14:41 +08:00
Jan Svoboda
13e1a2cb22 Reapply "[clang] Remove intrusive reference count from DiagnosticOptions (#139584)"
This reverts commit e2a885537f11f8d9ced1c80c2c90069ab5adeb1d. Build failures were fixed right away and reverting the original commit without the fixes breaks the build again.
2025-05-22 12:52:03 -07:00
Kazu Hirata
e2a885537f Revert "[clang] Remove intrusive reference count from DiagnosticOptions (#139584)"
This reverts commit 9e306ad4600c4d3392c194a8be88919ee758425c.

Multiple builtbot failures have been reported:
https://github.com/llvm/llvm-project/pull/139584
2025-05-22 12:44:20 -07:00
Jan Svoboda
9e306ad460
[clang] Remove intrusive reference count from DiagnosticOptions (#139584)
The `DiagnosticOptions` class is currently intrusively
reference-counted, which makes reasoning about its lifetime very
difficult in some cases. For example, `CompilerInvocation` owns the
`DiagnosticOptions` instance (wrapped in `llvm::IntrusiveRefCntPtr`) and
only exposes an accessor returning `DiagnosticOptions &`. One would
think this gives `CompilerInvocation` exclusive ownership of the object,
but that's not the case:

```c++
void shareOwnership(CompilerInvocation &CI) {
  llvm::IntrusiveRefCntPtr<DiagnosticOptions> CoOwner = &CI.getDiagnosticOptions();
  // ...
}
```

This is a perfectly valid pattern that is being actually used in the
codebase.

I would like to ensure the ownership of `DiagnosticOptions` by
`CompilerInvocation` is guaranteed to be exclusive. This can be
leveraged for a copy-on-write optimization later on. This PR changes
usages of `DiagnosticOptions` across `clang`, `clang-tools-extra` and
`lldb` to not be intrusively reference-counted.
2025-05-22 12:33:52 -07:00
Oleksandr T.
00f40e3c1a
[Clang] Add missing macro undefs in AttributeSpellingList emitter (#141090)
Fixes
https://github.com/llvm/llvm-project/pull/140629#issuecomment-2901568992

---

This patch adds `#undef ATTR_NAME` and `#undef ATTR_SCOPE_NAME` to the
end of the generated `AttributeSpellingList.inc` file to prevent macro
redefinition warnings
2025-05-22 11:24:12 -07:00
Oleksandr T.
50127ac054
[Clang] add typo correction for unknown attribute names (#140629)
This patch enhances Clang's diagnosis for unknown attributes by
providing typo correction suggestions for known attributes.

```cpp
[[gmu::deprected]] // expected-warning {{unknown attribute 'gmu::deprected' ignored; did you mean 'gnu::deprecated'?}}
int f1(void) {
  return 0;
}

[[deprected]] // expected-warning {{unknown attribute 'deprected' ignored; did you mean 'deprecated'?}}
int f2(void) {
  return 0;
}
```
2025-05-22 17:03:32 +03:00
Fraser Cormack
6553dc30b8
[NVPTX] Support the OpenCL generic addrspace feature by default (#137940)
As best as I can see, all NVPTX architectures support the generic
address space.

I note there's a FIXME in the target's address space map about 'generic'
still having to be added to the target but we haven't observed any
issues with it downstream. The generic address space is mapped to the
same target address space as default/private (0), but this isn't
necessarily a problem for users.
2025-05-21 09:55:11 +01:00
Jim Lin
d561d595c4
[RISCV] Implement intrinsics for XAndesVPackFPH (#140007)
This patch implements clang intrinsic support for XAndesVPackFPH.

The document for the intrinsics can be found at:

https://github.com/andestech/andes-vector-intrinsic-doc/blob/ast-v5_4_0-release-v5/auto-generated/andes-v5/intrinsic_funcs.adoc#andes-vector-packed-fp16-extensionxandesvpackfph
and with policy variants

https://github.com/andestech/andes-vector-intrinsic-doc/blob/ast-v5_4_0-release-v5/auto-generated/andes-v5/policy_funcs/intrinsic_funcs.adoc#andes-vector-packed-fp16-extensionxandesvpackfph

Co-authored-by: Tony Chuan-Yue Yuan <yuan593@andestech.com>
2025-05-20 13:16:51 +08:00
Alexander Richardson
07e2ba445d
[AMDGPU] Set AS8 address width to 48 bits
Of the 128-bits of buffer descriptor only 48 bits are address bits, so
following the discussion on https://discourse.llvm.org/t/clarifiying-the-semantics-of-ptrtoint/83987/54,
the logic conclusion is to set the index width to 48 bits instead of
the current value of 128.

Most of the test changes are mechanical datalayout updates, but there
is one actual change: the ptrmask test now uses .i48 instead of .i128
and I had to update SelectionDAGBuilder to correctly extend the mask.

Reviewed By: krzysz00

Pull Request: https://github.com/llvm/llvm-project/pull/139419
2025-05-19 17:26:05 -07:00
Kazu Hirata
325281631a
[clang] Use *Map::try_emplace (NFC) (#140477)
We can simplify the code with *Map::try_emplace where we need
default-constructed values while avoding calling constructors when
keys are already present.
2025-05-19 06:19:53 -07:00
Ming-Yi Lai
c28d6c2f5f
[Clang][RISCV] Add Zicfilp CFI unlabeled scheme preprocessor macros (#109600)
This patch adds preprocessor macros when Zicfilp CFI is enabled. To be
specific:

+ `#define __riscv_landing_pad 1` when `-fcf-protection=[full|branch]`
+ `#define __riscv_landing_pad_unlabeled 1` when
`-fcf-protection=[full|branch] -mcf-branch-label-scheme=unlabeled`

The macros are proposed in riscv-non-isa/riscv-c-api-doc#76 , and the
CLI flags are from riscv-non-isa/riscv-toolchain-conventions#54.
2025-05-19 18:39:31 +08:00
Qinkun Bao
c6ad464347
[NFC] Run code formatter on Diagnostic.h/cpp ProfileList.cpp SpecialCaseList.cpp
Reviewers: vitalybuka

Reviewed By: vitalybuka

Pull Request: https://github.com/llvm/llvm-project/pull/140316
2025-05-17 17:11:49 -04:00
Kazu Hirata
dd4b69f9a8
[Basic] Use llvm::erase_if (NFC) (#140309) 2025-05-16 15:07:54 -07:00
Qinkun Bao
dd4a73069c
[NFCI][Sanitizer] Convert SpecialCaseList::Sections from StringMap to vector.
As discussed in https://github.com/llvm/llvm-project/pull/139772, SpecialCaseList::Sections can keep the order of Sections when parsing the case list.

Reviewers: thurstond, vitalybuka

Reviewed By: vitalybuka

Pull Request: https://github.com/llvm/llvm-project/pull/140127
2025-05-16 15:32:54 -04:00
Kazu Hirata
9adcb4fe12
[clang] Use llvm::replace (NFC) (#140264) 2025-05-16 09:06:31 -07:00
Matthew Devereau
22576e2cce
[Clang][AArch64] Add pessimistic vscale_range for sve/sme (#137624)
The "target-features" function attribute is not currently considered
when adding vscale_range to a function. When +sve/+sme are pushed onto
functions with "#pragma attribute push(+sve/+sme)", the function
potentially misses out on optimizations that rely on vscale_range being
present.
2025-05-16 09:39:07 +01:00
Oliver Hunt
76ba29bfd8
[NFC] Address bit-field storage sizes to ensure ideal packing (#139825)
The MS bit-field packing ABI depends on the storage size of the type of
being placed in the bit-field. This PR addresses a number of cases in
llvm where the storage type has lead to suboptimal packing.
2025-05-16 00:02:58 -07:00
Kazu Hirata
0f0fd6213e
[Basic] Use std::optional::value_or (NFC) (#140172) 2025-05-15 23:28:57 -07:00
Sean Fertile
4ac8e90df7
[PPC] Disable rop-protect for 32-bit OS targets. (#139619)
The instructions are not supported on either 32-bit ELF (due to no
redzone) or 32-bit AIX due to the instructions always using the full
64-bit width of the register inputs.
2025-05-14 13:00:15 -04:00
Krzysztof Parzyszek
6094080d27
[clang][OpenMP] Pass OpenMP version to getOpenMPDirectiveName (#139115)
The OpenMP version is stored in language options in ASTContext. If the
context is not available, use the fallback version.

RFC:
https://discourse.llvm.org/t/rfc-alternative-spellings-of-openmp-directives/85507
2025-05-09 07:41:54 -05:00
Oleksandr T.
61b435ec4d
[Clang] show attribute namespace in diagnostics (#138519)
This patch enhances Clang's diagnosis of an unknown attribute by
printing the attribute's namespace in the diagnostic text. e.g.,

```cpp
[[foo::nodiscard]] int f(); // warning: unknown attribute 'foo::nodiscard' ignored
```
2025-05-09 00:49:01 +03:00
Lei Wang
b836f96b8f
[Coverage] Support -fprofile-list for cold function coverage (#136333)
Add a new instrumentation section type `[sample-coldcov]` to
support`-fprofile-list` for sample pgo based cold function coverage.
Note that the current cold function coverage is based on sampling PGO
pipeline, which is incompatible with the existing [llvm] option(see
[PGOOptions](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Support/PGOOptions.h#L27-L43)),
so we can't reuse the IR-PGO(-fprofile-instrument=llvm) flag.
2025-05-08 10:51:38 -07:00
Prabhu Rajasekaran
20d6375796
[clang] Handle CC attrs for UEFI (#138935)
UEFI's default ABI is MS ABI. Handle the calling convention attributes
accordingly.
2025-05-07 21:42:01 -07:00
Tomohiro Kashiwada
eb6d51a2fd
[Cygwin] Enable TLS on Cygwin target (#138618)
Cygwin environment and toolchain supports EMUTLS.

From
https://cygwin.com/git/?p=newlib-cygwin.git;a=blob;f=config/tls.m4;hb=HEAD#l118,

```
$ 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
Configured with: (snip)
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.0.1 20250406 (experimental) (GCC)

$ echo '__thread int a; int b; int main() { return a = b; }' | gcc -S -xc -o- - | grep __emutls_get_address
        call    __emutls_get_address
        .def    __emutls_get_address;   .scl    2;      .type   32;     .endef
```
2025-05-06 23:38:18 +03:00
Oliver Hunt
f4c3254956
[clang][NFC] rename FPOptions.def's macro to FP_OPTION (#138374)
While investigating the recent warnings around FEM_Indeterminate I
noticed that the macro name for FPOptions.def was given the very generic
name `OPTION`.

This PR renames it to FP_OPTION instead.
2025-05-06 13:29:19 -07:00
Aaron Ballman
0b2ab11321 Simplify implementation; NFC
Suggestion came via post-commit review feedback
2025-05-02 09:39:20 -04:00
Aaron Ballman
85c810060e
[C] Diagnose use of C++ keywords in C (#137234)
This adds a new diagnostic group, -Wc++-keyword, which is off by default
and grouped under -Wc++-compat. The diagnostic catches use of C++
keywords in C code.

This change additionally fixes an issue with -Wreserved-identifier not
diagnosing use of reserved identifiers in function parameter lists in a
function declaration which is not a definition.

Fixes https://github.com/llvm/llvm-project/issues/21898
2025-05-02 07:20:02 -04:00
Justin Cai
faf4e8af74
[Clang][SYCL] Add initial set of Intel OffloadArch values (#138158)
Following #137070, this PR adds an initial set of Intel `OffloadArch`
values with corresponding predicates that will be used in SYCL
offloading. More Intel architectures will be added in a future PR.
2025-05-01 16:29:48 -05:00
Michael Spencer
07deaf8464
Reland: [llvm][clang] Allocate a new stack instead of spawning a new thread to get more stack space (#136046)
Reland https://github.com/llvm/llvm-project/pull/133173

Clang spawns a new thread to avoid running out of stack space. This can
make debugging and performance analysis more difficult as how the
threads are connected is difficult to recover.

This patch introduces `runOnNewStack` and applies it in Clang. On
platforms that have good support for it this allocates a new stack and
moves to it using assembly. Doing split stacks like this actually runs
on most platforms, but many debuggers and unwinders reject the large or
backwards stack offsets that occur. Apple platforms and tools are known
to support this, so this only enables it there for now.
2025-04-30 19:14:15 -07:00
Prabhu Rajasekaran
6274cdb9a6
[clang] Fix UEFI Target info (#127290)
For X64 UEFI targets set appropriate integer type sizes, and relevant
ABI information. 

---------

Co-authored-by: Petr Hosek <phosek@google.com>
2025-04-30 10:07:57 -07:00
Shoaib Meenai
705ceff7c1
[TargetParser] Fix flaky installs of generated headers (#137853)
The `llvm-headers` target wasn't depending on the generated TargetParser
headers, so they'd be flakily installed or not installed depending on
which order the build steps ran in. Add an explicit dependency to fix
this, and switch to a single `target_parser_gen` target to mirror the
pattern used by `intrinsics_gen` (which also fixes a few other missing
dependencies). Switch `llvm-headers` to use `add_dependencies` instead
of `DEPENDS` for the tablegen dependencies as well, since `DEPENDS` is
only intended for creating a file-level dependency on the output of an
`add_custom_command` in the same CMakeLists.txt (see `DEPENDS` under
https://cmake.org/cmake/help/latest/command/add_custom_target.html).
2025-04-29 12:13:38 -07:00
Fraser Cormack
1e31f4b5eb
[AMDGPU] Support the OpenCL generic addrspace feature by default (#137636)
This feature should be supported on AMDGCN architectures with flat
addressing.
2025-04-29 14:14:00 +01:00
Nick Sarnie
f9ee5ce605
[clang][SPIR-V] Fix OpenCL addrspace mapping when using non-zero default AS (#137187)
Based on feedback from https://github.com/llvm/llvm-project/pull/136753,
remove the dummy values for OpenCL and make them match the zero default
AS map.

Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-04-28 19:26:01 +00:00
Jan Svoboda
985410f87f
[clang] Hide the TargetOptions pointer from CompilerInvocation (#106271)
This PR hides the reference-counted pointer that holds `TargetOptions`
from the public API of `CompilerInvocation`. This gives
`CompilerInvocation` an exclusive control over the lifetime of this
member, which will eventually be leveraged to implement a copy-on-write
behavior.

There are two clients that currently share ownership of that pointer:

* `TargetInfo` - This was refactored to hold a non-owning reference to
`TargetOptions`. The options object is typically owned by the
`CompilerInvocation` or by the new `CompilerInstance::AuxTargetOpts` for
the auxiliary target. This needed a bit of care in `ASTUnit::Parse()` to
keep the `CompilerInvocation` alive.
* `clangd::PreambleData` - This was refactored to exclusively own the
`TargetOptions` that get moved out of the `CompilerInvocation`.
2025-04-28 07:43:26 -07:00
Rainer Orth
e71c8ea3cc
[Driver] Fix _XOPEN_SOURCE definition on Solaris (#137141)
Since commit 613a077b05b8352a48695be295037306f5fca151, `flang` doesn't
build any longer on Solaris/amd64:
```
flang/lib/Evaluate/intrinsics-library.cpp:225:26:
error: address of overloaded function 'acos' does not match required type '__float128 (__float128)'
  225 |       FolderFactory<F, F{std::acos}>::Create("acos"),
      |                          ^~~~~~~~~
```
That patch led to the version of `quadmath.h` deep inside `/usr/gcc/<N>`
to be found, thus `HAS_QUADMATHLIB` is defined. However, the `struct
HostRuntimeLibrary<__float128, LibraryVersion::Libm>` template is
guarded by `_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600`, while
`clang` only predefines `_XOPEN_SOURCE=500`.

This code dates back to commit 0c1941cb055fcf008e17faa6605969673211bea3
back in 2012. Currently, this is long obsolete and `gcc` prefefines
`_XOPEN_SOURCE=600` instead since GCC 4.6 back in 2011.

This patch follows that.

Tested on `amd64-pc-solaris2.11` and `sparcv9-sun-solaris2.11`.
2025-04-26 17:06:04 +02:00
Justin Cai
ea443eeb2a
[Clang][NFC] Move OffloadArch enum to a generic location (#137070)
Currently, the OffloadArch enum is defined Cuda.h. This PR moves the
definition to a more generic location in OffloadArch.h/cpp.
2025-04-25 11:37:56 -05:00
Nick Sarnie
52a96491e1
[clang][SPIR-V] Addrspace of opencl_global should always be 1 (#136753)
This fixes a CUDA SPIR-V regression introduced in
https://github.com/llvm/llvm-project/pull/134399.

---------

Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-04-24 14:20:13 +00:00
Ben Shi
b0524f3329
[clang][AVR] Improve compatibility of inline assembly with avr-gcc (#136534)
Allow the value 64 to be round up to 0 for constraint 'I'.
2025-04-23 18:42:07 +08:00
modiking
d6a68be7af
[NVPTX] Add support for Shared Cluster Memory address space [1/2] (#135444)
Adds support for new Shared Cluster Memory Address Space
(SHARED_CLUSTER, addrspace 7). See
https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#distributed-shared-memory
for details.

1. Update address space structures and datalayout to contain the new
space
2. Add new intrinsics that use this new address space
3. Update NVPTX alias analysis

The existing intrinsics are updated in
https://github.com/llvm/llvm-project/pull/136768
2025-04-22 15:14:39 -07:00
Shafik Yaghmour
5e6747686d
[Clang] Remove use after move of lambda (#136728)
Static analysis flagged this use after move. It is undefined behavior
and I don't see any possible performance gains here to attempt to do
anything else but simply remove it.
2025-04-22 12:43:02 -07:00
Steven Perron
c073c22865
[HLSL] Use hlsl_device address space for getpointer. (#127675)
We add the hlsl_device address space to represent the device memory
space as defined in section 1.7.1.3 of the [HLSL
spec](https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf).

Fixes https://github.com/llvm/llvm-project/issues/127075
2025-04-22 13:26:32 -04:00
Kazu Hirata
94733492b7
[clang] Use llvm::SmallVector::pop_back_val (NFC) (#136451) 2025-04-19 13:35:18 -07:00
Kazu Hirata
0ed1c9862d
[clang] llvm::append_range (NFC) (#136440) 2025-04-19 10:37:25 -07:00
Ernesto Su
89f930a7de
[clang][OpenMP] Fix/enforce order-concurrent-nestable rules (#135463)
OpenMP has restrictions on directives allowed to be strictly nested
inside a
construct with the order(concurrent) clause specified.
 - OpenMP 5.0, 5.1, and 5.2 allows: 'loop', 'parallel', 'simd', and
     combined directives starting with 'parallel'.
 - OpenMP 6.0 allows: the above directives plus 'atomic' and
     all loop-transformation directives.

Furthermore, a region that corresponds to a construct with
order(concurrent)
specified may not contain calls to the OpenMP runtime API.

This PR fixes the following issues in the current implementation:

With -fopenmp-version=50: none of the nesting restrictions above were
enforced
 With -fopenmp-version=60:
1. Clang did not reject OpenMP runtime APIs encountered in the region.
2. Clang erroneously rejected combined directives starting with
parallel.

---------

Co-authored-by: Zahira Ammarguellat <zahira.ammarguellat@intel.com>
2025-04-18 13:57:50 -04:00