113499 Commits

Author SHA1 Message Date
Chris B
a7d5b3f711
[HLSL] Disallow virtual inheritance and functions (#127346)
This PR disallows virtual inheritance and virtual functions in HLSL.
2025-03-09 12:18:44 -05:00
Timm Baeder
0f732481ac
[clang][bytecode] Fix getting pointer element type in __builtin_memcmp (#130485)
When such a pointer is heap allocated, the type we get is a pointer
type. Take the pointee type in that case.
2025-03-09 12:57:42 +01:00
Ben Shi
2172a5edcf
[clang][analyzer][NFC] Fix typos in comments (#130456) 2025-03-09 08:23:51 +01:00
Timm Baeder
227f9544a4
[clang][bytecode][NFC] Bail out on non constant evaluated builtins (#130431)
If the ASTContext says so, don't bother trying to constant evaluate the
given builtin.
2025-03-09 06:35:19 +01:00
Liberty
c4ed0ad1f5
[Clang] Fix typo 'dereferencable' to 'dereferenceable' (#116761)
This patch corrects the typo 'dereferencable' to 'dereferenceable' in
CGCall.cpp.
The typo is located within a comment inside the `void
CodeGenModule::ConstructAttributeList` function.
2025-03-08 19:35:20 +00:00
Timm Baeder
aff6ab9d90
[clang][bytecode] Surround bcp condition with Start/EndSpeculation (#130427)
This is similar to what the current interpreter is doing - the
FoldConstant RAII object surrounds the entire HandleConditionalOperator
call, which means the condition and both TrueExpr or FalseExpr.
2025-03-08 19:37:20 +01:00
Timm Baeder
e4fe22a8bd
[clang][bytecode][NFC] Check conditional op condition for ConstantExprs (#130425)
Same thing we now do in if statements. Check the condition of a
conditional operator for a statically known true/false value.
2025-03-08 18:29:19 +01:00
Timm Baeder
46d218d1af
[clang][bytecode] Implement __builtin_{memchr,strchr,char_memchr} (#130420)
llvm has recently started to use `__builitn_memchr` at compile time, so
implement this. Still needs some work but the basics are done.
2025-03-08 16:52:06 +01:00
Timm Baeder
3b8f9a228c
[clang][bytecode] Loosen assertion This() for array elements (#130399)
getRecord() returns null on array elements, even for composite arrays.
The assertion here was overly restrictive and having an array element as
instance pointer should be fine otherwise.
2025-03-08 13:13:52 +01:00
Timm Baeder
d08cf7900d
[clang][bytecode] Implement __builtin_constant_p (#130143)
Use the regular code paths for interpreting.

Add new instructions: `StartSpeculation` will reset the diagnostics
pointers to `nullptr`, which will keep us from reporting any diagnostics
during speculation. `EndSpeculation` will undo this.

The rest depends on what `Emitter` we use.

For `EvalEmitter`, we have no bytecode, so we implement `speculate()` by
simply visiting the first argument of `__builtin_constant_p`. If the
evaluation fails, we push a `0` on the stack, otherwise a `1`.

For `ByteCodeEmitter`, add another instrucion called `BCP`, that
interprets all the instructions following it until the next
`EndSpeculation` instruction. If any of those instructions fails, we
jump to the `EndLabel`, which brings us right before the
`EndSpeculation`. We then push the result on the stack.
2025-03-08 06:06:14 +01:00
Matt Arsenault
7602d781b0
clang/HIP: Use regex for final path separator in hip-partial-link, again (#130371) 2025-03-08 10:53:03 +07:00
Heejin Ahn
76393d3863
[WebAssembly] Rename functions in wasm-eh.cpp (#130220)
I think it is generally better for tests have some descriptive function
names so that we can insert new tests in the middle and don't have to
renumber all tests.

Also recently I added a (named) test to this file in #129020 so I think
it's consistent for other tests to be named.
2025-03-07 16:54:22 -08:00
Chris B
0ea52234fc
[DXC] Add -metal flag to DXC driver (#130173)
This adds a flag to the DXC driver to enable calling the metal shader
converter if it is available to convert the final shader output for
metal.
2025-03-07 17:28:41 -06:00
Lei Huang
23a44b925a
[NFC] Add additional checks to test for vec_pack_to_short_fp32 (#130324)
Update test in prep for IR changes that will be introduced in
https://github.com/llvm/llvm-project/pull/129923
2025-03-07 18:27:35 -05:00
Ziqing Luo
b2563028cf
[-Wunsafe-buffer-usage] Add alloc_size knowledge to the 2-param span constructor warning (#114894)
We can take advantage of the attribute `alloc_size`.  For example, 
```
void * malloc(size_t size) __attribute__((alloc_size(1)));

std::span<char>{(char *)malloc(x), x}; // this is safe
```

rdar://136634730
2025-03-07 15:05:20 -08:00
Ryosuke Niwa
c419acdf82
[alpha.webkit.UncountedCallArgsChecker] Recognize CXXUnresolvedConstructExpr as a safe origin. (#130258)
Handle CXXUnresolvedConstructExpr in tryToFindPtrOrigin so that
constructing Ref, RefPtr, CheckedRef, CheckedPtr, ... constructed in
such a way that its type is unresolved at AST level will be still
treated as a safe pointer origin.

Also fix a bug in isPtrOfType that it was not recognizing
DeducedTemplateSpecializationType.
2025-03-07 14:40:33 -08:00
Yaxun (Sam) Liu
5ff43550fa Revert "Fix amdgpu-arch for dll name on Windows (#101350)"
This reverts commit 6fa1bfad65edefe3f4c17740f05297d34e833b47.

Revert it due to breaking buildbot:

Z:\b\llvm-clang-x86_64-sie-win\llvm-project\clang\tools\amdgpu-arch\AMDGPUArchByHIP.cpp(104):
 error C2039: 'parse': is not a member of 'llvm::VersionTuple'

https://lab.llvm.org/buildbot/#/builders/46/builds/13184
2025-03-07 15:54:50 -05:00
Aaron Ballman
8c130b11cb Update the C status page for N3409
This was implemented in b19ed9c0435c5f7c89cba40285df3a1395a782fd but I
forgot to update the website at the same time.
2025-03-07 15:22:28 -05:00
Aaron Ballman
0ea02e7721 [C2y] Claim nonconformance to WG14 N3410
This paper made it a constraint violation for the same identifier
within a TU to have both internal and external linkage. It was
previously UB.

Clang does not correctly diagnose the constraint in some cases,
documented in the added test case.
2025-03-07 15:15:53 -05:00
Joseph Huber
fefb6858da [Clang][Docs] Fix `ext_vector_type` code block documentation 2025-03-07 13:55:39 -06:00
Aaron Ballman
b19ed9c043
[C2y] Implement WG14 N3409 (#130299)
This paper removes UB around use of void expressions. Previously, code
like this had undefined behavior:
```
  void foo(void) {
    (void)(void)1;
    extern void x;
    x;
  }
```
and this is now well-defined in C2y. Functionally, this now means that
it is valid to use `void` as a `_Generic` association.
2025-03-07 14:46:29 -05:00
Andy Kaylor
8eb9b947af
[CIR] Emit init of local variables (#130164)
Local variable initialization was previously being ignored. This change
adds support for initialization of scalar variables with constant values
and introduces the constant emitter framework.
2025-03-07 10:23:06 -08:00
Yaxun (Sam) Liu
6fa1bfad65
Fix amdgpu-arch for dll name on Windows (#101350)
Recently HIP runtime changed dll name to amdhip64_n.dll on Windows,
where n is ROCm major version number.

Fix amdgpu-arch to search for amdhip64_n.dll on Windows.
2025-03-07 13:13:46 -05:00
Joseph Huber
5c9d0a26d9
[LinkerWrapper] Try to fix testing on Windows (#130285)
Summary:
Thanks to @Meinersbur for finding this. The `:` character used in AMD's
target-id's is invalid on windows. This patch replaces them with `-`.

---------

Co-authored-by: Michael Kruse <github@meinersbur.de>
2025-03-07 11:10:21 -06:00
Joseph Huber
3ed4daf9a7 [Clang] Add missing printer for vector type attribute 2025-03-07 10:39:09 -06:00
Matt Arsenault
c6b9d5ce76
clang/HIP: Use regex for final path separator in hip-partial-link.hip (#130291)
Somehow this passed the precheck test on the windows bot, but is
failing in precheck of unrelated PRs
2025-03-07 23:36:34 +07:00
Timm Baeder
d6a4828c8a
[clang][bytecode] Special-case ConstantExpr in if conditions (#130294)
This happens a lot with `if constexpr` with a condition based on a
template param. In those cases, the condition is a ConstantExpr with a
value already set, so we can use that and ignore the other branch.
2025-03-07 17:35:06 +01:00
Aaron Ballman
494bf26736 Add a link to the paper to a release note; NFC 2025-03-07 11:10:28 -05:00
Joseph Huber
0a41fb71f1
[Clang] Treat ext_vector_type as a regular type attribute (#130177)
Summary:
This attribute is mostly borrowed from OpenCL, but is useful in general
for accessing the LLVM vector types. Previously the only way to use it
was through typedefs. This patch changes that to allow use as a regular
type attribute, similar to address spaces.
2025-03-07 10:09:06 -06:00
erichkeane
67960e5c08 [OpenACC] Ensure decl OpenACC constructs don't crash
I initially implemented codegen to be a 'no-op' for these declarations,
  which I thought was properly implemented.  However, when they are a
  top-level decl, we have a separate switch.  This patch makes sure they
  are properly emitted at top-level as a no-op, and adds a test for both
  top-level and not top-level.
2025-03-07 08:05:19 -08:00
Aaron Ballman
d1bd1c7e82 [C2y] Claim conformance to WG14 N3496
This was a clarification for C23's N2412, primarily about the
BOOL_WIDTH macro. It should expand to the number of bits in the value
representation, not the object representation. Clang 20 implements the
correct value.
2025-03-07 09:51:33 -05:00
erichkeane
1c1140c4cf [OpenACC] Enable 'device_type' for 'routine'
There is a slightly different list for routine on which clauses are
permitted after it (like the rest of the constructs), but this
implements and tests them to make sure we get them right.
2025-03-07 06:49:29 -08:00
Aaron Ballman
40ee5a0bcc [C2y] Claim conformance to WG14 N3481
This paper made it a constraint violation to have an incomplete type
during lvalue conversion. Previously, this was undefined behavior.

Clang has always diagnosed this for non-void incomplete types. However,
Clang does allow derefencing a void pointer (with a diagnostic, so we
still meet the conformance requirements), but not for a value
computation.
2025-03-07 09:37:15 -05:00
Aaron Ballman
5b3f50ead1 [C2y] Claim nonconformance to WG14 N3418
This paper makes it a constraint violation to form a UCN via token
concatenation. Clang does not conform to it and the paper goes in the
opposite direction of where C++ went with P2621R3 which was adopted for
C++26.
2025-03-07 08:58:33 -05:00
Aaron Ballman
9fc3310798
[C2y] Implement WG14 N3411 (#130180)
This paper (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3411.pdf)
allows a source file to end without a newline. Clang has supported this
as a conforming extension for a long time, so this suppresses the
diagnotic in C2y mode but continues to diagnose as an extension in
earlier language modes. It also continues to diagnose if the user passes
-Wnewline-eof explicitly.
2025-03-07 08:34:22 -05:00
Aaron Ballman
2c8b824ff5 [C2y] Claim conformance to WG14 N3478
This paper made it a constraint violation for a TU to end with an
unterminated multiline comment. This is something Clang has always
diagnosed as an error.
2025-03-07 08:31:56 -05:00
Jan Voung
81168e2dc1
[clang][dataflow] Add test for crash repro and clean up const accessor handling (#129930)
Add test for https://github.com/llvm/llvm-project/issues/125589

The crash is actually incidentally fixed by
https://github.com/llvm/llvm-project/pull/128437 since it added a branch
for the reference case and would no longer fall through when the return
type is a reference to a pointer.

Clean up a bit as well:
- make the fallback for early returns more consistent (check if
  returning optional and call transfer function for that case)
- check RecordLoc == nullptr in one place
- clean up extra spaces in test
- clean up parameterization in test of `std::` vs `$ns::$`
2025-03-07 08:16:46 -05:00
Joseph Huber
90e421516e
[Offload] Always consider flto on for AMDGPU (#129118)
Summary:
Previously we turned this off, but that led to a regression in some of
the option handling. I would argue that handling LTO by default was
incorrect bheavior, but for AMDGPU people were used to this default, so
we pass it by default. `-fno-lto` overrides.
2025-03-07 06:54:09 -06:00
Tom Eccles
f7daa9d302
[mlir][OpenMP] fix crash outlining infinite loop (#129872)
Previously an extra block was created by splitting the previous exit
block. This produced incorrect results when the outlined region
statically never terminated because then there wouldn't be a valid exit
block for the outlined region, this caused this newly added block to
have an incoming edge from outside of the outlining region, which caused
outlining to fail.

So far as I can tell this extra block no longer serves any purpose. The
comment says it is supposed to collate multiple control flow edges into
one place, but the code as it is now does not achieve this. In fact, as
can be seen from the changes to lit tests, this block was not actually
outlined in the end. This is because there are actually two code
extractors: one in the callback for creating a parallel op which is used
to find what the input/output variables are (which does have this block
added to it), and another one which actually does the outlining (which
this block was not added to).

Tested with the gfortran and fujitsu test suites.

Fixes #112884
2025-03-07 11:02:52 +00:00
Michael Jabbour
180f8032f0
[clang] Fix ASTWriter crash after merging named enums (#114240)
Clang already removes parsed enumerators when merging typedefs to
anonymous enums. This is why the following example decl used to be
handled correctly while merging, and ASTWriter behaves as expected:

```c
typedef enum { Val } AnonEnum;
```
However, the mentioned mechanism didn't handle named enums. This leads
to stale declarations in `IdResolver`, causing an assertion violation in
ASTWriter ``Assertion `DeclIDs.contains(D) && "Declaration not
emitted!"' failed`` when a module is being serialized with the following
example merged enums:

```c
typedef enum Enum1 { Val_A } Enum1;
enum Enum2 { Val_B };
```

The PR applies the same mechanism in the named enums case.

Additionally, I dropped the call to
`getLexicalDeclContext()->removeDecl` as it was causing a wrong
odr-violation diagnostic with anonymous enums.

Might be easier to to review commit by commit. Any feedback is
appreciated.

### Context

This fixes frontend crashes that were encountered when certain
Objective-C modules are included on Xcode 16. For example, by running
`CC=/path/to/clang-19 xcodebuild clean build` on a project that contains
the following Objective-C file:

```c
#include <os/atomic.h>

int main() {
  return memory_order_relaxed;
}
```
This crashes the parser in release, when ASTReader tries to load the
enumerator declaration.
2025-03-07 11:02:19 +01:00
Ricardo Jesus
21610e3ecc
Revert "[AArch64][SVE] Improve fixed-length addressing modes." (#130263)
This reverts commit f01e760c08365426de95f02dc2c2dc670eb47352.
2025-03-07 09:35:55 +00:00
Matt Arsenault
c687d78b3a
clang: Switch linker-wrapper test to unsupported windows (#130247)
Works fine on macos, so expand the tested hosts. This should work
on windows too, but it's been a pain debugging the error on the bot.
2025-03-07 16:31:58 +07:00
Matt Arsenault
eb4a7052f6
clang/HIP: Remove requires system-linux from some driver tests (#112842) 2025-03-07 16:24:02 +07:00
zhaohui
3a67c7c6f7
[Clang] Check for uninitialized use in lambda within CXXOperatorCallExpr (#129198)
Track whether a LambdaExpr is an immediate operand of a
CXXOperatorCallExpr using a new flag, isInCXXOperatorCall. This enables
special handling of capture initializations to detect uninitialized
variable uses, such as in `S s = [&]() { return s; }();`.

Fix #128058
2025-03-07 16:01:23 +08:00
Yanzuo Liu
d933882ed3
[Clang] Add test for CWG2285 "Issues with structured bindings" (#126421)
The resolution of [CWG2285](https://wg21.link/cwg2285) adds the point of
declaration of a structured binding, and was implemented in
bdb84f374c
.

Drive-by changes: modify comment and diagnostic messages mentioned in
CWG2285.
2025-03-07 07:16:51 +01:00
Owen Pan
3664b4e2d5
[clang-format] Remove special handling of C++ access specifiers in C (#129983)
This effectively reverts d1aed486efc6d35a81ca4acbabb4203c4b91cda9
because of
#129426.
2025-03-06 21:08:25 -08:00
Yaxun (Sam) Liu
2674034422
Reland "[HIP] Use original file path for CUID" (#111885)
This patch fixes the buildbots failure of lit tests on MacOS. Since
clang driver options depend on toolchain, we cannot hardcode CUID hash.
On MacOS there is an extra -mlinker-version= option.
2025-03-06 22:46:41 -05:00
Kito Cheng
55f86cf023
[RISCV][clang] Fix wrong VLS CC detection (#130107)
RISCVABIInfo::detectVLSCCEligibleStruct should early exit if VLS calling
convention is not used, however the sentinel value was not set to
correctly, it should be zero instead of one.
2025-03-07 11:15:20 +08:00
Joseph Huber
d5cef39d74
[Clang] Make '-Wglobal-constructors` work on the GNU attributes (#129917)
Summary:
The `-Wglobal-constructors` option is useful for restricting the usage
of global constructors / destructors. However, it currently ignores the
attributes that introduce global constructors, meaning that the module
can still have ctors if `-Werror` is set. If this is intentional by the
user, I believe it would be more correct to push the diagnostic.
2025-03-06 20:43:42 -06:00
Joseph Huber
ca39a029b6
[Clang] Fix 'gpuintrin.h' match when included with no arch set (#129927)
Summary:
These require `+ptx` features to be set even though they're guarded by
the `__nvvm_reflect`. Rather than figure out how to hack around that
with the `target` attribute I'm just going to disable it for 'generic'
builds and use the slow version for now.
2025-03-06 19:37:39 -06:00