5408 Commits

Author SHA1 Message Date
Brad Smith
0fff460592
[Driver] DragonFly does not support C11 threads (#154886) 2025-08-22 02:02:52 -04: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
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
Aditi Medhane
948abf1bf5
[PowerPC] Add BCDCOPYSIGN and BCDSETSIGN Instruction Support (#144874)
Support the following BCD format conversion builtins for PowerPC.

- `__builtin_bcdcopysign` – Conversion that returns the decimal value of
the first parameter combined with the sign code of the second parameter.
`
- `__builtin_bcdsetsign` – Conversion that sets the sign code of the
input parameter in packed decimal format.

> Note: This built-in function is valid only when all following
conditions are met:
> -qarch is set to utilize POWER9 technology.
> The bcd.h file is included.

## Prototypes

```c
vector unsigned char __builtin_bcdcopysign(vector unsigned char, vector unsigned char);
vector unsigned char __builtin_bcdsetsign(vector unsigned char, unsigned char);
```

## Usage Details

`__builtin_bcdsetsign`: Returns the packed decimal value of the first
parameter combined with the sign code.
The sign code is set according to the following rules:
- If the packed decimal value of the first parameter is positive, the
following rules apply:
     - If the second parameter is 0, the sign code is set to 0xC.
     - If the second parameter is 1, the sign code is set to 0xF.
- If the packed decimal value of the first parameter is negative, the
sign code is set to 0xD.
> notes:
>     The second parameter can only be 0 or 1.
> You can determine whether a packed decimal value is positive or
negative as follows:
> - Packed decimal values with sign codes **0xA, 0xC, 0xE, or 0xF** are
interpreted as positive.
> - Packed decimal values with sign codes **0xB or 0xD** are interpreted
as negative.

---------

Co-authored-by: Aditi-Medhane <aditi.medhane@ibm.com>
2025-08-19 14:47:27 +05:30
Nikita Popov
246a64a12e
[Clang] Rename HasLegalHalfType -> HasFastHalfType (NFC) (#153163)
This option is confusingly named. What it actually controls is whether,
under the default of `-ffloat16-excess-precision=standard`, it is
beneficial for performance to perform calculations on float (without
intermediate rounding) or not. For `-ffloat16-excess-precision=none` the
LLVM `half` type will always be used, and all backends are expected to
legalize it correctly.
2025-08-18 09:23:48 +02: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
Nikita Popov
2bf2b6b24d
[AVR] Only specify one legal int string in data layout (#153010)
There should not be both `n8` and `n16:8`. This is a single list of
legal integers. Additionally, this should use the standard order in
increasing size `n8:16`.
2025-08-11 20:42:28 +02:00
Tom Vijlbrief
97f0ff0c80
[AVR] Fix Avr indvar detection and strength reduction (missed optimization) (#152028)
Fix https://github.com/llvm/llvm-project/issues/151080
2025-08-09 12:46:32 +08:00
Alex Voicu
ff8b4f8151
[AMDGCNSPIRV][NFC] Match AMDGPU's __builtin_va_list type (#152044)
AMDGCN flavoured SPIRV should math AMDGPU TI as much as possible, and
the va_list difference was spurious.
2025-08-05 15:30:16 +01:00
Eli Friedman
558277ae4d
[clang][ARM] Fix setting of MaxAtomicInlineWidth. (#151404)
2f497ec3a0056f15727ee6008211aeb2c4a8f455 updated the backend's rules for
when lock-free atomics are available, but we never made a corresponding
change to the frontend. Fix it to be consistent. This only affects
targets older than v7.
2025-08-01 11:03:21 -07:00
Artem Belevich
507b879b6e
[CUDA] add support for targeting sm_103/sm_121 with CUDA-12.9 (#151587) 2025-07-31 13:38:54 -07:00
James Y Knight
c7f3437507
NFC: Clean up of IntrusiveRefCntPtr construction from raw pointers. (#151545)
Handles clang::DiagnosticsEngine and clang::DiagnosticIDs.

For DiagnosticIDs, this mostly migrates from `new DiagnosticIDs` to
convenience method `DiagnosticIDs::create()`.

Part of cleanup https://github.com/llvm/llvm-project/issues/151026
2025-07-31 15:07:35 -04:00
James Y Knight
9ddbb478ce
NFC: Clean up construction of IntrusiveRefCntPtr from raw pointers for llvm::vfs::FileSystem. (#151407)
This switches to `makeIntrusiveRefCnt<FileSystem>` where creating a new
object, and to passing/returning by `IntrusiveRefCntPtr<FileSystem>`
instead of `FileSystem*` or `FileSystem&`, when dealing with existing
objects.

Part of cleanup #151026.
2025-07-31 09:57:13 -04: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
Kazu Hirata
99fda1a09c
[Basic] Remove getVirtualFile (#151086)
This patch removes getVirtualFile because it has been deprecated for
more than 10 months since:

  commit b1aea98cfa357e23f4bb52232da5f41781f23bff
  Author: Jan Svoboda <jan_svoboda@apple.com>
  Date:   Wed Sep 25 10:36:44 2024 -0700

I'm not aware of any downstream use AFAICT.
2025-07-29 08:19:18 -07:00
Changpeng Fang
30ad2e24ab
[AMDGPU] Allow readonly features to be written to IR when there is no target (#148141)
Fixes: SWDEV-541399
2025-07-29 08:18:00 -07:00
Simon Tatham
d5985905ae
[Clang][ARM][Sema] Reject bad sizes of __builtin_arm_ldrex (#150419)
Depending on the particular version of the AArch32 architecture,
load/store exclusive operations might be available for various subset of
8, 16, 32, and 64-bit quantities. Sema knew nothing about this and was
accepting all four sizes, leading to a compiler crash at isel time if
you used a size not available on the target architecture.

Now the Sema checking stage emits a more sensible diagnostic, pointing
at the location in the code.

In order to allow Sema to query the set of supported sizes, I've moved
the enum of LDREX_x sizes out of its Arm-specific header into
`TargetInfo.h`.

Also, in order to allow the diagnostic to specify the correct list of
supported sizes, I've filled it with `%select{}`. (The alternative was
to make separate error messages for each different list of sizes.)
2025-07-29 09:01:37 +01:00
Hood Chatham
15b03687ff
[WebAssembly,clang] Add __builtin_wasm_test_function_pointer_signature (#150201)
Tests if the runtime type of the function pointer matches the static
type. If this returns false, calling the function pointer will trap.
Uses `@llvm.wasm.ref.test.func` added in #147486.

Also adds a "gc" wasm feature to gate the use of the ref.test
instruction.
2025-07-25 16:52:39 -07:00
Aaron Ballman
479ae4aa8f
Revert "fix: replace report_fatal_error with Diags and exit" (#150662)
Reverts llvm/llvm-project#147959
2025-07-25 13:24:00 -04:00
woruyu
9d3dd8efe0
fix: replace report_fatal_error with Diags and exit (#147959)
report_fatal_error is not a good way to report diagnostics to the users, so this switches to using actual diagnostic reporting mechanisms instead.

Fixes #147187
2025-07-25 10:20:30 -04:00
Alexandros Lamprineas
3ab64c5b29
[NFC][Clang][FMV] Make FMV priority data type future proof. (#150079)
FMV priority is the returned value of a polymorphic function. On RISC-V
and X86 targets a 32-bit value is enough. On AArch64 we currently need
64 bits and we will soon exceed that. APInt seems to be a suitable
replacement for uint64_t, presumably with minimal compile time overhead.
It allows bit manipulation, comparison and variable bit width.
2025-07-23 10:37:29 +01:00
Prabhu Rajasekaran
471e59b858
[clang] Set correct CXXABI for UEFI (#150115)
The target triple x86_64-uefi must be assumed to have Microsft ABI by
default.

Fixes: https://github.com/llvm/llvm-project/issues/150113
2025-07-22 17:57:17 -07:00
Slava "nerfur" Voronzoff
5eecbc018b
Adding Loongarch64 to OpenBSD parts (#149737)
Adding Loongarch64 to OpenBSD parts
2025-07-22 18:18:12 -04: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
Wenju He
b41398294c
[SPIR] Set MaxAtomicInlineWidth minimum size to 32 for spir32 and 64 for spir64 (#148997)
Set MaxAtomicInlineWidth the same way as SPIR-V targets in 3cfd0c0d3697.
This PR fixes build warning in scoped atomic built-in in #146814:
`warning: large atomic operation may incur significant performance
penalty; ; the access size (2 bytes) exceeds the max lock-free size (0
bytes) [-Watomic-alignment]`
2025-07-17 09:02:10 +08:00
David Pagan
52432b02a9
[clang][NFC] Updated incorrect llvm-unreachable message in getOpenMPSimpleClauseType() (#148056) 2025-07-15 12:51:28 -07:00
Jan Svoboda
c592b61fc8
[clang][modules] Serialize CodeGenOptions (#146422)
Some `LangOptions` duplicate their `CodeGenOptions` counterparts. My
understanding is that this was done solely because some infrastructure
(like preprocessor initialization, serialization, module compatibility
checks, etc.) were only possible/convenient for `LangOptions`. This PR
implements the missing support for `CodeGenOptions`, which makes it
possible to remove some duplicate `LangOptions` fields and simplify the
logic. Motivated by https://github.com/llvm/llvm-project/pull/146342.
2025-07-15 12:45:09 -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
Sirraide
7b43c6c6a7
Revert "[Clang] [Diagnostics] Simplify filenames that contain '..'" (#148367)
Revert llvm/llvm-project#143520 for now since it’s causing issues for
people who are using symlinks and prefer to preserve the original path
(i.e. looks like we’ll have to make this configurable after all; I just
need to figure out how to pass `-no-canonical-prefixes` down through the
driver); I’m planning to refactor this a bit and reland it in a few
days.
2025-07-12 15:13:22 +02:00
Yaxun (Sam) Liu
beea2a9414
[Clang] Respect MS layout attributes during CUDA/HIP device compilation (#146620)
This patch fixes an issue where Microsoft-specific layout attributes,
such as __declspec(empty_bases), were ignored during CUDA/HIP device
compilation on a Windows host. This caused a critical memory layout
mismatch between host and device objects, breaking libraries that rely
on these attributes for ABI compatibility.

The fix introduces a centralized hasMicrosoftRecordLayout() check within
the TargetInfo class. This check is aware of the auxiliary (host) target
and is set during TargetInfo::adjust if the host uses a Microsoft ABI.

The empty_bases, layout_version, and msvc::no_unique_address attributes
now use this centralized flag, ensuring device code respects them and
maintains layout consistency with the host.

Fixes: https://github.com/llvm/llvm-project/issues/146047
2025-07-09 08:53:10 -04:00
Ivan Kosarev
a7a7e95720
[AMDGPU][Clang] Support bfloat16 arithmetic. (#147541)
Co-authored-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
2025-07-08 17:30:06 +01:00
Oleksandr T.
2e8e254d18
[Clang] include attribute scope in diagnostics (#144619)
This patch updates diagnostics to print fully qualified attribute names,
including scope when present.
2025-07-08 11:36:52 +03:00
Nikita Popov
18f7655178
[Clang][Wasm] Set __float128 alignment to 64 for emscripten (#146494)
https://reviews.llvm.org/D104808 set the alignment of long double to 64
bits. This is also the alignment specified in the LLVM data layout.
However, the alignment of __float128 was left at 128 bits.

I assume that this was just an oversight, rather than an intentional
divergence. The C ABI document currently does not make any statement
about `__float128`:
https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md
2025-07-08 10:20:43 +02:00
Sirraide
e3e7393c46
[Clang] [Diagnostics] Simplify filenames that contain '..' (#143520)
This can significantly shorten file paths to standard library headers,
e.g. on my system, `<ranges>` is currently printed as
```console
/usr/lib/gcc/x86_64-redhat-linux/15/../../../../include/c++/15/ranges
```
but with this change, we instead print
```console
/usr/include/c++/15/ranges
```

This is of course just a heuristic; there are paths that would get longer
as a result of this, so we use whichever path ends up being shorter.

@AaronBallman pointed out that this might be problematic for network
file systems since path resolution might take a while, so this is enabled 
only for paths that are part of a local filesystem—though not on Windows
since there we noticed that the check itself is slow.

The file names are cached in `SourceManager`.
2025-07-08 01:02:19 +02:00
Jan Svoboda
9f1b9560e7
[clang] Refactor CodeGenOptions to specify compatibility as X macro arg (#146910)
This is the `CodeGenOptions` counterpart to
https://github.com/llvm/llvm-project/pull/146766.
2025-07-07 09:02:56 -07:00
Jan Svoboda
fee168913c
[clang] Refactor LangOptions to specify compatibility as X macro arg (#146766)
This removes the `{BENIGN,COMPATIBLE}{,_ENUM,_VALUE}_LANGOPT` X macros
controlling `LangOptions`. These are permutations of the base `LANGOPT`,
`ENUM_LANGOPT` and `VALUE_LANGOPT` X macros that also carry the
information of their effect on AST (and therefore module compatibility).
Their functionality is now implemented by passing `Benign`, `Compatible`
or `NotCompatible` argument to the base X macros and using C++17 `if
constexpr` in the clients to achieve the same codegen.

This PR solves this FIXME:
```
// FIXME: Clients should be able to more easily select whether they want
// different levels of compatibility versus how to handle different kinds
// of option.
```

The base X macros are preserved, since they are used in `LangOptions.h`
to generate different kinds of field and function declarations for
flags, values and enums, which can't be achieved with `if constexpr`.

The new syntax also forces developers to think about compatibility when
adding new language option, hopefully reducing the number of new options
that are affecting by default even though they are benign or compatible.

Note that the `BENIGN_` macros used to forward to their `COMPATIBLE_`
counterparts. I don't think this ever kicked in, since there are no
clients of the `.def` file that define `COMPATIBLE_` without also
defining `BENIGN_`. However, this might be something downstream forks
need to take care of by doing `if constexpr (CK::Compatibility ==
CK::Benign || CK::Compatibility == CK::Compatible)` in place of `#define
COMPATIBLE_`.
2025-07-07 09:01:42 -07:00
Haojian Wu
7c2182a132 NFC, use structured binding to simplify the code in SourceManager.cpp. 2025-07-07 16:43:46 +02:00
Haojian Wu
7fea83e314 [clang] NFC, use LocalLocOffsetTable in getFIleIDLocal. 2025-07-07 09:57:41 +02:00
Haojian Wu
784bd61fc4
[clang] Speedup getFileIDLocal with a separate offset table. (#146604)
The `SLocEntry` structure is 24 bytes, and the binary search only needs
the offset. Loading an entry's offset might pull the entire SLocEntry
object into the CPU cache.

To make the binary search much more cache-efficient, we use a separate
offset table.

See
https://llvm-compile-time-tracker.com/compare.php?from=650d0151c623c123e4e9736fe50421624a329260&to=6af564c0d75aff28a2784a8554448c0679877792&stat=instructions:u.
2025-07-07 09:42:38 +02:00
Haojian Wu
e2510b189d
[clang] SourceManager: Cache offsets for LastFileIDLookup to speed up getFileID (#146782)
`getFileID` is a hot method. By caching the offset range in
`LastFileIDLookup`, we can more quickly check whether a given offset
falls within it, avoiding calling `isOffsetInFileID`.

https://llvm-compile-time-tracker.com/compare.php?from=0588e8188c647460b641b09467fe6b13a8d510d5&to=64843a500f0191b79a8109da9acd7e80d961c7a3&stat=instructions:u
2025-07-04 22:11:59 +02:00
Eli Friedman
2aa0f0a3bd
[AArch64] Add option -msve-streaming-vector-bits= . (#144611)
This is similar to -msve-vector-bits, but for streaming mode: it
constrains the legal values of "vscale", allowing optimizations based on
that constraint.

This also fixes conversions between SVE vectors and fixed-width vectors
in streaming functions with -msve-vector-bits and
-msve-streaming-vector-bits.

This rejects any use of arm_sve_vector_bits types in streaming
functions; if it becomes relevant, we could add
arm_sve_streaming_vector_bits types in the future.

This doesn't touch the __ARM_FEATURE_SVE_BITS define.
2025-07-03 13:44:38 -07:00
Akira Hatanaka
77f0f812b4
[Sema][ObjC] Treat unknown selector messages as unrecoverable errors under ARC (#146803)
Fixes a CodeGen crash observed when C++ auto variable types remained
non-deduced due to a message being sent with an unknown selector under
ARC.

By treating these instances as an unrecoverable error, we prevent the
compiler from proceeding to CodeGen with fundamentally incorrect code.

rdar://144394403
2025-07-03 10:01:08 -07:00
Abhina Sree
a9ee1797b7
Remove helper function and use target agnostic needConversion function (#146680)
This patch adds back the needed AutoConvert.h header and removes the
unneeded include guard of MVS to prevent this header from being removed
in the future
2025-07-02 10:02:46 -04:00
Haojian Wu
650d0151c6
[clang] Improve getFileIDLocal binary search. (#146510)
Avoid reading the `LocalSLocEntryTable` twice per loop iteration. NFC.

https://llvm-compile-time-tracker.com/compare.php?from=0b6ddb02efdcbdac9426e8d857499ea0580303cd&to=1aa335ccfb07ba96177b89b1933aa6b980fa14f6&stat=instructions:u
2025-07-01 21:59:09 +02: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
Nikita Popov
7e830f7671
[Clang] Partially fix m68k alignments (#144740)
As the data layout a few lines further up specifies, the int, long and
pointer alignment should be 16 instead of the default of 32.

The long long alignment is also incorrect, but that would require a
change to the data layout as well.

Comparison with GCC, which consistently uses 2 byte alignment:
https://gcc.godbolt.org/z/K3x6a7dEf At least based on some spot checks,
the changes to bit field layout also make use match GCC now.

This was found by https://github.com/llvm/llvm-project/pull/144720.
2025-07-01 09:06:41 +02:00
Ami-zhang
8d9cdb65f0
[Clang][LoongArch] Fixed incorrect _BitInt(N>64) alignment (#145297)
This patch makes determining alignment and width of BitInt to be target
ABI specific and makes it consistent with [Procedure Call Standard for
the LoongArch™ Architecture] for LoongArch target
(https://github.com/loongson/la-abi-specs/blob/release/lapcs.adoc).
2025-07-01 08:42:16 +08:00