5683 Commits

Author SHA1 Message Date
Paul Kirth
9d476e1e1a
[clang][FatLTO] Avoid UnifiedLTO until it can support WPD/CFI (#79061)
Currently, the UnifiedLTO pipeline seems to have trouble with several
LTO features, like SplitLTO units, which means we cannot use important
optimizations like Whole Program Devirtualization or security hardening
instrumentation like CFI.

This patch reverts FatLTO to using distinct pipelines for Full LTO and
ThinLTO. It still avoids module cloning, since that was error prone.
2024-01-23 14:04:52 -08:00
cor3ntin
02a28ee8d9
[Clang] Update feature test macros for Clang 18 (#78991)
* Set `__cpp_auto_cast`, as per
https://github.com/cplusplus/CWG/issues/281
* Support `__has_extension(cxx_generalized_nttp)` in C++20 as the
feature isn't stable enough for a feature test macro
* Support `__has_extension(cxx_explicit_this_parameter)` in c++23 as the
feature isn't stable enough for a feature test macro
2024-01-22 21:19:29 +01:00
Qiongsi Wu
4f21fb8447
[PGO] Reland PGO's Counter Reset and File Dumping APIs #76471 (#78285)
https://github.com/llvm/llvm-project/pull/76471 caused buildbot failures
on Windows. For more details, see
https://github.com/llvm/llvm-project/issues/77546.

This PR revises the test and relands
https://github.com/llvm/llvm-project/pull/76471.
2024-01-22 14:54:58 -05:00
Aaron Ballman
997ffce43c [C23] Implement N2490, Remove trigraphs??!
This follows the same implementation logic as with C++ and is
compatible with the GCC behavior in C.

Trigraphs are enabled by default in -std=c* conformance modes before
C23, but are disabled in GNU and Microsoft modes as well as in C23 or
later.
2024-01-21 13:20:56 -05:00
Kazu Hirata
851143608e [Frontend] Use SmallString::operator std::string (NFC) 2024-01-20 14:30:36 -08:00
Natalie Chouinard
c21f48e5ad
[HLSL][SPIR-V] Add Vulkan to target triple (#76749)
Add support for specifying the logical SPIR-V target environment in the
triple as Vulkan. When compiling HLSL, this replaces the DirectX Shader
Model with a Vulkan environment instead.

Currently, the only supported combinations of SPIR-V version and Vulkan
environment are:
- Vulkan 1.2 and SPIR-V 1.5
- Vulkan 1.3 and SPIR-V 1.6

Fixes #70051
2024-01-18 12:52:00 -05:00
Kazu Hirata
eccd279979 [clang] Use SmallString::operator std::string() (NFC) 2024-01-12 18:39:49 -08:00
Vitaly Buka
a828cda9c8 Revert "[PGO] Exposing PGO's Counter Reset and File Dumping APIs (#76471)"
Issue #77546

This reverts commit 07c9189fcc063bdf6219d2733843c89cde3991e1.
2024-01-09 18:37:04 -08:00
sethp
baa8c2abcd
[Clang] Wide delimiters ('{{{') for expect strings (#77326)
Prior to this commit, it was impossible to use the simple string
matching directives to look for any content that contains unbalanced
`{{` `}}` pairs, such as:

```
// expected-note {{my_struct{{1}, 2}}}
```

Which would parse like so:

```
             "nested" brace v
// expected-note {{my_struct{{1}, 2}}}
          closes the nested brace  ^ |
                            trailing }
```

And the frontend would complain 'cannot find end ('}}') of expected'.

At this snapshot, VerifyDiagnosticConsumer's parser now counts the
opening braces and looks for a matching length of closing sigils,
allowing the above to be written as:

```
// expected-note {{{my_struct{{1}, 2}}}}
   opening brace |-|                 |-|
  closing brace is '}}}', found here ^
```

This came about as a result of this discussion:
https://github.com/llvm/llvm-project/pull/74852#discussion_r1443117644

cc @erichkeane
2024-01-09 12:45:57 -08:00
Qiongsi Wu
07c9189fcc
[PGO] Exposing PGO's Counter Reset and File Dumping APIs (#76471)
This PR exposes four PGO functions 

- `__llvm_profile_set_filename`
- `__llvm_profile_reset_counters`, 
- `__llvm_profile_dump` 
- `__llvm_orderfile_dump` 

to user programs through the new header `instr_prof_interface.h` under
`compiler-rt/include/profile`. This way, the user can include the header
`profile/instr_prof_interface.h` to introduce these four names to their
programs.

Additionally, this PR defines macro `__LLVM_INSTR_PROFILE_GENERATE` when
the program is compiled with profile generation, and defines macro
`__LLVM_INSTR_PROFILE_USE` when the program is compiled with profile
use. `__LLVM_INSTR_PROFILE_GENERATE` together with
`instr_prof_interface.h` define the PGO functions only when the program
is compiled with profile generation. When profile generation is off,
these PGO functions are defined away and leave no trace in the user's
program.

Background:
https://discourse.llvm.org/t/pgo-are-the-llvm-profile-functions-stable-c-apis-across-llvm-releases/75832
2024-01-09 10:38:17 -05:00
Kazu Hirata
5c37e711df [Frontend] Use StringRef::drop_while (NFC) 2023-12-28 10:06:20 -08:00
Kazu Hirata
68f832f56d [clang] Use StringRef::consume_front (NFC) 2023-12-25 12:54:35 -08:00
Kazu Hirata
f3dcc2351c
[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-13 08:54:13 -08:00
Jan Svoboda
0cb0a48cde
[clang] NFC: Remove OptionalFileEntryRefDegradesToFileEntryPtr (#74899) 2023-12-08 18:22:41 -08:00
Zixu Wang
6e1f19168b
[clang][PP] Add extension to predefine target OS macros (#74676)
Add an extension feature `define-target-os-macros` that enables clang to
provide definitions of common TARGET_OS_* conditional macros. The
extension is enabled in the Darwin toolchain driver.
2023-12-07 17:40:58 -08:00
Joseph Huber
4e80bc7d71
[Clang] Introduce scoped variants of GNU atomic functions (#72280)
Summary:
The standard GNU atomic operations are a very common way to target
hardware atomics on the device. With more heterogenous devices being
introduced, the concept of memory scopes has been in the LLVM language
for awhile via the `syncscope` modifier. For targets, such as the GPU,
this can change code generation depending on whether or not we only need
to be consistent with the memory ordering with the entire system, the
single GPU device, or lower.

Previously these scopes were only exported via the `opencl` and `hip`
variants of these functions. However, this made it difficult to use
outside of those languages and the semantics were different from the
standard GNU versions. This patch introduces a `__scoped_atomic` variant
for the common functions. There was some discussion over whether or not
these should be overloads of the existing ones, or simply new variants.
I leant towards new variants to be less disruptive.

The scope here can be one of the following

```
__MEMORY_SCOPE_SYSTEM // All devices and systems
__MEMORY_SCOPE_DEVICE // Just this device
__MEMORY_SCOPE_WRKGRP // A 'work-group' AKA CUDA block
__MEMORY_SCOPE_WVFRNT // A 'wavefront' AKA CUDA warp
__MEMORY_SCOPE_SINGLE // A single thread.
```
Naming consistency was attempted, but it is difficult to capture to full
spectrum with no many names. Suggestions appreciated.
2023-12-07 13:40:25 -06:00
Chuanqi Xu
b768b39342 [C++20] [Modules] Skip Writing diagnostic options, header search paths and pragma diagnostic mappings
It simply wastes of space and time to write diagnostic options, header
search paths and pragma diagnostic mappings for C++20 Named modules.
This patch tries to avoid the unnecessary writings.
2023-12-07 16:54:00 +08:00
Juergen Ributzka
5ad3a32c79
[clang][modules] Reset codegen options (take 2). (#74388)
CodeGen options do not affect the AST, so they usually can be ignored.
The only exception to the rule is when a PCM is created with
`-gmodules`.
In that case the Clang module format is switched to object file
container and contains also serialized debug information that can be
affected by debug options. There the following approach was choosen:

1.) Split out all the debug options into a separate `DebugOptions.def`
    file. The file is included by `CodeGenOptions.def`, so the change is
    transparent to all existing users of `CodeGenOptions.def`.
2.) Reset all CodeGen options, but excluding affecting debug options.
3.) Conditionally reset debug options that can affect the PCM.

This fixes rdar://113135909.
2023-12-05 08:31:21 -08:00
Juergen Ributzka
1157bee5ce Revert "[clang][modules] Reset codegen options. (#74006)"
This reverts commit fef1854318bd797c1f8a141d4b45b113b04860d1.
2023-12-04 14:28:22 -08:00
Juergen Ributzka
fef1854318
[clang][modules] Reset codegen options. (#74006)
CodeGen options do not affect the AST, so they usually can be ignored.
The only exception to the rule is when a PCM is created with
`-gmodules`.
In that case the Clang module format is switched to object file
container and contains also serialized debug information that can be
affected by debug options. There the following approach was choosen:

1.) Split out all the debug options into a separate `DebugOptions.def`
    file. The file is included by `CodeGenOptions.def`, so the change is
    transparent to all existing users of `CodeGenOptions.def`.
2.) Reset all CodeGen options, but excluding affecting debug options.
3.) Conditionally reset debug options that can affect the PCM.

This fixes rdar://113135909.
2023-12-04 13:54:57 -08:00
Momchil Velikov
e3a97dffee
[Verifier] Check function attributes related to branch protection (NFC) (#70565) 2023-12-04 16:16:55 +00:00
Paul Kirth
cfe1ece833
[clang][llvm][fatlto] Avoid cloning modules in FatLTO (#72180)
https://github.com/llvm/llvm-project/issues/70703 pointed out that
cloning LLVM modules could lead to miscompiles when using FatLTO.

This is due to an existing issue when cloning modules with labels (see
#55991 and #47769). Since this can lead to miscompilation, we can avoid
cloning the LLVM modules, which was desirable anyway.

This patch modifies the EmbedBitcodePass to no longer clone the module
or run an input pipeline over it. Further, it make FatLTO always perform
UnifiedLTO, so we can still defer the Thin/Full LTO decision to
link-time. Lastly, it removes dead/obsolete code related to now defunct
options that do not work with the EmbedBitcodePass implementation any
longer.
2023-11-30 17:09:34 -08:00
Juergen Ributzka
21361bb860
[clang] Remove unused argument. NFC. (#73594) 2023-11-28 09:19:39 -08:00
Fangrui Song
e2d60c8626 [Frontend] Remove unneeded -frtti check. NFC
-frtti is not a CC1 option. We just need to check -fno-rtti.
2023-11-27 21:41:04 -08:00
Egor Zhdan
07d799f08f
[APINotes] Upstream Driver and Frontend options that enable API Notes
This upstreams more of the Clang API Notes functionality that is
currently implemented in the Apple fork:
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes
2023-11-23 18:52:27 +00:00
Egor Zhdan
e6ef315247
[APINotes] Introduce APINotes infrastructure in Clang Sema and Frontend
This upstreams more of the Clang API Notes functionality that is
currently implemented in the Apple fork:
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes

This adds the initial Clang APINotes infrastructure to Clang Sema and
Clang Frontend.

There will shortly be a follow-up patch with the actual usages of this
API. I'm splitting these changes into separate PRs to keep the diffs
easier to review.
2023-11-21 13:36:50 +00:00
Erich Keane
ff219ea9ca
[OpenACC] Initial commits to support OpenACC (#70234)
Initial commits to support OpenACC.  This patchset:

adds a clang-command line argument '-fopenacc', and starts
 to define _OPENACC, albeit to '1' instead of the standardized
value (since we don't properly implement OpenACC yet).

The OpenACC spec defines `_OPENACC` to be equal to the latest standard
implemented. However, since we're not done implementing any standard,
we've defined this by default to be `1`. As it is useful to run our
compiler against existing OpenACC workloads, we're providing a
temporary override flag to change the `_OPENACC` value to be any
entirely digit value, permitting testing against any existing OpenACC
project.

Exactly like the OpenMP parser, the OpenACC pragma parser needs to
consume and reprocess the tokens. This patch sets up the infrastructure
to do so by refactoring the OpenMP version of this into a more general
version that works for OpenACC as well.

Additionally, this adds a few diagnostics and token kinds to get us
started.
2023-11-17 06:29:02 -08:00
Kazu Hirata
651c502fc8 [clang] Stop including llvm/ADT/DenseSet.h (NFC)
Identified with clangd.
2023-11-11 22:25:48 -08:00
Chuanqi Xu
0f7aaeb324 [C++20] [Modules] Allow export from language linkage
Close https://github.com/llvm/llvm-project/issues/71347

Previously I misread the concept of module purview. I thought if a
declaration attached to a unnamed module, it can't be part of the module
purview. But after the issue report, I recognized that module purview is
more of a concept about locations instead of semantics.

Concretely, the things in the language linkage after module declarations
can be exported.

This patch refactors `Module::isModulePurview()` and introduces some
possible code cleanups.
2023-11-09 17:44:41 +08:00
Arthur Eubanks
955dd8800b
Revert "Reland [clang] Canonicalize system headers in dependency file when -canonical-prefixes" (#71697)
This reverts commit 578a4716f549167165a2ec3bac89c86706136d4e.

This causes multiple issues. Compile time slowdown due to more path
canonicalization, and weird behavior on Windows.

Will reland under a separate flag `-f[no-]canonical-system-headers` to
match gcc in the future and further limit when it's passed by default.

Fixes #70011.
2023-11-08 11:43:35 -08:00
Vlad Serebrennikov
3e6ce58701 [clang][NFC] Refactor StringLiteral::StringKind
This patch converts `StringLiteral::StringKind` to a scoped enum in namespace scope. This enabled forward-declarations of this enum where necessary, e.g. for `preferred_type` annotation for bit-fields.
2023-11-05 12:30:49 +03:00
Vlad Serebrennikov
edd690b02e
[clang][NFC] Refactor TagTypeKind (#71160)
This patch converts TagTypeKind into scoped enum. Among other benefits,
this allows us to forward-declare it where necessary.
2023-11-03 21:45:39 +04:00
Jan Svoboda
6c465a201b
[clang][deps] Skip slow UNHASHED_CONTROL_BLOCK records (#69975)
Deserialization of the `DIAGNOSTIC_OPTIONS` and `HEADER_SEARCH_PATHS`
records is slow and done for every transitively loaded PCM.
Deserialization of these records cannot be skipped, because the words
are VBR6-encoded and we don't store the length of the entire record. We
could either turn them into binary blobs that can be skipped during
deserialization, or skip writing them altogether. This patch takes the
latter approach, since these records are not necessary in scanning PCMs.
The scanner doesn't make any guarantees about the accuracy of
diagnostics, and we always have the same header search paths due to
strict context hashing.

The commit that makes the `DIAGNOSTIC_OPTIONS` record skippable was
originally implemented by @benlangmuir in a downstream repo.
2023-11-02 15:07:58 -07:00
Egor Zhdan
f1c9a1c3a5
Revert "Revert "[APINotes] Upstream APINotesOptions""
This re-lands https://github.com/llvm/llvm-project/pull/70827 while
preventing the assertion failure that occurred when generating
`ASTNodeAPI.json` on non-Apple platforms.
2023-11-02 12:39:55 +00:00
Johannes Doerfert
0e06ddf0f6 Revert "[APINotes] Upstream APINotesOptions"
This reverts commit c0a1857928c557400af0ed53d198cc9f3f185f9a.

A shared_ptr assertion always triggers causes all bots to fail.
2023-11-01 11:33:25 -07:00
Egor Zhdan
c0a1857928
[APINotes] Upstream APINotesOptions
This upstreams more of the Clang API Notes functionality that is
currently implemented in the Apple fork:
https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes

This adds the first compiler options related to API Notes to the
upstream Clang: `-iapinotes-modules` and `-fapinotes-swift-version=`.
However, this does not add the `-fapinotes` flag that enables API Notes,
since the feature is not fully functional yet.
2023-11-01 17:56:39 +00:00
Vlad Serebrennikov
aaba3761db [clang][NFC] Refactor ObjCMethodDecl::ImplementationControl
This patch moves `ObjCMethodDecl::ImplementationControl` to a DeclBase.h so that it's complete at the point where corresponsing bit-field is declared. This patch also converts it to a scoped enum `clang::ObjCImplementationControl`.
2023-11-01 13:40:11 +03:00
Vlad Serebrennikov
49fd28d960 [clang][NFC] Refactor ArrayType::ArraySizeModifier
This patch moves `ArraySizeModifier` before `Type` declaration so that it's complete at `ArrayTypeBitfields` declaration. It's also converted to scoped enum along the way.
2023-10-31 18:06:34 +03:00
Chuanqi Xu
e9a7876c2c [C++20] [Modules] Chose BMI from for module m with the last
-fmodule-file=<module-name>= option

Currently if we have multiple `-fmodule-file=<module-name>=<BMI-path>`
flags for the same `<module-name>`, we will pick the BMI-path from the
first flag. And this is inconsistent with what users generally expect.
e.g, we might expect the latter flags can override the former ones.

This patch changes the behavior to match user's expectation.
2023-10-27 16:52:21 +08:00
Paul Robinson
513b950a79 Make -frewrite-includes handle -include correctly
The `-include "file"` option implicitly adds a leading #include
to the main source; however, there's no explicit #include, which
left -frewrite-includes emitting an unmatched #endif at the end
of the included text.

This corrects a bug in 4a16b51f.
2023-10-24 09:08:31 -07:00
Min-Yih Hsu
fd4f96290a [Clang][M68k] Add Clang support for the new M68k_RTD CC
This patch adds `CC_M68kRTD`, which will be used on function if either
`__attribute__((m68k_rtd))` is presented or `-mrtd` flag is given.

Differential Revision: https://reviews.llvm.org/D149867
2023-10-15 16:13:43 -07:00
Kazu Hirata
d7b18d5083 Use llvm::endianness{,::little,::native} (NFC)
Now that llvm::support::endianness has been renamed to
llvm::endianness, we can use the shorter form.  This patch replaces
llvm::support::endianness with llvm::endianness.
2023-10-09 00:54:47 -07:00
David Stone
701d804cdb
[clang][Modules] checkModuleIsAvailable should use a const & parameter instead of pointer (#67902)
The `Module` parameter to `checkModuleIsAvailable` is currently passed
by pointer to non-const. However, it requires only const access and it
cannot be null. Change this to be a reference to const instead.

This then makes it obvious that it is an input-only parameter, so move
it to be before the in-out parameter for diagnostics.
2023-10-08 09:49:05 +08:00
Paul Robinson
71d83bb426 Add -fkeep-system-includes modifier for -E
This option will cause -E to preserve the #include directives
for system headers, rather than expanding them into the output.
This can greatly reduce the volume of preprocessed source text
in a test case, making test case reduction simpler.

Note that -fkeep-system-includes is not always appropriate. For
example, if the problem you want to reproduce is induced by a
system header file, it's better to expand those headers fully.
If your source defines symbols that influence the content of a
system header (e.g., _POSIX_SOURCE) then -E will eliminate the
definition, potentially changing the meaning of the preprocessed
source. If you use -isystem to point to non-system headers, for
example to suppress warnings in third-party software, those will
not be expanded and might make the preprocessed source less useful
as a test case.
2023-10-06 12:55:48 -07:00
Paul Robinson
9500616a04 [NFC] Change a reference member to pointer
This will allow the raw_ostream to be redirected in a subsequent commit.
2023-10-06 12:55:48 -07:00
Paul T Robinson
4a16b51f43
Make -frewrite-includes put an endif at the end of the included text (#67613)
The #if now has a conditional expression, so a user can add 
`-D__CLANG_REWRITTEN_SYSTEM_INCLUDES` to include the system headers
instead of using the expanded content, or 
`-D__CLANG_REWRITTEN_INCLUDES` to include all headers.
Also added the filename to the comments it emits, to help identify where
included text ends, making it easier to identify and remove the content of
individual headers.
2023-10-06 12:27:07 -07:00
Aaron Ballman
46518a14f1 Revert "Revert "Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (#68127)""
This reverts commit a6acf3fd49a20c570a390af2a3c84e10b9545b68 and
relands a50e63b38b931d945f97eac882278068221eca17. The original revert
was done by mistake.
2023-10-06 07:43:19 -04:00
Kazu Hirata
a6acf3fd49 Revert "Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (#68127)"
This reverts commit a50e63b38b931d945f97eac882278068221eca17.

With clang-14.0.6 as the host compiler, I'm getting:

ld.lld: error: undefined symbol: clang::ASTWriter::WriteAST(clang::Sema&, llvm::StringRef, clang::Module*, llvm::StringRef, bool, bool)
>>> referenced by ASTUnit.cpp
>>>               ASTUnit.cpp.o:(clang::ASTUnit::serialize(llvm::raw_ostream&)) in archive lib/libclangFrontend.a
2023-10-05 13:08:24 -07:00
Rajkumar Ananthu
a50e63b38b
Fixes and closes #53952. Setting the ASTHasCompilerErrors member variable correctly based on the PP diagnostics. (#68127)
The issue #53952 is reported indicating clang is giving a crashing pch
file, when hasErrors is been passed incorrectly to WriteAST method.

To fix the issue, the parameter has been removed and instead we're
relying on the results of `hasUncompilableErrorOccured()` instead of
letting the caller override it.

Fixes https://github.com/llvm/llvm-project/issues/53952
2023-10-05 14:51:57 -04:00
Pranav Kant
7d21086d0c Revert "[clang] Predefined macros for float128 support (#67196)"
This reverts commit 457f582ffe23e951380bc345c4c96ec053c09681.
2023-10-04 18:19:24 +00:00