114169 Commits

Author SHA1 Message Date
Yingwei Zheng
2257f51431
Revert "[Clang][CodeGen][UBSan] Add more precise attributes to recoverable ubsan handlers" (#135130)
Reverts llvm/llvm-project#130990

Breaks buildbot https://lab.llvm.org/buildbot/#/builders/186/builds/8072
2025-04-10 13:15:55 +08:00
Timm Baeder
02f923f8e4
[clang][bytecode] Classify function pointers as PT_Ptr (#135026)
The Pointer class already has the capability to be a function pointer,
but we still classifed function pointers as PT_FnPtr/FunctionPointer.
This means when converting from a Pointer to a FunctionPointer, we lost
the information of what the original Pointer pointed to.
2025-04-10 06:40:54 +02:00
Timm Baeder
98ea512f72
[clang][bytecode] Clear inactive union fields when copying (#134982)
When copying unions, we need to only copy the active field of the source
union, which we were already doing. However, we also need to zero out
the (now) inactive fields, so we don't end up with dangling pointers in
those inactive fields.
2025-04-10 06:12:00 +02:00
Yingwei Zheng
0283bb3afc
[Clang][CodeGen][UBSan] Add more precise attributes to recoverable ubsan handlers (#130990)
This patch adds `memory(argmem: read, inaccessiblemem: readwrite)
mustprogress` to **recoverable** ubsan handlers in order to unblock some
memory/loop optimizations. It provides an average of 3% performance
improvement on llvm-test-suite (except for 49 test failures due to ubsan
diagnostics).

Closes https://github.com/llvm/llvm-project/issues/130093.
2025-04-10 11:09:45 +08:00
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
Owen Pan
f344838389
[clang-format] Keep the space between not and a unary operator (#135035)
Also keep the space between `not` and `::`.

Based on the
[documentation](https://releases.llvm.org/20.1.0/tools/clang/docs/ClangFormatStyleOptions.html#spaceafterlogicalnot),
it can be argued that SpaceAfterLogicalNot doesn't cover the alternative
operator `not`.

Closes #125465
2025-04-09 17:52:12 -07:00
Owen Pan
75cbb1f0fa
[clang-format][NFC] Add FormatToken::is(tok::ObjCKeywordKind) (#134973)
This allows simplification of code that checks if a token is an
Objective-C keyword.

Also, delete the following in
UnwrappedLineParser::parseStructuralElement():
- an else-after-break in the tok::at case
- the copypasted code in the tok::objc_autoreleasepool case
2025-04-09 17:49:26 -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
Andy Kaylor
58b91d10a4
[CIR][NFC] Upstream LValueBaseInfo handling (#134928)
Previous implementations that used the cir::LValue class omitted hanling
of the LValueBaseInfo class, which tracks information about the basis
for the LValue's alignment. As more code was upstreamed from the
incubator, we were accumulating technical debt by adding more places
where this wasn't handled correctly. This change puts the interfaces in
place to track this information.

The information being tracked isn't used yet, so no functional change is
intended. The tracking is being added now because it will become more
difficult to add it as more features are implemented.
2025-04-09 15:27:50 -07: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
Andy Kaylor
f75dce43ea
[CIR][NFC] Fix an unused variable warning (#135046)
This fixes a warning where a variable assigned in a 'if' statement
wasn't referenced again.
2025-04-09 14:27:09 -07:00
Shafik Yaghmour
12b1ed213e
[Clang] Add non static data member initializer for BindingDecl member Decomp (#134969)
Static analysis flagged BindingDecl Decomp member as not being
initialized during construction or by any other member function.

Fix is add a default initializer for it like the other member Binding.
2025-04-09 13:31:52 -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
Nick Sarnie
68ee56d150
[clang][OpenMP][SPIR-V] Fix addrspace of global constants (#134399)
SPIR-V has strict address space rules, constant globals cannot be in the
default address space.

The OMPIRBuilder change was required for lit tests to pass, we were
missing an addrspacecast.

---------

Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-04-09 15:41:53 +00: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
Timm Baeder
78c86b38b0
[clang][bytecode][NFC] Avoid implicit integer conversion (#134983)
See discussion in https://github.com/llvm/llvm-project/pull/134672
2025-04-09 13:44:24 +02:00
Liao Chunyu
43bb6bac2f [clang] Fix GCC -Wparentheses warning. NFC.
Without this gcc warned like:
clang/lib/Sema/SemaExprCXX.cpp:4656:74: warning: suggest parentheses around ‘&&’ within ‘||’ [-Wparentheses]
 4655 |              From->isNullPointerConstant(Context,
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 4656 |                                          Expr::NPC_ValueDependentIsNull) &&
      |                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
 4657 |                  "Expr must be null pointer constant!");
      |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2025-04-08 23:42:27 -04: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
Jann
8d90a54153
[clang] Add comment about misleading alloc_size argument names (#134899)
Attr.td names the first alloc_size argument "ElemSizeParam" and the
second optional argument "NumElemsParam"; but the semantics of how the
two-argument version is used in practice is the opposite of that.

glibc declares calloc() like this, so the second alloc_size argument is
the element size:
```
extern void *calloc (size_t __nmemb, size_t __size)
__THROW __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __wur;
```

The Linux kernel declares array allocation functions like
`kmalloc_array_noprof()` the same way.

Add a comment explaining that the names used inside clang are
misleading.
2025-04-08 14:18:24 -06: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
Sirraide
6c74fe9087
[Clang] [NFC] Tablegen component diags headers (#134777)
The component diagnostic headers (i.e. `DiagnosticAST.h` and friends)
all follow the same format, and there’s enough of them (and in them) to
where updating all of them has become rather tedious (at least it was
for me while working on #132348), so this patch instead generates all of
them (or rather their contents) via Tablegen.

Also, it seems that `%enum_select` currently wouldn’t work in
`DiagnosticCommonKinds.td` because the infrastructure for that was
missing from `DiagnosticIDs.h`; this patch should fix that as well.
2025-04-08 17:21:45 +02: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
Joseph Huber
79cb6f05da
[Clang] Unify 'nvptx-arch' and 'amdgpu-arch' into 'offload-arch' (#134713)
Summary:
These two tools do the same thing, we should unify them into a single
tool. We create symlinks for backward compatiblity and provide a way to
get the old vendor specific behavior with `--amdgpu-only` and
`--nvptx-only`.
2025-04-08 07:27:12 -05: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
Pedro Lobo
bb5006169f
[CodeGen] Change placeholder from undef to poison (#134731)
Fill default values of a map with `poison` instead of `undef`. There
should be no functional difference as the default values are overridden
later.
2025-04-08 09:50:48 +01:00
Orlando Cazalet-Hyams
308654608c [Clang][NFC] Move some static functions into CodeGenFunction (#134634)
Patches in the Key Instructions (KeyInstr) stack need to access CGF in these
functions. 2 CGF fields are passed to these functions already; at this point it
felt natural to promote them to CGF methods.
2025-04-08 08:44:10 +01: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