57751 Commits

Author SHA1 Message Date
Thurston Dang
d1badf5635
[cfi][NFCI] Precommit tests to show nomerge functionality (#135104)
https://github.com/llvm/llvm-project/pull/120464 (and earlier CLs) added -fsanitize-merge functionality, which is intended to work for all "sanitizers". It is nearly correct for CFI.

This patch precommits some tests for CFI, to track the progress of future -fsanitize-merge fixes for CFI.
2025-04-09 19:46:59 -07:00
Matheus Izvekov
98feb05825
[clang] fix unresolved dependent template specialization mangling (#135111)
This fixes a regression introduced in
https://github.com/llvm/llvm-project/pull/133610 which was reported here
https://github.com/llvm/llvm-project/pull/133610#issuecomment-2787332042

When mangling a dependent template specialization appearing within an
unresolved prefix, translate the dtst back to a dependent template name
including the prefix, and mangle following the nested unresolved-type
production.

There are no release notes, since this regression was never released.
2025-04-09 23:23:52 -03:00
Deric C.
747d4a952b
[DirectX] Implement UseNativeLowPrecision shader flag analysis (#134288)
Fixes #112267 

Implement the shader flag analysis to set the UseNativeLowPrecision DXIL
module flag.

The flag is only able to be set when the command-line flag
`-enable-16bit-types` is passed to clang-dxc, or equivalently
`-fnative-half-type` is passed to clang.
When the command-line flag is passed, a module metadata flag called
"dx.nativelowprec" is set to 1.
The DXILShaderFlags shader flags analysis checks that the module
metadata flag "dx.nativelowprec" is set to 1 and the DXIL Version is 1.2
or greater before setting the UseNativeLowPrecision DXIL module flag.
2025-04-09 18:14:23 -07:00
Matheus Izvekov
154507cf40
[clang] fix NestedNameSpecifier dependency calculation (#135067)
A NestedNameSpecifier of TypeSpec kind can be non-dependent even if its
prefix is dependent, when for example the prefix is an injected class
type but the type itself is a simple alias to a non-dependent type.

This issue was a bit hard to observe because if it is an alias to a
class type, then we (for some unknown reason) ignored that the NNS was
dependent in the first place, which wouldn't happen with an enum type.

This could have been a workaround for previous dependency bugs, and is
not relevant anymore for any of the test cases in the tree, so this
patch also removes that.

The other kinds of dependencies are still relevant. If the prefix
contains an unexpanded pack, then this NNS is still unexpanded, and
likewise for errors.

This fixes a regression reported here:
https://github.com/llvm/llvm-project/pull/133610#issuecomment-2787909829
which was introduced by https://github.com/llvm/llvm-project/pull/133610

There are no release notes since the regression was never released.
2025-04-09 19:44:40 -03:00
erichkeane
d47401e376 [OpenACC] Start enforcing 'device_type' clause values
Researching in prep of doing the implementation for lowering, I found
that the source of the valid identifiers list from flang is in the
frontend.  This patch adds the same list to the frontend, but does it as
a sema diagnostic, so we still parse it as an identifier/identifier-like
thing, but then diagnose it as invalid later.
2025-04-09 14:55:50 -07:00
Jan Svoboda
fe2eefc471
[clang][index] Handle undefined function-like macros in single file parse mode (#135054)
The single file parse mode is supposed to enter both branches of an
`#if` directive whenever the condition contains undefined identifiers.
This patch adds support for undefined function-like macros, where we
would previously emit an error that doesn't make sense from end-user
perspective.

(I discovered this while working on a very similar feature that parses
single module only and doesn't enter either `#if` branch when the
condition contains undefined identifiers.)
2025-04-09 13:00:17 -07:00
Kaitlin Peng
2ab2276ee0
[HLSL] Implement the lit intrinsic (#134171)
Closes #99135.

Tasks completed:
- Wrote implementation in `hlsl_intrinsics.h`/`hlsl_intrinsic_helpers.h`
- Added codegen tests to `clang/test/CodeGenHLSL/builtins/lit.hlsl`
2025-04-09 12:12:26 -07:00
Ryosuke Niwa
2c31403f4f
[alpha.webkit.UnretainedLambdaCapturesChecker] Add the support for protectedSelf (#132518)
This PR adds the support for treating capturing of "self" as safe if the
lambda simultaneously captures "protectedSelf", which is a RetainPtr of
"self".

This PR also fixes a bug that the checker wasn't generating a warning
when "self" is implicitly captured. Note when "self" is implicitly
captured, we use the lambda's getBeginLoc as a fallback source location.
2025-04-09 11:52:36 -07:00
metkarpoonam
3ef2bb6d0b
[HLSL] Implement the dst HLSL Function (#133828)
fixes: https://github.com/llvm/llvm-project/issues/99108
Implement dst algorithm in the hlsl_intrinsics.h and added test cases
for HLSL codegen and sema


- [x] implement dst algorithm in the hlsl_intrinsics.h

- [x] Add HLSL codegen tests to clang/test/CodeGenHLSL/builtins/dst.hlsl

- [x] Add sema tests to clang/test/SemaHLSL/BuiltIns/dst-errors.hlsl
2025-04-09 12:25:37 -06:00
erichkeane
505a7e7d1c [OpenACC][CIR] Support for init and shutdown lowering
These two are very simple.  they don't require any clauses and don't
have an associated statement, so they have very simple output.  This
patch implements them, but none of the associated clauses.
2025-04-09 11:22:35 -07:00
Erich Keane
fa273e1158
[OpenACC][CIR] Implement 'data' construct lowering (#135038)
This patch does the lowering of the OpenACC 'data' construct, which
requires getting the `default` clause (as `data` requires at least 1 of
a list of clauses, and this is the easiest one). The lowering of the
clauses appears to happen in 1 of 2 ways: a- as an operand. or b- as an
attribute.

This patch adds infrastructure to lower as an attribute, as that is how
'data' works.

In addition to that, it changes the OpenACCClauseVisitor a bit, which
previously just required that each of the derived classes have all of
the clauses covered. This patch modifies it so that the visitor directly
calls the derived class from its visitor function, which leaves the
base-class ones the ability to defer to a generic function. This was
previously like this because I had some use cases that I didn't end up
using, and the 'generic' function here seems much more useful.
2025-04-09 10:45:17 -07:00
Ryosuke Niwa
c8d49e9dd2
[alpha.webkit.RetainPtrCtorAdoptChecker] Recognize mutableCopy from literal as +1 (#132350)
This PR adds the support for recognizing the return value of copy /
mutableCopy as +1. isAllocInit and isOwned now traverses
PseudoObjectExpr to its last semantic expression.
2025-04-09 10:33:08 -07:00
Yingwei Zheng
c0480738cb
[Clang][CodeGen] Respect -fwrapv-pointer when emitting struct GEPs (#134269)
This patch turns off inbounds/nuw flags for member accesses when
`-fwrapv-pointer` is set.

Closes https://github.com/llvm/llvm-project/issues/132449.

It is required by https://github.com/llvm/llvm-project/pull/130734.
2025-04-10 00:48:18 +08:00
Aaron Ballman
543e5f5842
Fix crash with align_value diagnostic reporting (#135013)
We were passing the address of a local variable to a call to Diag()
which then tried to use the object after its lifetime ended, resulting
in crashes. We no longer pass the temporary object any longer.

Fixes #26612
2025-04-09 12:39:03 -04:00
Matt Arsenault
54cdc75857
clang/AMDGPU: Stop looking for hip.bc in device libs (#134801)
This has been an empty library since January 2023
2025-04-09 16:39:50 +02:00
Yaxun (Sam) Liu
d54c28b9c1
[HIP] use offload wrapper for non-device-only non-rdc (#132869)
Currently HIP still uses offload bundler for non-rdc mode for the new
offload driver.

This patch switches to use offload wrapper for non-device-only non-rdc
mode when new offload driver is enabled.

This makes the rdc and non-rdc compilation more consistent and speeds up
compilation since the offload wrapper supports parallel compilation for
different GPU arch's.

It is implemented by adding a linker wrapper action for each assemble
action of input file. Linker wrapper action differentiates this special
type of work vs normal linker wrapper work by the fle type. This type of
work results in object instead of image. The linker wrapper adds "-r"
for it and only includes the object file as input, not the host
libraries.

For device-only non-RDC mode, the new driver keeps the original
behavior.
2025-04-09 09:13:21 -04:00
Erich Keane
6e7c40b83d
[OpenACC][CIR] Initial patch to do OpenACC->IR lowering (#134936)
This patch adds some lowering code for Compute Constructs, plus the
infrastructure to someday do clauses. Doing this requires adding the
dialect to the CIRGenerator.

This patch does not however implement/correctly initialize lowering from
OpenACC-Dialect to anything lower however.
2025-04-09 06:05:31 -07:00
Andres-Salamanca
ccf22848da
[CIR] Add if statement support (#134333)
This patch adds support for if statements in the CIR dialect
Additionally, multiple RUN lines were introduced to improve codegen test
coverage
2025-04-08 17:50:53 -07:00
Cyndy Ishida
1365b5b1ad
[clang][DependencyScanning] Track dependencies from prebuilt modules to determine IsInStableDir (#132237)
When a module is being scanned, it can depend on modules that have
already been built from a pch dependency. When this happens, the pcm
files are reused for the module dependencies. When this is the case,
check if input files recorded from the PCMs come from the provided
stable directories transitively since the scanner will not have access
to the full set of file dependencies from prebuilt modules.
2025-04-08 15:48:25 -07:00
Andy Kaylor
1a1698b5dd
[CIR] Handle NullStmt (#134889)
The handling for NullStmt was going to an error saying the statement
handling wasn't implemented. It doesn't need any implementation. It is
sufficient for emitSimpleStmt to just return success for that statement
class. This change does that.
2025-04-08 13:55:12 -07:00
Alex MacLean
a6853cd9af
[NVPTX] Auto-Upgrade llvm.nvvm.atomic.load.{inc,dec}.32 (#134111)
These intrinsics can be upgrade to an atomicrmw instruction.
2025-04-08 13:44:11 -07:00
Oleksandr T.
9f463056e6
[Clang] add ext warning for missing return in 'main' for C89 mode (#134617)
Fixes #21650 

--- 

Clang currently inserts an implicit `return 0;` in `main()` when
compiling in `C89` mode, even though the `C89` standard doesn't require
this behavior. This patch changes that behavior by emitting a warning
instead of silently inserting the implicit return under `-pedantic`.
2025-04-08 23:21:53 +03:00
Aaron Ballman
9ba1a3fcb5
Reject invalid integer constants in unevaluated preprocessor operands (#134884)
Clang was previously accepting invalid code like:
```
  #if 1 ? 1 : 999999999999999999999
  #endif
```
because the integer constant (which is too large to fit into any
standard or extended integer type) was in an unevaluated branch of the
conditional operator. Similar invalid code involving || or && was also
accepted and is now rejected.

Fixes #134658
2025-04-08 14:25:59 -04:00
Matheus Izvekov
11fdea984d
[clang] NFC: remove trailing whitespaces from clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp 2025-04-08 15:10:33 -03:00
Andy Kaylor
4928093a21
[CIR] Upstream support for address of and dereference (#134317)
This adds support for handling the address of and dereference unary
operations in ClangIR code generation. This also adds handling for
nullptr and proper initialization via the NullToPointer cast.
2025-04-08 10:32:03 -07:00
Erich Keane
231aa3070d
[OpenACC][CIR] Basic infrastructure for OpenACC lowering (#134717)
This is the first of a few patches that will do infrastructure work to
enable the OpenACC lowering via the OpenACC dialect.

At the moment this just gets the various function calls that will end up
generating OpenACC, plus some tests to validate that we're doing the
diagnostics in OpenACC specific locations.

Additionally, this adds Stmt and Decl files for CIRGen.
2025-04-08 10:06:28 -07:00
Morris Hafner
441f87968d
[CIR] Upstream CmpOp (#133159)
This patch adds support for comparison operators with ClangIR, both
integral and floating point.

---------

Co-authored-by: Morris Hafner <mhafner@nvidia.com>
Co-authored-by: Henrich Lauko <xlauko@mail.muni.cz>
Co-authored-by: Andy Kaylor <akaylor@nvidia.com>
2025-04-08 09:53:54 -07:00
Matt Arsenault
3f38cd07d8 Revert "Inline: Propagate callsite nofpclass attribute"
This reverts commit b0cb672b9968eeee6eb022e98476957dbdf8e6e2.

Breaks bot
2025-04-08 23:15:00 +07:00
Matt Arsenault
b0cb672b99
Inline: Propagate callsite nofpclass attribute
(#134800)

Fixes #134070
2025-04-08 22:53:17 +07:00
Shilei Tian
f19c6f23ab
[Clang][AMDGPU] Improve error message when device libraries for COV6 are missing (#134745)
#130963 switches the default to COV6, which requires ROCm 6.3.
Currently, if the
device libraries for COV6 are not found, the error message is not very
helpful.
This PR provides a more informative error message in such cases.
2025-04-08 09:57:43 -04:00
Jonathan Thackray
204d8c0d58
[clang][llvm] Fix AArch64 MOP4{A/S} intrinsic tests (NFC) (#134746)
Fix some of the recently-added tests (PRs #127797, #128854, #129226 and
#129230) which were incorrectly defined.
2025-04-08 11:45:47 +01:00
Jakub Ficek
a5509d62a7
[clang] fp options fix for __builtin_convertvector (#134102)
Add missing CGFPOptionsRAII for fptoi and itofp cases
2025-04-08 11:36:48 +02:00
Aniket Lal
642481a428
[Clang][OpenCL][AMDGPU] Allow a kernel to call another kernel (#115821)
This feature is currently not supported in the compiler.
To facilitate this we emit a stub version of each kernel
function body with different name mangling scheme, and
replaces the respective kernel call-sites appropriately.
    
Fixes https://github.com/llvm/llvm-project/issues/60313
    
D120566 was an earlier attempt made to upstream a solution
for this issue.

---------

Co-authored-by: anikelal <anikelal@amd.com>
2025-04-08 10:29:30 +05:30
Timm Baeder
65cede26a6
[clang][bytecode] Fix emitting dtors of zero-sized arrays (#134672)
Desc->getNumElems() returning 0 made us underflow here.
2025-04-08 06:09:21 +02:00
Timm Baeder
fb9915a391
[clang][bytecode] Fix emitDestruction() for dummy descriptors (#134665)
This might happen if the referenced declaration is invalid and thus gets
a dummy descriptor. We ran into an assertion later on.
2025-04-08 06:00:35 +02:00
Timm Baeder
bdd087023f
[clang][bytecode] Fix various issues with multidimensional arrays (#134628)
This issue is very convoluted, but in essence, in the new version:

For a Pointer P that points to the root of a multidimensional, primitive
array:

`P.narrow()` does nothing.
`P.atIndex(0)` points `P[0]`
`P.atIndex(0).atIndex(0)` is the same as `P.atIndex(0)` (as before)
`P.atIndex(0).narrow().atIndex(0)` points to `P[0][0]`
`P.atIndex(0).narrow().narrow()` is the same as `P.atIndex(0).narrow()`.
2025-04-08 05:48:55 +02:00
Naveen Seth Hanig
ac42b083f1
[clang][modules] Guard against bad -fmodule-file mappings (#132059) (#133462)
Fix https://github.com/llvm/llvm-project/issues/132059.

Providing incorrect mappings via `-fmodule-file=<name>=<path/to/bmi>`
can crash the compiler when loading a module that imports an
incorrectly mapped module.

The crash occurs during AST body deserialization, when the compiler
attempts to resolve remappings using the `ModuleFile` from the
incorrectly mapped module's BMI file.
The cause is an invalid access into an incorrectly loaded
`ModuleFile`.

This commit fixes the issue by verifying the identity of the imported
module.
2025-04-08 11:02:57 +08:00
Matheus Izvekov
d057811655
[clang] fix diagnostic printing of expressions ignoring LangOpts (#134693)
Currently when printing a template argument of expression type, the
expression is converted immediately into a string to be sent to the
diagnostic engine, unsing a fake LangOpts.

This makes the expression printing look incorrect for the current
language, besides being inneficient, as we don't actually need to print
the expression if the diagnostic would be ignored.

This fixes a nastiness with the TemplateArgument constructor for
expressions being implicit, and all current users just passing an
expression to a diagnostic were implicitly going through the template
argument path.

The expressions are also being printed unquoted. This will be fixed in a
subsequent patch, as the test churn is much larger.
2025-04-07 23:19:32 -03:00
Matheus Izvekov
735f5b1cb4
[clang] fix DependentTemplateSpecializationType transform (#134748)
This changes the transform for DTST so it rebuilds the node if any of
the template arguments changed.

This fixes a regression reported here:
https://github.com/llvm/llvm-project/pull/133610#issuecomment-2784576267
which was introduced by https://github.com/llvm/llvm-project/pull/133610

There are no release notes since the regression was never released.
2025-04-07 21:25:37 -03:00
Sarah Spall
01bc672b8a
[HLSL] Desugar ConstantArrayType when calculating cbuffer field layout (#134683)
When calculating the layout for a cbuffer field, if that field is a
ConstantArrayType, desguar it before casting it to a ConstantArrayType.
Closes #134668

---------

Co-authored-by: Eli Friedman <efriedma@quicinc.com>
2025-04-07 15:25:47 -07:00
Drew Lewis
27c099bc84
Move CodeGen cuda.h to Inputs from include (#134706)
Mirrors the behavior of CodeGenCUDA directory and the location of other
.h files in CodeGen.
2025-04-07 12:23:10 -07:00
Farzon Lotfi
16c84c4475
[DirectX] Add target builtins (#134439)
- fixes #132303
- Moves dot2add from a language builtin to a target builtin.
-  Sets the scaffolding for Sema checks for DX builtins
-  Setup DirectX backend as able to have target builtins
- Adds a DX TargetBuiltins emitter in
`clang/lib/CodeGen/TargetBuiltins/DirectX.cpp`
2025-04-07 12:06:57 -04:00
Paul Kirth
268c065eab
[fatlto] Add coroutine passes when using FatLTO with ThinLTO (#134434)
When coroutines are used w/ both -ffat-lto-objects and -flto=thin,
the coroutine passes are not added to the optimization pipelines.
Ensure they are added before ModuleOptimization to generate a
working ELF object.

Fixes #134409.
2025-04-07 08:41:49 -07:00
Matheus Izvekov
954ccee5d5
[clang] fix partial ordering of NTTP packs (#134461)
This fixes partial ordering of pack expansions of NTTPs, by procedding
with the check using the pattern of the NTTP through the rules of the
non-pack case.

This also unifies almost all of the different versions of
FinishTemplateArgumentDeduction (except the function template case).
This makes sure they all follow the rules consistently, instantiating
the parameters and comparing those with the argument.

Fixes #132562
2025-04-07 12:30:51 -03:00
Jay Foad
e2fe78797f
[Clang] Use "syncscope" instead of "synchscope". NFC. (#134616)
This matches the spelling of the keyword in LLVM IR.
2025-04-07 13:32:36 +01:00
Aaron Ballman
b9ec68431b
Correctly diagnose incomplete arrays with static storage in C (#134374)
A file scope declaration without an initializer which is neither extern
nor thread_local is a tentative definition. If the declaration of an
identifier for an object is a tentative definition and has internal
linkage, the declared type shall not be an incomplete type.

Clang was previously failing to diagnose this in -pedantic mode.

Fixes #50661

---------

Co-authored-by: Mariya Podchishchaeva <mariya.podchishchaeva@intel.com>
2025-04-07 07:12:33 -04:00
Juan Manuel Martinez Caamaño
44e32fb802
[Clang][OpenCL] Fix wait_for_event argument address space with -fdeclare-opencl-builtins (#134598)
The pointer argument for `wait_for_event(int, event_t*)` should take the
default address space: generic if available, otherwise private.

Before this patch it would always be generic with
`-fdeclare-opencl-builtins`. This was inconsistent with the behavior
when opencl-c.h is included.
2025-04-07 10:44:37 +02:00
Balázs Kéri
31ef7acf12
[clang][analyzer] Fix a possible crash in CastSizeChecker (#134387) 2025-04-07 09:46:03 +02:00
Nikita Popov
87a4215ed1
[Clang] Always verify LLVM IR inputs (#134396)
We get a lot of issues that basically boil down to "I passed malformed
LLVM IR to clang and it crashed". Clang does not perform IR verification
by default in (non-assertion-enabled) release builds, and that's
sensible for IR that Clang itself produces, which is expected to always
be valid. However, if people pass in their own handwritten IR, we should
report if it is malformed, instead of crashing. We should also report it
in a way that does not produce a crash trace and ask for a bug report,
as currently happens in assertions-enabled builds. This aligns the
behavior with how opt/llc work.
2025-04-07 09:18:47 +02:00
Matheus Izvekov
6ce0fd7f74
[clang] NFC: clean trailing whitespaces in clang/test/CXX/drs/cwg15xx.cpp 2025-04-06 23:42:27 -03:00