5984 Commits

Author SHA1 Message Date
Owen Pan
da283b54d9 Revert "[clang-format] Fix an off-by-1 bug with -length option (#143302)"
This reverts commit 1fae5918b3d6fbed8ce6d8a2edf31bdf304ca8db because it may
break VSCode.

Closes #146036
2025-07-14 22:42:12 -07:00
Cyndy Ishida
15c3793cdf
[clang][scan-deps] Report a scanned TU's visible modules (#147969)
Clients of the dependency scanning service may need to add dependencies
based on the visibility of importing modules, for example, when
determining whether a Swift overlay dependency should be brought in
based on whether there's a corresponding **visible** clang module for
it.
This patch introduces a new field `VisibleModules` that contains all the
visible top-level modules in a given TU.
Because visibility is determined by which headers or (sub)modules were
imported, and not top-level module dependencies, the scanner now
performs a separate DFS starting from what was directly imported for
this computation.

In my local performance testing, there was no observable performance
impact.

resolves: rdar://151416358

---------

Co-authored-by: Jan Svoboda <jan@svoboda.ai>
2025-07-11 09:33:55 -07:00
Joseph Huber
535d6917ec
[Clang] Extract offloading code from static libs with 'offload-arch=' (#147823)
Summary:
The semantics of static libraries only extract stuff that's used. We
somewhat extend this behavior with the linker wrapper only doing this to
fat binaries that match any found architectures. However, this has some
unfortunate effects when the user uses static libraries.

This is somewhat of a hack, but we now assume that if the user specified
`--offload-arch=` on the link job, they *definitely* want that
architecture to be used if it exists. This patch just forces extraction
of those libraries which resolves an issue observed with some customers.

The old behavior will still be present if the user does `--offload-link`
with no offloading architecture present, and for the vast, vast majority
of cases this will change nothing.

Fixes: https://github.com/llvm/llvm-project/issues/147788
2025-07-11 10:26:24 -05:00
darkbuck
378e9bb7e0
[cir-translate] Fix crash issue where the data layout string is missing (#147209)
- Targets like 'aarch64' or 'arm' only populate the data layout string
after the constructor. Need to call 'CreateTargetInfo' to setup them
properly.
2025-07-09 23:26:15 -04:00
Tomohiro Kashiwada
9c4e2dcb56
[libclang][Cygwin] Use LLVM_EXPORTED_SYMBOL_FILE (*.def file) for Cygwin (#147278)
This is not mandatory but recommended for completeness and consistency
with MinGW.
2025-07-09 23:57:12 +03:00
Yaxun (Sam) Liu
beea2a9414
[Clang] Respect MS layout attributes during CUDA/HIP device compilation (#146620)
This patch fixes an issue where Microsoft-specific layout attributes,
such as __declspec(empty_bases), were ignored during CUDA/HIP device
compilation on a Windows host. This caused a critical memory layout
mismatch between host and device objects, breaking libraries that rely
on these attributes for ABI compatibility.

The fix introduces a centralized hasMicrosoftRecordLayout() check within
the TargetInfo class. This check is aware of the auxiliary (host) target
and is set during TargetInfo::adjust if the host uses a Microsoft ABI.

The empty_bases, layout_version, and msvc::no_unique_address attributes
now use this centralized flag, ensuring device code respects them and
maintains layout consistency with the host.

Fixes: https://github.com/llvm/llvm-project/issues/146047
2025-07-09 08:53:10 -04:00
Haojian Wu
b7c4ac2db4 NFC, use structured binding to simplify the code. 2025-07-07 17:07:37 +02:00
Kazu Hirata
a244907922
[clang] Use range-based for loops (NFC) (#146811)
Note that LLVM Coding Standards discourages std::for_each and
llvm::for_each unless the callable object already exists.
2025-07-03 08:36:03 -07:00
Paddy McDonald
4db8ce7251
[clang-fuzzer] Fix latent race condition in build (#146119)
Add explicit dependency for gen_vt to the CMakeLists.txt for
clang/tools/clang-fuzzer/handle-llvm/handle_llvm.cpp to prevent race
condition on generation of llvm/CodeGen/GenVT.inc This explicit
dependency was added in other CMakeLists.txt when the tablegen was added
for GenVT.inc file in https://reviews.llvm.org/D148770, but not for
handle-llvm

A similar fix was made in
https://github.com/llvm/llvm-project/pull/109306

rdar://151325382
2025-07-02 07:53:33 -07:00
SahilPatidar
3f531552e6
[REAPPLY][Clang-Repl] Add support for out-of-process execution. #110418 (#144064)
This PR introduces out-of-process (OOP) execution support for
Clang-Repl. With this enhancement, two new flags, oop-executor and
oop-executor-connect, are added to the Clang-Repl interface. These flags
enable the launch of an external executor (llvm-jitlink-executor), which
handles code execution in a separate process.
2025-06-28 08:42:59 +03:00
Haojian Wu
0b6ddb02ef
[clang] NFC: Add alias for std::pair<FileID, unsigned> used in SourceLocation (#145711)
Introduce a type alias for the commonly used `std::pair<FileID,
unsigned>` to improve code readability, and make it easier for future
updates (64-bit source locations).
2025-06-26 14:12:51 +02:00
wieDasDing
d76fdf7f53
[clang-c] introduce queries on GCC-style inline assembly statements (#143424)
[Discourse
link](https://discourse.llvm.org/t/a-small-proposal-for-extraction-of-inline-assembly-block-information/86658)

We strive for exposing such information using existing stable ABIs. In
doing so, queries are limited to what the original source holds or the
LLVM IR `asm` block would expose in connection with attributes that the
queries are concerned.

These APIs opens new opportunities for `rust-bindgen` to translate
inline assemblies in reasonably cases into Rust inline assembly blocks,
which would further aid better interoperability with other existing
code.

---------

Signed-off-by: Xiangfei Ding <dingxiangfei2009@protonmail.ch>
2025-06-25 10:08:56 -04:00
Naveen Seth Hanig
52fbefb281
[clang][clang-scan-deps] Add named modules to format 'experimental-full' (#145221) 2025-06-24 16:21:19 -07:00
Qinkun Bao
43d042b350
Revert "[clang][scan-deps] Add option to disable caching stat failures" (#145528)
Reverts llvm/llvm-project#144000

First buildbot failure:
https://lab.llvm.org/buildbot/#/builders/164/builds/11064
2025-06-24 11:12:05 -04:00
Miguel Cárdenas
e80acd4fae
[clang][nvlink-wrapper] Add support for opt-remarks command line options (#145365)
## Problem
When using `-fsave-optimization-record` with offloading, the Clang
driver passes optimization record options like
`-plugin-opt=opt-remarks-format=yaml` to `clang-nvlink-wrapper`.
However, the wrapper doesn't recognize these options, causing
compilation to fail.


## Solution
This patch adds support for the standard optimization record command
line options to `clang-nvlink-wrapper`, matching the interface provided
by LLD and gold-plugin as documented in the [LLVM Remarks
documentation](https://llvm.org/docs/Remarks.html).

## Changes
- **NVLinkOpts.td**: Added definitions for `opt-remarks-filename`,
`opt-remarks-format`, `opt-remarks-filter`, and
`opt-remarks-with-hotness` options
- **NVLinkOpts.td**: Added `plugin-opt=` aliases for these options to
match what the Clang driver sends
- **ClangNVLinkWrapper.cpp**: Updated `createLTO()` to use command line
arguments when available, falling back to existing global variables

## Testing
The fix allows `-fsave-optimization-record` to work correctly with
offloading, generating optimization records during the LTO phase without
throwing unknown argument errors.

This change maintains backward compatibility and follows the existing
pattern used by other LLVM linkers.
2025-06-23 13:15:04 -05:00
Michael Spencer
6110dead89
[clang][scan-deps] Add option to disable caching stat failures (#144000)
While the source code isn't supposed to change during a build, in some
environments it does. This adds an option that disables caching of stat
failures, meaning that source files can be added to the build during
scanning.

This adds a `-no-cache-negative-stats` option to clang-scan-deps to
enable this behavior. There are no tests for clang-scan-deps as there's
no reliable way to do so from it. A unit test has been added that
modifies the filesystem between scans to test it.
2025-06-20 13:28:05 -07:00
Joseph Huber
6fb36db481
[LinkerWrapper] Fix 'save-temps' when targeting SPIR-V (#144605)
Summary:
The logic here is flawed, it was only intended to apply to the CPU case
where we use the linker passed in on the command line. This was falsely
applying to SPIR-V which caused issues.
2025-06-17 16:16:37 -05:00
Aaron Ballman
9eef4d1c5f
Remove delayed typo expressions (#143423)
This removes the delayed typo correction functionality from Clang
(regular typo correction still remains) due to fragility of the
solution.

An RFC was posted here:
https://discourse.llvm.org/t/rfc-removing-support-for-delayed-typo-correction/86631
and while that RFC was asking for folks to consider stepping up to be
maintainers, and we did have a few new contributors show some interest,
experiments show that it's likely worth it to remove this functionality
entirely and focus efforts on improving regular typo correction.

This removal fixes ~20 open issues (quite possibly more), improves
compile time performance by roughly .3-.4%
(https://llvm-compile-time-tracker.com/?config=Overview&stat=instructions%3Au&remote=AaronBallman&sortBy=date),
and does not appear to regress diagnostic behavior in a way we wouldn't
find acceptable.

Fixes #142457
Fixes #139913
Fixes #138850
Fixes #137867
Fixes #137860
Fixes #107840
Fixes #93308
Fixes #69470
Fixes #59391
Fixes #58172
Fixes #46215
Fixes #45915
Fixes #45891
Fixes #44490
Fixes #36703
Fixes #32903
Fixes #23312
Fixes #69874
2025-06-13 06:45:40 -04:00
Owen Pan
1fae5918b3
[clang-format] Fix an off-by-1 bug with -length option (#143302)
Also validate the argument value.

Fixes #56245
2025-06-13 00:45:52 -07:00
Yaxun (Sam) Liu
7232c07eb9 Reland [HIP] use offload wrapper for non-device-only non-rdc (#143964)
Fixed a typo:

-  auto Section = (Prefix + "llvm_offload_entries").str();
+  auto Section = (Prefix + "_offload_entries").str();

which broke buildbot e.g.

https://lab.llvm.org/buildbot/#/builders/208/builds/1948
2025-06-12 21:41:41 -04:00
Yaxun (Sam) Liu
8890706db6 Revert "Reland [HIP] use offload wrapper for non-device-only non-rdc (#132869) (#143964)"
This reverts commit 22f9b4aa1dad597d908be77be1e10ba4c77330ce.
2025-06-12 21:33:05 -04:00
Yaxun (Sam) Liu
22f9b4aa1d
Reland [HIP] use offload wrapper for non-device-only non-rdc (#132869) (#143964)
Fixed two issues:

1. assertion with -flto. the linker wrapper action is missing for
wrapping the device binary. Added it for -flto.

2. when there are two HIP files, the kernels in the second file were not
found. This is because the -r option of linker wrapper assumes offload
entries section of HIP to be hip_offloading_entries but it is actually
llvm_offload_entries, causing the offload entries sections not made
unique for different object files. Fixed and tested working for both
-fgpu-rdc and -fno-gpu-rdc case with and without -r
2025-06-12 20:08:55 -04:00
Owen Pan
f6eaa2b00c
Reland "[clang-format][NFC] Clean up fillRanges() in ClangFormat.cpp" (#143477)
Reapply https://github.com/llvm/llvm-project/pull/143236 and fix the bug
reported in
https://github.com/llvm/llvm-project/pull/143236#issuecomment-2957102180.
2025-06-12 08:29:49 -07:00
Jorge Gorbe Moya
3c02150f02 Revert "[clang-format][NFC] Clean up fillRanges() in ClangFormat.cpp (#143236)"
This reverts commit 897ccddcc30cacdfe04ddd622986b50ec963eabc. It
introduced a bug when formatting multiple files in one go. When a
shorter file is passed after a longer one, a stale length from the
previous file seems to be used, triggering an "invalid length (...) is
outside the file" error.
2025-06-09 14:42:32 -07:00
Owen Pan
897ccddcc3
[clang-format][NFC] Clean up fillRanges() in ClangFormat.cpp (#143236) 2025-06-07 20:59:53 -07:00
Kazu Hirata
6ab6321d03
[clang] Use range-based for loops (NFC) (#143153)
Note that use of llvm::for_each is discouraged unless we have functors
readily available.
2025-06-06 09:16:41 -07:00
Tomohiro Kashiwada
b07a6da7cb
[scan-build][Windows] Fix driver name transformation in scan-build (#143135)
On Windows system, scan-build resolves clang++ driver name as
"clang-{ver}++.exe" from "clang-{ver}.exe" but should transform to
"clang++.exe".
2025-06-06 15:21:13 +02:00
Andres-Salamanca
dc9b8fe3b7
[CIR ] Add DLTI dialect support to module attributes (#142241)
This PR adds support for the DLTI dialect by attaching it to the module
attributes and introduces a utility function to determine if the target
is big-endian, which is required for
https://github.com/llvm/llvm-project/pull/142041. Some tests were
updated because we now use `mlir::translateDataLayout`, which "updates"
the `DataLayout` where the alignment for `long` is 8 instead of the
previously 4. This updated is consistent with Incubator.
2025-06-05 09:42:01 -05:00
Nick Sarnie
3b9ebe9201
[clang] Simplify device kernel attributes (#137882)
We have multiple different attributes in clang representing device
kernels for specific targets/languages. Refactor them into one attribute
with different spellings to make it more easily scalable for new
languages/targets.

---------

Signed-off-by: Sarnie, Nick <nick.sarnie@intel.com>
2025-06-05 14:15:38 +00:00
Kazu Hirata
ddc8b5419a
[tools] Remove unused local variables (NFC) (#142880) 2025-06-04 22:42:59 -07:00
Abid Qadeer
de38c4eaf5
[flang][driver] Introduce FCC_OVERRIDE_OPTIONS. (#140556)
This PR add functionality to change `flang` command line using
environment variable `FCC_OVERRIDE_OPTIONS`. It is quite similar to what
`CCC_OVERRIDE_OPTIONS` does for clang.

The `FCC_OVERRIDE_OPTIONS` seemed like the most obvious name to me but I
am open to other ideas. The `applyOverrideOptions` now takes an extra
argument that is the name of the environment variable. Previously
`CCC_OVERRIDE_OPTIONS` was hardcoded.
2025-06-02 11:37:26 +01:00
Qiongsi Wu
8f4fd86403
Revert "[clang][Dependency Scanning] Report What a Module Exports during Scanning (#137421)" (#140820)
This reverts commit ea1bfbf3f6399b7d2d840722f0e87542d00f6a35.

The commit did not solve the fundamental issue we need to handle and is
no longer necessary.

rdar://144794793
2025-05-29 11:11:31 -07:00
David Green
3a42cbd47d [AArch64] Rename AArch64SVEACLETypes.def and add base SVE_TYPE. 2025-05-28 12:26:54 +01: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
Robin Caloudis
b56b4e02b5
Fix tests of lookup table generator (#139463)
## Why
In
https://github.com/llvm/llvm-project/pull/113612/files#diff-ada12e18f3e902b41b6989b46455c4e32656276e59907026e2464cf57d10d583,
the parameter `qual_name` was introduced. However, the tests have not
been adopted accordingly and hence cannot be executed.

## What
Fix the execution of tests by providing the missing argument.
2025-05-27 13:45:11 +02:00
Jan Svoboda
13e1a2cb22 Reapply "[clang] Remove intrusive reference count from DiagnosticOptions (#139584)"
This reverts commit e2a885537f11f8d9ced1c80c2c90069ab5adeb1d. Build failures were fixed right away and reverting the original commit without the fixes breaks the build again.
2025-05-22 12:52:03 -07:00
Kazu Hirata
e2a885537f Revert "[clang] Remove intrusive reference count from DiagnosticOptions (#139584)"
This reverts commit 9e306ad4600c4d3392c194a8be88919ee758425c.

Multiple builtbot failures have been reported:
https://github.com/llvm/llvm-project/pull/139584
2025-05-22 12:44:20 -07:00
Jan Svoboda
d25f95fdbc [clang] Fix handle_cxx.cpp after 9e306ad4 2025-05-22 12:40:03 -07:00
Jan Svoboda
9e306ad460
[clang] Remove intrusive reference count from DiagnosticOptions (#139584)
The `DiagnosticOptions` class is currently intrusively
reference-counted, which makes reasoning about its lifetime very
difficult in some cases. For example, `CompilerInvocation` owns the
`DiagnosticOptions` instance (wrapped in `llvm::IntrusiveRefCntPtr`) and
only exposes an accessor returning `DiagnosticOptions &`. One would
think this gives `CompilerInvocation` exclusive ownership of the object,
but that's not the case:

```c++
void shareOwnership(CompilerInvocation &CI) {
  llvm::IntrusiveRefCntPtr<DiagnosticOptions> CoOwner = &CI.getDiagnosticOptions();
  // ...
}
```

This is a perfectly valid pattern that is being actually used in the
codebase.

I would like to ensure the ownership of `DiagnosticOptions` by
`CompilerInvocation` is guaranteed to be exclusive. This can be
leveraged for a copy-on-write optimization later on. This PR changes
usages of `DiagnosticOptions` across `clang`, `clang-tools-extra` and
`lldb` to not be intrusively reference-counted.
2025-05-22 12:33:52 -07:00
Owen Pan
0dfdf7efbf
[clang-format] Handle raw string literals containing JSON code (#140666)
Fix #65400
2025-05-20 19:15:57 -07:00
Owen Pan
5ddcd765db
[clang-format][NFC] Upgrade SortIncludes option to a struct (#140497)
This allows adding other suboptions e.g. IgnoreExtension in #137840.
2025-05-19 01:32:17 -07:00
Brad Smith
fbb8a0c9c8
[CMake] Add a linker test for -Bsymbolic-functions to AddLLVM (#79539)
Add a linker test for -Bsymbolic-functions to AddLLVM and remove
the illumos hardcoded bits for its handling. OpenBSD also has a
local patch for linking with the old BFD linker on mips64 and
sparc64.
2025-05-18 21:20:32 -04:00
Kazu Hirata
0fc9cd13a6
[clang] Use llvm::unique (NFC) (#140459) 2025-05-18 09:47:06 -07:00
Naveen Seth Hanig
636628d8fd
[clang] Enforce 1-based indexing for command line source locations (#139457)
Fixes #139375

Clang expects command line source locations to be provided using 1-based
indexing.
Currently, Clang does not reject zero as invalid argument for column or
line number, which can cause Clang to crash.

This commit extends validation in `ParsedSourceLocation::FromString` to
only accept (unsinged) non-zero integers.
2025-05-15 09:36:28 -04:00
Jan Svoboda
989a40cba8
[clang][modules] Invalidate module cache when SDKSettings.json changes (#139751)
This PR adds the `%sdk/SDKSettings.json` file to the PCM input file
table, so that the PCM gets invalidated when the file changes. This is
necessary for availability checks to work correctly.
2025-05-13 14:00:31 -07:00
Justin Cai
dcd5e476d9
[clang-sycl-linker] Add AOT compilation support for Intel GPUs/CPUs (#133194)
This PR adds support for AOT compilation for Intel CPUs and GPUs in
clang-sycl-linker. When no `-arch` is passed to `clang-sycl-linker`, the
output of the tool will be the resulting linked SPIR-V bytecode. If the
`-arch` is passed to `clang-sycl-linker` and the value is a supported
Intel CPU or GPU, then SPIR-V bytecode is then further passed to the
respective tool (`opencl-aot` or `ocloc`) for AOT compilation.
2025-05-13 10:39:44 -05:00
Finn Plummer
dd3d7cfe2e
[HLSL][RootSignature] Define and integrate rootsig clang attr and decl (#137690)
- Defines a new declaration node `HLSLRootSignature` in `DeclNodes.td`
that will consist of a `TrailingObjects` of the in-memory construction
of the root signature, namely an array of `hlsl::rootsig::RootElement`s

- Defines a new clang attr `RootSignature` which simply holds an
identifier to a corresponding root signature declaration as above

- Integrate the `HLSLRootSignatureParser` to construct the decl node in
`ParseMicrosoftAttributes` and then attach the parsed attr with an
identifier to the entry point function declaration.

- Defines the various required declaration methods

- Add testing that the declaration and reference attr are created
correctly, and some syntactical error tests.

It was previously proposed that we could have the root elements
reference be stored directly as an additional member of the attribute
and to not have a separate root signature decl. In contrast, by defining
them separately as this change proposes, we will allow a unique root
signature to have its own declaration in the AST tree. This allows us to
only construct a single root signature for all duplicate root signature
attributes. Having it located directly as a declaration might also prove
advantageous when we consider root signature libraries.

Resolves https://github.com/llvm/llvm-project/issues/119011
2025-05-12 09:59:46 -07:00
Kazu Hirata
f5f8ddc166
[clang] Remove redundant calls to std::unique_ptr<T>::get (NFC) (#139399) 2025-05-10 12:11:17 -07:00
Cyndy Ishida
823b1a5822
[clang-installapi] Store dylib attributes in the order they are passed on the command line. (#139087)
With the introduction of tbd-v5 holding rpaths, the order in which those
attributes are passed to `clang-installapi` must be represented in tbd
files. Previously, all dylib attributes were stored in a
non-deterministic `StringMap`. Instead, hold them in a custom collection
with an underlying vector to continue supporting searching by attribute.
This makes the order of all diagnostics related to load command
comparisons stable.

This approach resolves errors when building with reverse-iteration.
2025-05-08 21:15:10 -07:00
Rahul Joshi
7245e21e89
[NFC][Support] Add llvm::uninitialized_copy (#138174)
Add `llvm::uninitialized_copy` that accepts a range instead of start/end
iterator for the source of the copy.
2025-05-07 17:37:38 -07:00