112754 Commits

Author SHA1 Message Date
Owen Pan
f88a294673 [clang-format] Fix a bug that changes keyword or to an identifier (#128410)
Backports ffc61dc393e4 0968df9c3a55 2d585ccecc45

Fixes #105482
2025-03-04 06:59:18 -08:00
Tom Stellard
560ac756cb [CMake][Release] Statically link ZSTD on all OSes (#128554)
This will make the binaries more portable.

(cherry picked from commit 09832777d830e0fddff84bf36793ec4e453656b0)
2025-02-25 17:08:20 -08:00
Tom Stellard
a2112e20c7 [CMake][Release] Enable bolt optimization for clang on Linux (#128090)
Also stop buiding the bolt project on other platforms since bolt only
supports ELF.

(cherry picked from commit 148111fdcf0e807fe74274b18fcf65c4cff45d63)
2025-02-25 16:20:35 -08:00
Amy Kwan
5d3b9e2f92
[PowerPC] Update LLVM 20.1.0 Release Notes (#128764)
This PR adds LLVM 20.1.0 release notes that are related to the PowerPC
target.

---------

Co-authored-by: Hubert Tong <hubert.reinterpretcast@gmail.com>
2025-02-25 15:01:32 -08:00
Matt Arsenault
2cb3798958 Revert "[clang][OpenCL][CodeGen][AMDGPU] Do not use private as the default AS for when generic is available (#112442)"
This reverts commit 6e0b0038cd65ce726ce404305a06e1cf33e36cca.

This breaks the rocm-device-libs build, so it should not ship in
the release.
2025-02-25 08:41:24 -08:00
Chuanqi Xu
d6fd6e4d6a [Serialization] Update DECL_LAST
Address post commit review at
https://github.com/llvm/llvm-project/pull/119333#pullrequestreview-2637471908

(cherry picked from commit 366daddfad9aa38ebb7d40055cf65f4ecb7dd6f9)
2025-02-25 08:31:12 -08:00
Younan Zhang
d919b8d97b [Clang] Handle instantiating captures in addInstantiatedCapturesToScope() (#128478)
addInstantiatedCapturesToScope() might be called when transforming a
lambda body. In this situation, it would look into all the lambda's
parents and figure out all the instantiated captures. However, the
instantiated captures are not visible from lambda's class decl until the
lambda is rebuilt (i.e. after the lambda body transform). So this patch
corrects that by also examining the LambdaScopeInfo, serving as a
workaround for not having deferred lambda body instantiation in Clang
20, to avoid regressing some real-world use cases.

Fixes #128175

(cherry picked from commit ecc7e6ce4cd57a614985e95daf7027918cb8723e)
2025-02-25 08:30:16 -08:00
Chuanqi Xu
eb389b1259 [C++20] [Modules] handling selectAny attribute for vardecl
Close https://github.com/llvm/llvm-project/issues/127963

The root cause of the problem seems to be that we didn't realize it
simply.

(cherry picked from commit 24c06a19be7bcf28b37e5eabbe65df95a2c0265a)
2025-02-25 08:15:51 -08:00
Joseph Huber
e0c4a3397f [Clang] Fix cross-lane scan when given divergent lanes (#127703)
Summary:
The scan operation implemented here only works if there are contiguous
ones in the executation mask that can be used to propagate the result.
There are two solutions to this, one is to enter 'whole-wave-mode' and
forcibly turn them back on, or to do this serially. This implementation
does the latter because it's more portable, but checks to see if the
parallel fast-path is applicable.

Needs to be backported for correct behavior and because it fixes a
failing libc test.

(cherry picked from commit 6cc7ca084a5bbb7ccf606cab12065604453dde59)
2025-02-21 14:10:17 -08:00
Sebastian Jodłowski
b84ffb9f3b [CUDA] Add support for sm101 and sm120 target architectures (#127187)
Add support for sm101 and sm120 target architectures. It requires CUDA
12.8.

---------

Co-authored-by: Sebastian Jodlowski <sjodlowski@nuro.ai>
(cherry picked from commit 0127f169dc8e0b5b6c2a24f74cd42d9d277916f6)
2025-02-21 14:06:54 -08:00
Matheus Izvekov
deb63e72d6
[clang] Track function template instantiation from definition (#125266) (#127777)
This fixes instantiation of definition for friend function templates,
when the declaration found and the one containing the definition have
different template contexts.

In these cases, the the function declaration corresponding to the
definition is not available; it may not even be instantiated at all.

So this patch adds a bit which tracks which function template
declaration was instantiated from the member template. It's used to find
which primary template serves as a context for the purpose of
obtainining the template arguments needed to instantiate the definition.

Fixes #55509
2025-02-21 10:49:10 -08:00
Mariya Podchishchaeva
8e06e0e65f [clang] Fix preprocessor output from #embed (#126742)
When bytes with negative signed char values appear in the data, make
sure to use raw bytes from the data string when preprocessing, not char
values.

Fixes https://github.com/llvm/llvm-project/issues/102798
2025-02-21 10:38:44 -08:00
Alexander Richardson
77195a5edb [CSKY] Default to unsigned char
This matches the ABI document found at
https://github.com/c-sky/csky-doc/blob/master/C-SKY_V2_CPU_Applications_Binary_Interface_Standards_Manual.pdf

Partially addresses https://github.com/llvm/llvm-project/issues/115957

Reviewed By: zixuan-wu

Pull Request: https://github.com/llvm/llvm-project/pull/115961

(cherry picked from commit d2047242e6d0f0deb7634ff22ab164354c520c79)
2025-02-21 10:36:15 -08:00
Tom Stellard
dc1bd6a8fa [CMake][Release] Statically link clang with stage1 runtimes (#127268)
This change will cause clang and the other tools to statically link
against the runtimes built in stage1. This will make the built binaries
more portable by eliminating dependencies on system libraries like
libgcc and libstdc++.

(cherry picked from commit f5b311e47de044160aeb25221095898c35c4847f)
2025-02-21 09:39:33 -08:00
Matheus Izvekov
9189ca8722 Backport: [clang] fix P3310 overload resolution flag propagation (#125791)
Class templates might be only instantiated when they are required to be
complete, but checking the template args against the primary template is
immediate.

This result is cached so that later when the class is instantiated,
checking against the primary template is not repeated.

The 'MatchedPackOnParmToNonPackOnArg' flag is also produced upon
checking against the primary template, so it needs to be cached in the
specialziation as well.

This fixes a bug which has not been in any release, so there are no
release notes.

Fixes #125290
2025-02-20 15:18:47 -08:00
Zixu Wang
99947c59de Revert "[C++20][Modules][Serialization] Delay marking pending incompl… (#127136)
…ete decl chains until the end of `finishPendingActions`. (#121245)"

This reverts commit a9e249f64e800fbb20a3b26c0cfb68c1a1aee5e1.

Reverting this change because of issue #126973.

(cherry picked from commit 912b154f3a3f8c3cebf5cc5731fd8b0749762da5)
2025-02-20 15:11:16 -08:00
Younan Zhang
3007684f86
release/20.x: [Clang] Remove the PackExpansion restrictions for rewrite substitution (#127174)
This backports c08b80eb525a6e6a34d74634bf5181f11ed12984 with a release
note towards 20 so that we could resolve some pains in CTAD.
2025-02-20 15:08:46 -08:00
Haojian Wu
6b57839efb [clang] Fix false positive regression for lifetime analysis warning. (#127460)
This fixes a false positive caused by #114044.

For `GSLPointer*` types, it's less clear whether the lifetime issue is
about the GSLPointer object itself or the owner it points to. To avoid
false positives, we take a conservative approach in our heuristic.

Fixes #127195

(This will be backported to release 20).

(cherry picked from commit 9c49b188b8e1434eb774ee8422124ad3e8870dce)
2025-02-18 15:20:07 -08:00
Owen Pan
34f5f905f7 [clang-format] Fix a bug in annotating StartOfName (#127545)
Also ensure we can break before ClassHeadName like StartOfName.

Fixes #127470

(cherry picked from commit 13de15c9c49068db850368c45ffed8f7bbf07f20)
2025-02-18 15:12:11 -08:00
Matheus Izvekov
99eab31a80 [clang] StmtPrinter: Handle DeclRefExpr to a Decomposition (#125001)
A DeclRefExpr could never refer to a Decomposition in valid C++ code,
but somehow the Analyzer creates these entities and then it tries to
print them.

There is no sensible answer here, so we print 'decomposition' followed
by the names of all of its bindings, separated by dashes.

(cherry picked from commit 00c096e604ad3a5244af06602556f8de867e36c4)
2025-02-18 15:06:26 -08:00
Florian Hahn
7643bd6602 [TBAA] Don't emit pointer-tbaa for void pointers. (#122116)
While there are no special rules in the standards regarding void
pointers and strict aliasing, emitting distinct tags for void pointers
break some common idioms and there is no good alternative to re-write
the code without strict-aliasing violations. An example is to count the
entries in an array of pointers:

    int count_elements(void * values) {
      void **seq = values;
      int count;
      for (count = 0; seq && seq[count]; count++);
      return count;
    }

https://clang.godbolt.org/z/8dTv51v8W

An example in the wild is from
https://github.com/llvm/llvm-project/issues/119099

This patch avoids emitting distinct tags for void pointers, to avoid
those idioms causing mis-compiles for now.

Fixes https://github.com/llvm/llvm-project/issues/119099.
Fixes https://github.com/llvm/llvm-project/issues/122537.

PR: https://github.com/llvm/llvm-project/pull/122116
(cherry picked from commit 77d3f8a92564b533a3c60a8c8e0657c38fd88ba1)
2025-02-18 15:04:10 -08:00
Owen Pan
6d3b034f8f [clang-format] Add ClassHeadName to help annotating StartOfName (#124891)
Fixes #124574.

(cherry picked from commit 1a25bea852cd4f7d99e644953c31278f7f257ccd)
2025-02-14 14:29:57 -08:00
Owen Pan
94b97d19b7 [clang-format] Fix annotation of Java/JavaScript keyword extends (#125038)
Uncovered in #124891.

(cherry picked from commit ea84474966f19af4f1f4a1250ec258af1c6e2571)
2025-02-14 14:29:57 -08:00
Haojian Wu
37f7f151e5 Diagnose the code with trailing comma in the function call. (#125232)
This patch fixes a regression caused by
https://github.com/llvm/llvm-project/pull/114684 where clang accepts
trailing commas for function calls.

Fixes #125225

(cherry picked from commit 922f339c4ef3631f66dc4b8caa4c356103dbf69d)
2025-02-14 14:15:23 -08:00
Harald van Dijk
4f10d6d3ae [reland][DebugInfo] Update DIBuilder insertion to take InsertPosition (#126967)
After #124287 updated several functions to return iterators rather than
Instruction *, it was no longer straightforward to pass their result to
DIBuilder. This commit updates DIBuilder methods to accept an
InsertPosition instead, so that they can be called with an iterator
(preferred), or with a deprecation warning an Instruction *, or a
BasicBlock *. This commit also updates the existing calls to the
DIBuilder methods to pass in iterators.

As a special exception, DIBuilder::insertDeclare() keeps a separate
overload accepting a BasicBlock *InsertAtEnd. This is because despite
the name, this method does not insert at the end of the block, therefore
this cannot be handled implicitly by using InsertPosition.

(cherry picked from commit 1083ec647f16314bcc9af8c4d6b11f50d288bca6)
2025-02-14 13:35:16 -08:00
Nathan Ridge
79da30bcee [clang][AST] Handle dependent representation of call to function with explicit object parameter in CallExpr::getBeginLoc() (#126868)
This fixes a crash where CallExpr::getBeginLoc() tries to access the
first argument of a CallExpr representing a call to a function with
an explicit object parameter, assuming that a first argument exists
because it's the object argument.

This is the case for non-dependent calls, but for dependent calls
the object argument is part of the callee (the semantic analysis
that separates it out has not been performed yet) and so there may
not be a first argument.

Fixes https://github.com/llvm/llvm-project/issues/126720

(cherry picked from commit 32c8754fbcb936ba6b5bc6cb6817cf3b6a4602f4)
2025-02-14 13:18:28 -08:00
Owen Pan
a7f00c8ed8 [clang-format] Fix a crash on parsing requires clause (#125021)
Fixes #124921.

(cherry picked from commit 14178deab0334d9ce095ae7adce408868659faee)
2025-02-13 18:38:24 -08:00
Owen Pan
82150695fb [clang-format] Hanlde qualified type name for QualifierAlignment (#125327)
Fixes #125178.

(cherry picked from commit eb6ca1242c1035fac6a8f1edfe7925b4994d4ecf)
2025-02-13 18:32:40 -08:00
Owen Pan
bc87f9b809 [clang-format] Handle C-style cast of member function pointer type (#126340)
Fixes #125012.

(cherry picked from commit 8d373ceaec1f1b27c9e682cfaf71aae19ea48d98)
2025-02-11 14:20:03 -08:00
Mikołaj Piróg
f33b128b3d [AVX10.2] Fix wrong intrinsic names after rename (#126390)
In my previous PR (#123656) to update the names of AVX10.2 intrinsics
and mnemonics, I have erroneously deleted `_ph` from few intrinsics.
This PR corrects this.

(cherry picked from commit 161cfc6f39bef8994eb944687033ebd3570196e8)
2025-02-11 14:09:54 -08:00
Mikołaj Piróg
1c36697fbb [AVX10.2] Fix wrong mask casting in some convert intrinsics (#126627)
Found during work on #120927. This caused the compiler to silently drop
ignore half of the mask in the specific intrinsics.

(cherry picked from commit af522c5dd3a38cc5e11e8e62009d7dbe2cde2d86)
2025-02-11 14:07:33 -08:00
Chuanqi Xu
ac97cff5a3 [C++20] [Modules] Don't diagnose duplicated declarations in different modules which is not in file scope
Close https://github.com/llvm/llvm-project/issues/126373

Although the root problems should be we shouldn't place the friend
declaration to the incorrect module, let's avoid bleeding the edge by
stoping diagnosing declarations not in file scope.

(cherry picked from commit 569e94f8f1c3e6998860e2b2ff577870433bdac9)
2025-02-11 14:05:14 -08:00
higher-performance
923d35bcf7 Fix false positive of [[clang::require_explicit_initialization]] on copy/move constructors (#126553)
Fixes #126490

(cherry picked from commit 90192e8872cc90b4d292b180a49babf72d17e579)
2025-02-11 13:22:17 -08:00
Joseph Huber
9e7f8352c7 [Clang] Fix test after new argument was added
(cherry picked from commit 718cdeb9c701725412a040b2b7148523a286a256)
2025-02-11 12:10:47 -08:00
Joseph Huber
1ee32d2234 [Clang] Add width handling for <gpuintrin.h> shuffle helper (#125896)
Summary:
The CUDA impelementation has long supported the `width` argument on its
shuffle instrucitons, which makes it more difficult to replace those
uses with this helper. This patch just correctly implements that for
AMDGPU and NVPTX so it's equivalent to `__shfl_sync` in CUDA. This will
ease porting.

Fortunately these get optimized out correctly when passing in known
widths.

(cherry picked from commit 2d8106cb5a505326d1da0f4461708ed44a0ac761)
2025-02-11 12:10:47 -08:00
Nikolas Klauser
6195c3a981 [Clang] Fix __{add,remove}_pointer in Objective-C++ (#123678)
This aligns the builtins with how implementations work which don't use
the buitins.
2025-02-11 12:03:58 -08:00
Daniil Kovalev
984a779b81 [PAC] Do not support some values of branch-protection with ptrauth-returns (#125280)
This patch does two things.

1. Previously, when checking driver arguments, we emitted an error for
unsupported values of `-mbranch-protection` when using pauthtest ABI.
The reason for that was ptrauth-returns being enabled as part of
pauthtest. This patch changes the check against pauthtest to a check
against ptrauth-returns.

2. Similarly, check against values of the following function attribute
which are unsupported with ptrauth-returns:
`__attribute__((target("branch-protection=XXX`. Note that existing
`validateBranchProtection` function is used, and current behavior is to
ignore the unsupported attribute value, so no error is emitted.

(cherry picked from commit 84b0c128a751acfbf5b439edc724ba27d1da653e)
2025-02-10 17:32:12 -08:00
Nico Weber
b4421735de [clang] Handle f(no-)strict-overflow, f(no-)wrapv, f(no-)wrapv-pointer like gcc (#126524)
We now process all 6 options left-to-right and pick whatever is active
at the end.

Fixes #124868.

(cherry picked from commit 783275eb7b3ecde63bdb6ac1316c090bfc568bdd)
2025-02-10 17:30:02 -08:00
Nico Weber
f0f59e3ecc [clang] Expose -f(no-)strict-overflow as a clang-cl option (#126512)
Also move the -fno-strict-overflow option definition next to the
-fstrict-overflow one while here.

Also add test coverage for f(no-)wrapv-pointer being a clang-cl option.

(cherry picked from commit 71adb054024a1e9bd5ed4566beda74dea65362cd)
2025-02-10 13:47:49 -08:00
Oliver Stannard
38333d5e42 [ARM] Empty structs are 1-byte for C++ ABI (#124762)
For C++ (but not C), empty structs should be passed to functions as if
they are a 1 byte object with 1 byte alignment.

This is defined in Arm's CPPABI32:
  https://github.com/ARM-software/abi-aa/blob/main/cppabi32/cppabi32.rst
  For the purposes of parameter passing in AAPCS32, a parameter whose
  type is an empty class shall be treated as if its type were an
  aggregate with a single member of type unsigned byte.

The AArch64 equivalent of this has an exception for structs containing
an array of size zero, I've kept that logic for ARM. I've not found a
reason for this exception, but I've checked that GCC does have the same
behaviour for ARM as it does for AArch64.

The AArch64 version has an Apple ABI with different rules, which ignores
empty structs in both C and C++. This is documented at
https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms.
The ARM equivalent of that appears to be AAPCS16_VFP, used for WatchOS,
but I can't find any documentation for that ABI, so I'm not sure what
rules it should follow. For now I've left it following the AArch64 Apple
rules.
2025-02-10 13:30:35 -08:00
Chuanqi Xu
0d363c30b8 [C++20] [Modules] Don't diagnose duplicated friend declarations between modules incorrectly
Close https://github.com/llvm/llvm-project/issues/125521

We shouldn't use the ownership information for friend declarations to do
anything.

(cherry picked from commit c5a9a72b3cd118a23193d01bf9393fbf1d4b90ae)
2025-02-10 13:22:12 -08:00
Lang Hames
50c4c2bf68 Re-reapply "[ORC] Enable JIT support for the compact-unwind..." with fixes.
Re-enables compact-unwind support in JITLink, which was reverted in b04847b427d
due to buildbot failures.

The underlying cause for the failures on the buildbots was the lack of
compact-unwind registration support on older Darwin OSes. Since the
CompactUnwindManager pass now removes eh-frames by default we were left with
unwind-info that could not be registered. On x86-64, where eh-frame info is
produced by default the solution is to fall back to using eh-frames. On arm64
we simply can't support exceptions on older OSes.

This patch updates the EHFrameRegistrationPlugin to remove the compact-unwind
section (__LD,__compact_unwind) when installed, forcing use of eh-frames when
the EHFrameRegistrationPlugin is used. In LLJIT, the EHFrameRegistrationPlugin
continues to be used for all non-Darwin platform, and will be added on Darwin
platforms when the a CompactUnwindRegistrationPlugin instance can't be created
(e.g. due to missing support for compact-unwind info registration).

The lit.cfg.py script is updated to check whether the host OSes default unwind
info supports JIT registration, allowing tests to be disabled for older Darwin
OSes on arm64.

(cherry picked from commit eae6d6d18bd4d9e7dfe5fc1206d23d8ef663c8c7)
2025-02-08 16:19:52 +00:00
Michael Park
b2b41544ee [C++20][Modules][Serialization] Delay marking pending incomplete decl chains until the end of finishPendingActions. (#121245)
The call to `hasBody` inside `finishPendingActions` that bumps the `PendingIncompleteDeclChains`
size from `0` to `1`, and also sets the `LazyVal->LastGeneration` to `6` which matches
the `LazyVal->ExternalSource->getGeneration()` value of `6`. Later, the iterations over `redecls()`
(which calls `getNextRedeclaration`) is expected to trigger the reload, but it **does not** since
the generation numbers match.

The proposed solution is to perform the marking of incomplete decl chains at the end of `finishPendingActions`.
This way, **all** of the incomplete decls are marked incomplete as a post-condition of `finishPendingActions`.
It's also safe to delay this operation since any operation being done within `finishPendingActions` has
`NumCurrentElementsDeserializing == 1`, which means that any calls to `CompleteDeclChain` would simply
add to the `PendingIncompleteDeclChains` without doing anything anyway.

(cherry picked from commit a9e249f64e800fbb20a3b26c0cfb68c1a1aee5e1)
2025-02-07 18:36:03 -08:00
kadir çetinkaya
e40790864b [clang] Parse warning-suppression-mapping after setting up diagengine (#125714)
We can emit diagnostics while parsing warning-suppression-mapping, make
sure command line flags take affect when emitting those.

(cherry picked from commit ecb016a87d89aed36b8f5d8102e15d8eb0e57108)
2025-02-07 15:59:30 -08:00
Brad Smith
7bcfaa1c4d [flang][Driver] When linking with the Fortran runtime also link with libexecinfo (#125998)
Also link with libexecinfo on FreeBSD, NetBSD, OpenBSD and DragonFly
for the backtrace functions.

(cherry picked from commit d1de75acea0da55316cd7827563e064105868f0f)
2025-02-07 13:08:01 -08:00
kadir çetinkaya
4cde428de0 [clang] Stop parsing warning suppression mappings in driver (#125722)
This gets rid of some extra IO from driver startup, and possiblity of
emitting warnings twice.

(cherry picked from commit df22bbe2beb57687c76402bc0cfdf7901a31cf29)
2025-02-07 12:49:40 -08:00
Phoebe Wang
99f3ed7375
[X86][AVX10] Disable m[no-]avx10.1 and switch m[no-]avx10.2 to alias of 512 bit options (#124511) (#125057)
Per the feedback we got, we’d like to switch m[no-]avx10.2 to alias of
512 bit options and disable m[no-]avx10.1 due to they were alias of 256
bit options.

We also change -mno-avx10.[1,2]-512 to alias of 256 bit options to
disable both 256 and 512 instructions.

Cherry-pick from
9ebfee9d68
2025-02-06 16:56:13 -08:00
Alexandros Lamprineas
78729e5ae2
[FMV][AArch64] Release notes for LLVM20. (#125525) 2025-02-05 17:27:35 -08:00
Benjamin Maxwell
d8cec6dfe6 [clang] Support member function poiners in Decl::getFunctionType() (#125077)
This seems consistent with the documentation, which claims it:

```
/// Looks through the Decl's underlying type to extract a FunctionType
/// when possible. Will return null if the type underlying the Decl does not
/// have a FunctionType.
const FunctionType *getFunctionType(bool BlocksToo = true) const;
```
Note: This patch rewords this doc comment to clarify it includes various
function pointer types.

Without this, attaching attributes (which use `HasFunctionProto`) to
member function pointers errors with:

```
error: '<attr>' only applies to non-K&R-style functions
```

...which does not really make sense, since member functions are not K&C
functions.

With this change the Arm SME TypeAttrs work correctly on member function
pointers.

Note, however, that not all attributes work correctly when applied to
function pointers or member function pointers. For example,
`alloc_align` crashes when applied to a function pointer (on truck):
https://godbolt.org/z/YvMhnhKfx (as it only expects a `FunctionDecl` not
a `ParmVarDecl`). The same crash applies to member function pointers
(for the same reason).

(cherry picked from commit 692c9b210728323ac499a402ee6eb901f35856f2)
2025-02-05 23:13:28 +00:00
David Green
d185bd94ff [AArch64] Enable vscale_range with +sme (#124466)
If we have +sme but not +sve, we would not set vscale_range on
functions. It should be valid to apply it with the same range with just
+sme, which can help mitigate some performance regressions in cases such
as scalable vector bitcasts (https://godbolt.org/z/exhe4jd8d).

(cherry picked from commit 9f1c825fb62319b94ac9604f733afd59e9eb461b)
2025-02-03 17:32:53 -08:00