5949 Commits

Author SHA1 Message Date
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
Morris Hafner
2eb6545b3e
[CIR] Add cir-simplify pass (#138317)
This patch adds the cir-simplify pass for SelectOp and TernaryOp. It
also adds the SelectOp folder and adds the constant materializer for the
CIR dialect.
2025-05-07 18:50:39 +02:00
Alexey Bader
3f1267e1b3
[NFC][clang-offload-bundler] Simplify main function (#138555)
Applied "no else after return" rule from the LLVM's Coding Standards
https://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return
2025-05-05 20:01:42 -07:00
Arthur Eubanks
b06a014f01
[cmake] Reenable libclang.dll when LLVM_ENABLE_PIC (#138343)
This was disabled for Windows/Mingw in #138343, but it's actually
linkable and is being used by some people.
2025-05-05 13:37:06 +02:00
Jugst3r
93680b5242
Remove duplicate API (#132776)
And adapt the existing code to account for the comments made when
introducing the duplicate API.

Note that this introduces a retro-incompatibility with LLVM 19.

cc @sebastianpoeplau
2025-05-05 07:06:02 -04:00
Nikita Popov
b492ec5899
[ErrorHandling] Add reportFatalInternalError + reportFatalUsageError (NFC) (#138251)
This implements the result of the discussion at:

https://discourse.llvm.org/t/rfc-report-fatal-error-and-the-default-value-of-gencrashdialog/73587

There are two different use cases for report_fatal_error, so replace it
with two functions reportFatalInternalError() and
reportFatalUsageError(). The former indicates a bug in LLVM and
generates a crash dialog. The latter does not. The names have been
suggested by rnk and people seemed to like them.

This replaces a lot of the usages that passed an explicit value for
GenCrashDiag. I did not bulk replace remaining report_fatal_error usage
-- they probably require case by case review for which function to use.
2025-05-05 12:10:03 +02:00
Björn Pettersson
0054ab4dc8
[NFC] Fix c++ style comment in c file (#138244)
Fix "C++ style comments are not allowed in ISO C90" warnings in some C
files.
2025-05-05 09:15:32 +02:00
Kazu Hirata
aafbddee80
[clang-linker-wrapper] Remove unused local variables (NFC) (#138480) 2025-05-04 20:36:07 -07:00
Kazu Hirata
4c587f549c
[clang] Use *(Set|Map)::contains (NFC) (#138464) 2025-05-04 11:56:31 -07:00
Kazu Hirata
f002f300c5
[clang] Remove unused local variables (NFC) (#138453) 2025-05-04 10:51:40 -07:00
jeremyd2019
74d921c01a
[Clang][Cygwin] don't use -Bsymbolic-functions (#138217)
GNU ld seems to ignore this option, but LLD treats the presence of this
unknown option as an error.
2025-05-04 00:33:54 +03:00
Mateusz Mikuła
abe93fe7c8
[Clang][Cygwin] Remove erroneous _WIN32 define and clean up Cygwin code (#138120)
With this define present and building with Clang the build fails:
```
In file included from /h/projects/llvm-project/clang/tools/libclang/CIndexer.cpp:36:
In file included from /usr/include/w32api/windows.h:69:
In file included from /usr/include/w32api/windef.h:9:
In file included from /usr/include/w32api/minwindef.h:163:
In file included from /usr/include/w32api/winnt.h:1658:
In file included from /usr/lib/clang/20/include/x86intrin.h:15:
In file included from /usr/lib/clang/20/include/immintrin.h:24:
In file included from /usr/lib/clang/20/include/xmmintrin.h:31:
/usr/lib/clang/20/include/mm_malloc.h:45:22: error: use of undeclared identifier '_aligned_malloc'; did you mean 'aligned_alloc'?
   45 |   __mallocedMemory = _aligned_malloc(__size, __align);
      |                      ^
```
Removing it allows the build with Clang to succeed and doesn't break
build with GCC.

The "#define _WIN32" was originally "#define LLVM_ON_WIN32", but this
was changed into a plain "#define _WIN32" (which not necessarily is
something that is supported to do) in
1865df49960e34cc90d0083b0e0cd4771c0feb35 as part of a larger
refactoring.

This cygwin specific code isn't needed for converting paths anymore, as
dladdr takes care of it. (dladdr was added to cygwin in 2017, according
to the tags in version 2.8.0.)

Co-authored-by: Jeremy Drake <github@jdrake.com>
2025-05-02 11:07:15 +03:00
Mateusz Mikuła
9bc20fbbad
[Clang][Cygwin] Disable shared libs on Cygwin by default (#138119)
This change follows MinGW decisions, otherwise build with GCC fail with:
```
FAILED: bin/msys-clang-cpp-21.0git.dll lib/libclang-cpp.dll.a
...
/usr/lib/gcc/x86_64-pc-msys/13.3.0/../../../../x86_64-pc-msys/bin/ld: error: export ordinal too large: 92250
```

Co-authored-by: jeremyd2019 <github@jdrake.com>
2025-05-02 11:02:11 +03:00
Jan Svoboda
b69dcb8734
[clang][frontend] Require invocation to construct CompilerInstance (#137668)
This PR makes it so that `CompilerInvocation` needs to be provided to
`CompilerInstance` on construction. There are a couple of benefits in my
view:
* Making it impossible to mis-use some `CompilerInstance` APIs. For
example there are cases, where `createDiagnostics()` was called before
`setInvocation()`, causing the `DiagnosticEngine` to use the
default-constructed `DiagnosticOptions` instead of the intended ones.
* This shrinks `CompilerInstance`'s state space.
* This makes it possible to access **the** invocation in
`CompilerInstance`'s constructor (to be used in a follow-up).
2025-05-01 07:31:30 -07:00
Alan Zhao
69327c16d1
[clang] Make -ftime-report and -ftime-report-json honor -info-output-file (#138035)
This way, the output of `-ftime-report` and `-ftime-report-json` can be
redirected to a specific file rather than just stderr.
2025-04-30 14:48:17 -07:00
Qiongsi Wu
ea1bfbf3f6
[clang][Dependency Scanning] Report What a Module Exports during Scanning (#137421)
We would like to report, for a module, which direct dependencies it
exports during dependency scanning. This PR implements this reporting by
augmenting `ModuleDep`'s `ClangModuleDeps` variable. `ClangModuleDeps`
now contains instances of `DepInfo`, which is made of a `ModuleID` and a
boolean flag that indicates if a particular dependence is exported.

rdar://144794793
2025-04-30 14:08:02 -07:00
Alan Zhao
4a6c81dc0e
[clang] Implement JSON formatted -ftime-report (#137737)
This patch adds a new flag, -ftime-report-json, which outputs the same
information as -ftime-report but as JSON instead of -ftime-report's
pretty printed format.
2025-04-30 13:43:05 -07:00
Shoaib Meenai
705ceff7c1
[TargetParser] Fix flaky installs of generated headers (#137853)
The `llvm-headers` target wasn't depending on the generated TargetParser
headers, so they'd be flakily installed or not installed depending on
which order the build steps ran in. Add an explicit dependency to fix
this, and switch to a single `target_parser_gen` target to mirror the
pattern used by `intrinsics_gen` (which also fixes a few other missing
dependencies). Switch `llvm-headers` to use `add_dependencies` instead
of `DEPENDS` for the tablegen dependencies as well, since `DEPENDS` is
only intended for creating a file-level dependency on the output of an
`add_custom_command` in the same CMakeLists.txt (see `DEPENDS` under
https://cmake.org/cmake/help/latest/command/add_custom_target.html).
2025-04-29 12:13:38 -07:00
Bob Wilson
2f1ef1d183
[Clang] Add new -header-include-filtering=direct-per-file option (#137087)
This adds a new filtering option to be used along with the
-header-include-format=json option. The existing "only-direct-system"
filtering option is missing some things:
- It does not show module imports.
- It does not show includes of non-system headers. This new
"direct-per-file" filtering has a separate entry in the JSON output for
each non-system source file, showing the direct includes and imports
from that file. You can use this to see uses of non-system headers, and
also find the paths through non-system headers that lead up to module
imports and system headers. Modules are identified here by their
modulemap files.
2025-04-28 21:54:45 -07:00
Jan Svoboda
985410f87f
[clang] Hide the TargetOptions pointer from CompilerInvocation (#106271)
This PR hides the reference-counted pointer that holds `TargetOptions`
from the public API of `CompilerInvocation`. This gives
`CompilerInvocation` an exclusive control over the lifetime of this
member, which will eventually be leveraged to implement a copy-on-write
behavior.

There are two clients that currently share ownership of that pointer:

* `TargetInfo` - This was refactored to hold a non-owning reference to
`TargetOptions`. The options object is typically owned by the
`CompilerInvocation` or by the new `CompilerInstance::AuxTargetOpts` for
the auxiliary target. This needed a bit of care in `ASTUnit::Parse()` to
keep the `CompilerInvocation` alive.
* `clangd::PreambleData` - This was refactored to exclusively own the
`TargetOptions` that get moved out of the `CompilerInvocation`.
2025-04-28 07:43:26 -07:00
Jan Svoboda
77148fce6f
[clang] Do not share ownership of HeaderSearchOptions (#132984)
This PR makes it so that `CompilerInvocation` is the sole owner of the
`HeaderSearchOptions` instance.
2025-04-25 07:38:51 -07:00
Bob Wilson
4f36ada1e2
[Clang] Fix crash when -header-include-filtering is not specified (#136232)
If you specify -header-include-format=json, the only filtering option
currently supported is -header-include-filtering=only-direct-system. If
you specify some other filtering option, Clang gives an error message.
But, if you do not specify the filtering option at all, Clang crashes
when producing the error message, since it tries to get the value of the
unused option.
2025-04-23 16:09:38 -07:00
Jannick Kremer
d7215c0ee2
[libclang/C++] Fix clang_File_isEqual for in-memory files (#135773)
Add tests for `clang_File_isEqual` (on-disk and in-memory)
2025-04-23 18:41:29 +02:00
Kazu Hirata
c2d6c7cea7
[clang] Use llvm::append_range (NFC) (#136448) 2025-04-19 12:21:14 -07:00
Selim Keles
0c0b5abff7
[clang-format] Handle spaces in filename paths in clang-format-diff.py (#135779)
This PR resolves an issue in clang-format-diff.py where
filenames containing spaces were not correctly extracted from Git diffs.
Due to the previous regex implementation, filenames were being
truncated, causing the script to fail when processing diffs with such
filenames.

Fixes #135619.
2025-04-18 19:42:22 -07:00
Kazu Hirata
f4c76bba59
[clang] Use llvm::append_range (NFC) (#136256)
This patch replaces:

  llvm::copy(Src, std::back_inserter(Dst));

with:

  llvm::append_range(Dst, Src);

for breavity.

One side benefit is that llvm::append_range eventually calls
llvm::SmallVector::reserve if Dst is of llvm::SmallVector.
2025-04-18 00:15:13 -07:00
Kazu Hirata
3133c956c5 [clang-sycl-linker] Fix a warning
This patch fixes:

  clang/tools/clang-sycl-linker/ClangSYCLLinker.cpp:368:14: error:
  moving a local object in a return statement prevents copy elision
  [-Werror,-Wpessimizing-move]
2025-04-17 10:19:37 -07:00
Arvind Sudarsanam
52e10e6c3b
[SYCL] Add clang-linker-wrapper changes to call clang-sycl-linker for SYCL offloads (#135683)
This PR is one of the many PRs in the SYCL upstreaming effort focusing
on device code linking during the SYCL offload compilation process. RFC:
https://discourse.llvm.org/t/rfc-offloading-design-for-sycl-offload-kind-and-spir-targets/74088

Approved PRs so far:
1. [Clang][SYCL] Introduce clang-sycl-linker to link SYCL offloading
device code (Part 1 of many) -
[Link](https://github.com/llvm/llvm-project/pull/112245)
2. [clang-sycl-linker] Replace llvm-link with API calls -
[Link](https://github.com/llvm/llvm-project/pull/133797)
3. [SYCL][SPIR-V Backend][clang-sycl-linker] Add SPIR-V backend support
inside clang-sycl-linker -
[Link](https://github.com/llvm/llvm-project/pull/133967)

This PR adds SYCL device code linking support to clang-linker-wrapper.

### Summary for this PR

Device code linking happens inside clang-linker-wrapper. In the current
implementation, clang-linker-wrapper does the following:

1. Extracts device code. Input_1, Input_2,.....
5. Group device code according to target devices Inputs[triple_1] = ....
Inputs[triple_2] = ....
6. For each group, i.e. Inputs[triple_i], a. Gather all the offload
kinds found inside those inputs in ActiveOffloadKinds b. Link all images
inside Inputs[triple_i] by calling clang --target=triple_i .... c.
Create a copy of that linked image for each offload kind and add it to
Output[Kind] list.

In SYCL compilation flow, there is a deviation in Step 3b. We call
device code splitting inside the 'clang --target=triple_i ....' call and
the output is now a 'packaged' file containing multiple device images.
This deviation requires us to capture the OffloadKind during the linking
stage and pass it along to the linking function (clang), so that clang
can be called with a unique option '--sycl-link' that will help us to
call 'clang-sycl-linker' under the hood (clang-sycl-linker will do SYCL
specific linking).

Our current objective is to implement an end-to-end SYCL offloading flow
and get it working. We will eventually merge our approach with the
community flow.

Thanks

---------

Signed-off-by: Arvind Sudarsanam <arvind.sudarsanam@intel.com>
2025-04-17 16:48:08 +00:00
Arvind Sudarsanam
6cfec29cb9
[Offload][SYCL] Refactor OffloadKind implementation (#135809)
Following are the changes:

1. Make OffloadKind enum values to be powers of two so we can use them
like a bitfield
2. Include OFK_SYCL enum value
3. Modify ActiveOffloadKinds support in clang-linker-wrapper to use
bitfields instead of a vector.

Thanks

---------

Signed-off-by: Arvind Sudarsanam <arvind.sudarsanam@intel.com>
2025-04-16 14:13:30 +00:00
Brian Cody
03b0f55d9c
[cindex] Add support for calling getFullyQualifiedName to the Python binding. (#135420)
We're coming from llvm 11. There was a change made back in 15f3cd6 that
changed how type spelling works. Previous we were given namespaces of
the types within the spelling, and this was necessary in our use-case.
There is a more appropriate function available but it was not being
exposed over the Python bindings. This PR is intended to make make this
already-existing functionality accessible.

---------

Co-authored-by: Jannick Kremer <jannick.kremer@mailbox.org>
2025-04-15 12:36:00 +02:00
Fangrui Song
c04d9d57ee
MCAsmStreamer: Replace the MCInstPrinter * parameter with unique_ptr
... to clarify ownership, aligning with other parameters. Using
`std::unique_ptr` encourages users to manage `createMCInstPrinter` with
a unique_ptr instead of a raw pointer, reducing the risk of memory
leaks.

* llvm-mc: fix a leak and update llvm/test/tools/llvm-mc/disassembler-options.test
* #121078 copied the llvm-mc code to CodeGenTargetMachineImpl and made
  the same mistake. Fixed by 2b8cc651dca0c000ee18ec79bd5de4826156c9d6

Using unique_ptr requires #include MCInstPrinter.h in a few translation
units.

* Delete a createAsmStreamer overload I deprecated in 2024
* SystemZMCTargetDesc.cpp: rename to `createSystemZAsmStreamer` to fix
  an overload conflict.

Pull Request: https://github.com/llvm/llvm-project/pull/135128
2025-04-10 21:25:35 -07:00
Owen Pan
72540dbe01 [clang-format][NFC] Reformat git-clang-format 2025-04-10 19:07:44 -07:00
Tim Clephas
c893f1d18d
Treat ipynb as json (#135137)
Fixes #110727
2025-04-10 20:40:43 +02:00
Wenju He
923da2b843
[clang-format] Add 'cl' to enable OpenCL kernel file formatting (#134529)
There are many .cl files in llvm repo. It would be great that
clang-format can support it.
2025-04-10 01:23:46 -07: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
Jan Svoboda
506630d6db
[clang][deps] Avoid unchecked error assertion (#134284) 2025-04-03 14:57:06 -07:00