22399 Commits

Author SHA1 Message Date
Sharjeel Khan
ee46630dd0
[Clang][Sema] Add fortify warnings for stpcpy (#141646)
As mentioned in https://github.com/llvm/llvm-project/issues/142230, I am
adding fortify warnings for functions missing in Clang and I am starting
with stpcpy.
2025-06-03 10:34:08 -07:00
A. Jiang
986254ee07
[Clang] Implement LWG3819 for __reference_meows_from_temporary (#142554)
Also fix use cases for function reference binding
(`__reference_binds_to_temporary` is also affected despite being
deprecated).
2025-06-03 22:58:14 +08:00
cor3ntin
c9968f4a04
[Clang] Improve infrastructure for libstdc++ workarounds (Reland) (#142592)
Reland with debug traces to try to understand a bug that only happens on
one CI configuration

===

This introduces a way detect the libstdc++ version,
use that to enable workarounds.
The version is cached.

This should make it easier in the future to find and remove
these hacks.

I did not find the need for enabling a hack between or after
specific versions, so it's left as a future exercise.

We can extend this fature to other libraries as the need arise.

===
2025-06-03 14:22:54 +02:00
cor3ntin
16c13e5f7c
Revert "[Clang] Improve infrastructure for libstdc++ workarounds" (#142432)
Reverts llvm/llvm-project#141977

This causes CI failure that I am unable to reproduce.
https://lab.llvm.org/buildbot/#/builders/168/builds/12688
2025-06-03 12:27:36 +02:00
Ami-zhang
06f779b69d
Reland "[Clang][LoongArch] Support target attribute for function" (#142546)
This relands #140700. I have updated the test case('targetattr.c') to
resolve the test failure.

Original PR resulted in test fail:
https://lab.llvm.org/buildbot/#/builders/11/builds/16173
https://lab.llvm.org/buildbot/#/builders/202/builds/1531

Original description:
Followup to #140700.
2025-06-03 15:57:50 +08:00
A. Jiang
208e3b0956
[Clang] Properly deprecate __reference_binds_to_temporary (#141909)
At the time `__reference_constructs_from_temporary` got implemented,
`__reference_binds_to_temporary` was mentioned as deprecated in
`LanguageExtensions.rst`, but no deprecation warning was emitted. This
PR adds the previously missing warning.
2025-06-03 11:25:07 +08:00
Tomas Matheson
832a7bb460
[AArch64] Add missing Neon Types (#126945)
The AAPCS64 adds a number of vector types to the C unconditionally:
https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#11appendix-support-for-advanced-simd-extensions

The equivalent SVE types are already available in clang:
https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#12appendix-support-for-scalable-vectors

__mfp8 is defined in the ACLE
https://arm-software.github.io/acle/main/acle.html#data-types

---------

Co-authored-by: David Green <david.green@arm.com>
2025-06-02 17:09:35 +01:00
Yutong Zhu
0ada5c7b1a
[Clang] Separate implicit int conversion on negation sign to new diagnostic group (#139429)
This PR reverts a change made in #126846. 

#126846 introduced an ``-Wimplicit-int-conversion`` diagnosis for 
```c++
int8_t x = something;
x = -x; // warning here
```

This is technically correct since -x could have a width of 9, but this
pattern is common in codebases.

Reverting this change would also introduce the false positive I fixed in
#126846:
```c++
bool b(signed char c) {
  return -c >= 128; // -c can be 128
}
```

This false positive is uncommon, so I think it makes sense to revert the
change.
2025-06-02 07:27:32 -04:00
Alexandros Lamprineas
b3fd2ea888
[Clang][FMV] Stop emitting implicit default version using target_clones. (#141808)
With the current behavior the following example yields a linker error:
"multiple definition of `foo.default'"

// Translation Unit 1
__attribute__((target_clones("dotprod, sve"))) int foo(void) { return 1; }

// Translation Unit 2
int foo(void) { return 0; }
__attribute__((target_version("dotprod"))) int foo(void);
__attribute__((target_version("sve"))) int foo(void);
int bar(void) { return foo(); }

That is because foo.default is generated twice. As a user I don't find
this particularly intuitive. If I wanted the default to be generated in
TU1 I'd rather write target_clones("dotprod, sve", "default")
explicitly.

When changing the code I noticed that the RISC-V target defers the
resolver emission when encountering a target_version definition. This
seems accidental since it only makes sense for AArch64, where we only
emit a resolver once we've processed the entire TU, and only if the
default version is present. I've changed this so that RISC-V immediately
emmits the resolver. I adjusted the codegen tests since the functions
now appear in a different order.

Implements https://github.com/ARM-software/acle/pull/377
2025-06-02 11:04:00 +01:00
Younan Zhang
e04e140adb
[Clang] Reapply CWG2369 "Ordering between constraints and substitution" (#122423)
The previous approach broke code generation for the MS ABI due to an
unintended code path during constraint substitution. This time we
address the issue by inspecting the evaluation contexts and thereby
avoiding that code path.

This reapplies 96eced624 (#102857).
2025-06-02 17:10:07 +08:00
Brandon Wu
88aa5cbbda
[clang][RISCV] Handle target features correctly in CheckBuiltinFunctionCall (#141548)
Currently we only check the required features passed by command line
arguments.
We also need to check the features passed by using target features.
2025-06-01 17:57:08 +08:00
Timm Baeder
b9675617af
[clang][Sema] Optimize ~SemaDiagnosticBuilder (#142252)
Call getDiagnosticLevel(), which is expensive, only if ShowCallStack is
set.

Small gains:

https://llvm-compile-time-tracker.com/compare.php?from=843e362318e884991e517a54446b4faeacdad789&to=5cef0c18466318a426924b3c45f7abaaa8f6b535&stat=instructions:u
2025-05-31 19:59:55 +02:00
Aaron Ballman
0adf6e8d33
Work around a build issue with MSVC; NFC (#142195)
Microsoft helpfully defines `THIS` to `void` in two different platform
SDK headers, at least one of which is reachable via <Windows.h>. We have
a user who ran into a build because of `THIS` unfortunate macro name
collision.

Rename the members to better match our naming conventions.

Fixes #142186
2025-05-31 08:35:26 -04:00
cor3ntin
6f7268e204
[Clang] Improve infrastructure for libstdc++ workarounds (#141977)
This introduces a way detect the libstdc++ version, use that to enable
workarounds.
The version is cached.

This should make it easier in the future to find and remove these hacks.

I did not find the need for enabling a hack between or after specific
versions, so it's left as a future exercise.

We can extend this fature to other libraries as the need arise.
2025-05-31 12:26:49 +02:00
Jim Lin
dfbb9a0e30
[RISCV] Implement intrinsics for XAndesVDot (#141441)
This patch implements clang intrinsic support for XAndesVDot.

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-dot-product-extensionxandesvdot
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-dot-product-extensionxandesvdot

Co-authored-by: Tony Chuan-Yue Yuan <yuan593@andestech.com>
2025-05-31 14:12:01 +08:00
erichkeane
c66dbbe385 [OpenACC] Implement 'capture' modifier Sema/AST
The 'capture' modifier is an OpenACC 3.3NEXT (AKA 3.4) feature, which
permits a new kind of identifying the memory location of variables in a
data clause. However, it is only valid on data, combined, or compute
constructs.

This patch implements all of the proper restrictions.
2025-05-30 09:31:25 -07:00
Timm Baeder
ccb6b0dafd
[clang][NFC] Move Diags.isIgnored check later in checkForRedundantLoop (#141470)
... Iteration.

The `isIgnored()` check is more expensive than the earlier checks, so
move it last.
2025-05-30 17:26:30 +02:00
Acthink Yang
4d650ef4b3
[Sema] Fix type mismatch error when arguments to elementwise math builtin have different qualifiers, which should be well-formed (#141485)
Fixes #141397
Element-wise math builtins (e.g.
__builtin_elementwise_max/__builtin_elementwise_pow etc.) fail when
their arguments have different qualifications, but should be
well-formed. The fix is ​​to use hasSameUnqualifiedType to check if the
arguments match.
2025-05-30 07:09:20 -07:00
Matheus Izvekov
3609e09aa7
[clang] member pointer class qualification fix (#142081)
This fixes a regression introduced in
https://github.com/llvm/llvm-project/pull/130537,
which was reported here:
https://github.com/llvm/llvm-project/pull/132401#issuecomment-2839690599

When deducing member pointers class, ignore top level qualifiers on the
argument side, since the class portion of a member pointer is a
nested-name-specifier, and these just nominate an entity.

Qualifiers on the parameter side are fine since deduction allows the
parameter side to be more qualified, and these qualifiers won't be part
of the result.

Since this regression was never released, there are no release notes.
2025-05-30 02:25:21 -03:00
Weining Lu
fbbae9ea2b [LoongArch] Only report the first range error if there is actually more than one for __builtin_loongarch_cacop_[wd]
Other builtins do the same. Align with them.
2025-05-30 10:29:00 +08:00
Paul Kirth
d93788fcbf
Revert "[Clang][LoongArch] Support target attribute for function" (#141998)
Reverts llvm/llvm-project#140700

This breaks bots both in buildbot and downstream CI: 
- https://lab.llvm.org/buildbot/#/builders/11/builds/16173
- https://lab.llvm.org/buildbot/#/builders/202/builds/1531
-
https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-host-linux-x64/b8713537585914796017/overview
2025-05-29 11:26:44 -07:00
Kazu Hirata
28eb66b794 [Sema] Fix a warning
This patch fixes:

  clang/lib/Sema/SemaSPIRV.cpp:132:3: error: default label in switch
  which covers all enumeration values
  [-Werror,-Wcovered-switch-default]
2025-05-29 09:10:19 -07:00
Victor Lomuller
c474f8f240
[clang][SPIRV] Add builtin for OpGenericCastToPtrExplicit and its SPIR-V friendly binding (#137805)
The patch introduce __builtin_spirv_generic_cast_to_ptr_explicit which
is lowered to the llvm.spv.generic.cast.to.ptr.explicit intrinsic.

The SPIR-V builtins are now split into 3 differents file:
BuiltinsSPIRVCore.td,
BuiltinsSPIRVVK.td for Vulkan specific builtins, BuiltinsSPIRVCL.td for
OpenCL specific builtins
and BuiltinsSPIRVCommon.td for common ones.

The patch also introduces a new header defining its SPIR-V friendly
equivalent (__spirv_GenericCastToPtrExplicit_ToGlobal,
__spirv_GenericCastToPtrExplicit_ToLocal and
__spirv_GenericCastToPtrExplicit_ToPrivate). The functions are declared
as aliases to the new builtin allowing C-like languages to have a
definition to rely on as well as gaining proper front-end diagnostics.

The motivation for the header is to provide a stable binding for
applications or library (such as SYCL) and allows non SPIR-V targets to
provide an implementation (via libclc or similar to how it is done for
gpuintrin.h).
2025-05-29 15:19:40 +02:00
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
cor3ntin
13011f21d6
[Clang] Optimize some getBeginLoc implementations (#141058)
The bulk of the changes are in `CallExpr`

We cache Begin/End source locs in the trailing objects, in the space
left by making the offset to the trailing objects static.
We also set a flag to indicate that we are calling an explicit object
member function, further reducing the cost of getBeginLoc.

Fixes #140876
2025-05-29 10:25:53 +02:00
Joseph Huber
539a2ac5f2
[OpenMP] Fix atomic compare handling with overloaded operators (#141142)
Summary:
When there are overloaded C++ operators in the global namespace the AST
node for these is not a `BinaryExpr` but a `CXXOperatorCallExpr`. Modify
the uses to handle this case, basically just treating it as a binary
expression with two arguments.

Fixes https://github.com/llvm/llvm-project/issues/141085
2025-05-28 21:44:55 -05:00
Ashley Coleman
cb7f4ff03c
[HLSL] Add Buffer def to frontend (#141086)
Fixes #138902

Defines the `Buffer<>` type in the clang frontend. Lowering from
IR->Target Machine is already handled by other code
2025-05-28 13:58:47 -06:00
Younan Zhang
67d907a72f
[Clang] Reset ArgPackSubstIndex before rewriting CTAD template parameters (#141741)
032ad59 taught the instantiator to expand template argument packs for
rewrite. However we might already be in a pack expansion when we
synthesizing the CTAD guide, so we reset the ArgPackSubstIndex to ensure
it doesn't get confused.

No release note because this is a regression in Clang 21.

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

---------

Co-authored-by: Erich Keane <ekeane@nvidia.com>
2025-05-28 23:33:43 +08:00
Rajveer Singh Bharadwaj
59a5c1f25f
[clang][Sema] Diagnose exceptions only in non-dependent context in discarded try/catch/throw blocks (#139859)
Resolves #138939

When enabling `--fno-exceptions` flag, discarded statements containing
`try/catch/throw` in an independent context can be avoided from being
rejected.
2025-05-28 07:10:55 -07:00
Yaxun (Sam) Liu
54ddbc6be3
[AMDGPU] fix amdgpu_max_num_work_groups in templates (#141633)
Clang does not instantiate amdgpu_max_num_work_groups attribute with one
template argument, causing
assertion codegen.

Fixes: https://github.com/llvm/llvm-project/issues/139570
2025-05-28 08:05:03 -04:00
David Green
3a42cbd47d [AArch64] Rename AArch64SVEACLETypes.def and add base SVE_TYPE. 2025-05-28 12:26:54 +01:00
cor3ntin
5c063bebe4
[Clang] Fix a regression introduced by #138518 (#141342)
We did not handle the case where a variable could be initialized by a
CXXParenListInitExpr.

---------

Co-authored-by: Shafik Yaghmour <shafik.yaghmour@intel.com>
2025-05-28 07:00:22 +02:00
Timm Baeder
2340a4e902
[clang][Sema] Cleanup and optimize DiagnoseAssignmentEnum (#141471)
Reorder the precondition checks to move the costly onces last. Also,
only evaluate the RHS once to get the integral value.
2025-05-28 06:02:02 +02:00
Helena Kotas
20f1e351c7
[HLSL] Add resource name argument to resource class constructors (#139985)
Adds resource name argument to resource class constructors and to builtin functions that initialize resource handles
`__builtin_hlsl_resource_handlefrombinding` and `__builtin_hlsl_resource_handlefromimplicitbinding`.

Part 1/4 of https://github.com/llvm/llvm-project/issues/105059
2025-05-27 10:41:04 -07:00
Cassandra Beckley
5a4571133a
[HLSL] Implement SpirvType and SpirvOpaqueType (#134034)
This implements the design proposed by [Representing SpirvType in
Clang's Type System](https://github.com/llvm/wg-hlsl/pull/181). It
creates `HLSLInlineSpirvType` as a new `Type` subclass, and
`__hlsl_spirv_type` as a new builtin type template to create such a
type.

This new type is lowered to the `spirv.Type` target extension type, as
described in [Target Extension Types for Inline SPIR-V and Decorated
Types](https://github.com/llvm/wg-hlsl/blob/main/proposals/0017-inline-spirv-and-decorated-types.md).
2025-05-27 11:40:54 -04:00
Aaron Ballman
cc5237c7af
[C2y] Correctly handle incomplete types in generic selections (#141596)
We were emitting a non-error diagnostic but claiming we emitted an
error, which caused some obvious follow-on problems.

Fixes #141549
2025-05-27 11:29:30 -04:00
Younan Zhang
f8d63168b6
[Clang] Fix a pack expansion bug in template argument deduction (#141547)
I think the intent of df18ee96206 was to substitute only those non-packs
into a pack expansion type (e.g. `T` in `T::pack...`), so let's hold off
pack expansions explicitly, in case there are calls coming from a
substitution of pack expansion.

Fixes https://github.com/llvm/llvm-project/issues/53609
2025-05-27 15:10:24 +08:00
Timm Baeder
17ef0fe594
[clang][OpenCL] Only evaluate initializer once to check for zero init (#141474)
Both Expr::isIntegerConstantExpr() and Expr::EvaluateKnownConstInt()
evaluate the expression. Just do it once and check the integer result.
2025-05-27 08:12:18 +02:00
Marco Elver
c7ccfc6dfc
Thread Safety Analysis: Support reentrant capabilities (#137133)
Introduce the `reentrant_capability` attribute, which may be specified
alongside the `capability(..)` attribute to denote that the defined
capability type is reentrant. Marking a capability as reentrant means
that acquiring the same capability multiple times is safe, and does not
produce warnings on attempted re-acquisition.

The most significant changes required are plumbing to propagate if the
attribute is present to a CapabilityExpr, and introducing
ReentrancyDepth to the LockableFactEntry class.
2025-05-26 17:03:55 +02:00
Timm Baeder
dff6aee945
[clang][NFC] Call Stmt::getBeginLoc() once in DiagnoseForRangeVariable (#141472)
...Copies. Instead of three times.
2025-05-26 13:46:12 +02:00
Connector Switch
64bc35f33e
[NFC] Fix bad link in clang/lib/Sema/SemaTypeTraits.cpp (#141405) 2025-05-26 10:13:14 +08:00
Kazu Hirata
12af64d0d7
[Sema] Remove unused includes (NFC) (#141419)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-05-25 10:55:32 -07:00
GkvJwa
7511107d60
Use emplace_back instead of push_back (NFC) 2025-05-26 00:38:23 +08:00
Kazu Hirata
24c782e003
[clang] Use llvm::partition_point (NFC) (#141351) 2025-05-24 09:37:26 -07:00
Timm Baeder
3f3b19d2b7
[clang][NFC] Clean up SemaChecking.cpp (#141041)
Make pointer parameters const, remove some unused parameters, fix coding
style, etc.
2025-05-24 16:17:37 +02:00
Benjamin Kramer
7cfdd74f0f [Sema] Fold variable into assert to avoid warnings. NFCI 2025-05-24 13:03:36 +02:00
cor3ntin
0804ca88ab
[Clang] Explain why a type trait evaluated to false. (#141238)
`static_assert(std::is_xx_v<MyType>);` is a common pattern to check that
a type meets a requirement.

This patch produces diagnostics notes when such assertion fails. The
first type trait for which we provide detailed explanation is
std::is_trivially_relocatable.

We employ the same mechanisn when a type trait appears an an unsatisfied
atomic constraint.

I plan to also support `std::is_trivially_replaceable` in a follow up
PR, and hopefully, over time we can support more type traits.
2025-05-24 10:36:18 +02:00
cor3ntin
9502d1bcb2
[Clang][NFC] Move the type trait logic to a separate file. (#141245)
Just to try to keep the size of SemaExprCXX.cpp in check.

As discussed in #141238
2025-05-23 18:22:49 +02:00
Younan Zhang
d4f0f43506
[Clang] Fix the access checking for non-aggregates in default arguments (#141207)
We check the accessibility of constructors when initializing a default
argument whose type is not an aggregate.

Make sure the check is performed within the correct DeclContext.
Otherwise, it will be delayed until the end of the declaration, at which
point the context is mismatched.

Fixes #62444 
Fixes https://github.com/llvm/llvm-project/issues/83608
2025-05-23 20:11:22 +08:00
Jiefeng Wang
4f844e7881
[OpenCL] No need to check array of struct for kernel arguments (#138894)
Since arrays decay into pointers, no need to check them for arguments.
This commit reverts part of the changes from the commit "[OpenCL] Check
for invalid kernel arguments in array types"
3b238ed6626983beb238b95eada4172184fb2d29.
2025-05-23 10:38:35 +02:00