5714 Commits

Author SHA1 Message Date
Nathan Lanza
e66b670f3b
[CIR][Basic][NFC] Add the CIR language to the Language enum
Add the CIR language to the Language enum and the standard usages of it.

commit-id:fd12b2c2

Reviewers: bcardosolopes, AaronBallman, erichkeane

Reviewed By: AaronBallman, bcardosolopes

Pull Request: https://github.com/llvm/llvm-project/pull/86072
2024-03-21 19:53:48 -04:00
Evan Wilde
12a6546395
Add support for sysroot-relative system header search paths (#82084)
Clang supported header searchpaths of the form `-I =/path`, relative to
the sysroot if one is passed, but did not implement that behavior for
`-iquote`, `-isystem`, or `-idirafter`.

This implements the `=` portion of the behavior implemented by GCC for
these flags described in
https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html.
2024-03-19 13:17:11 -07:00
Ahmed Bougacha
0481f049c3
[AArch64][PAC] Support ptrauth builtins and -fptrauth-intrinsics. (#65996)
This defines the basic set of pointer authentication clang builtins
(provided in a new header, ptrauth.h), with diagnostics and IRGen
support.  The availability of the builtins is gated on a new flag,
`-fptrauth-intrinsics`.

Note that this only includes the basic intrinsics, and notably excludes
`ptrauth_sign_constant`, `ptrauth_type_discriminator`, and
`ptrauth_string_discriminator`, which need extra logic to be fully
supported.

This also introduces clang/docs/PointerAuthentication.rst, which
describes the ptrauth model in general, in addition to these builtins.

Co-Authored-By: Akira Hatanaka <ahatanaka@apple.com>
Co-Authored-By: John McCall <rjmccall@apple.com>
2024-03-15 14:17:21 -07:00
Ulrich Weigand
c9062e8f78 Reapply [libomptarget] Build plugins-nextgen for SystemZ (#83978)
The plugin was not getting built as the build_generic_elf64 macro
assumes the LLVM triple processor name matches the CMake processor name,
which is unfortunately not the case for SystemZ.

Fix this by providing two separate arguments instead.

Actually building the plugin exposed a number of other issues causing
various test failures. Specifically, I've had to add the SystemZ target
to
- CompilerInvocation::ParseLangArgs
- linkDevice in ClangLinuxWrapper.cpp
- OMPContext::OMPContext (to set the device_kind_cpu trait)
- LIBOMPTARGET_ALL_TARGETS in libomptarget/CMakeLists.txt
- a check_plugin_target call in libomptarget/src/CMakeLists.txt

Finally, I've had to set a number of test cases to UNSUPPORTED on
s390x-ibm-linux-gnu; all these tests were already marked as UNSUPPORTED
for x86_64-pc-linux-gnu and aarch64-unknown-linux-gnu and are failing on
s390x for what seem to be the same reason.

In addition, this also requires support for BE ELF files in
plugins-nextgen: https://github.com/llvm/llvm-project/pull/85246
2024-03-15 19:06:43 +01:00
Zaara Syeda
37b5eb0a0a
[AIX][TOC] Add -mtocdata/-mno-tocdata options on AIX (#67999)
This patch enables support that the XL compiler had for AIX under
-qdatalocal/-qdataimported.
2024-03-13 10:26:31 -04:00
Chuanqi Xu
5d7796e674 [NFC] [C++20] [Modules] Refactor ReducedBMIGenerator
Changes:
- Don't lookup the emitting module from HeaderSearch. We will use the
  module from the ASTContext directly.
- Remove some useless arguments. Let's addback in the future if
  required.
2024-03-13 11:22:32 +08:00
Jie Fu
a4703e5bcc [clang] Remove std::move in GenerateModuleAction::CreateMultiplexConsumer (NFC)
llvm-project/clang/lib/Frontend/FrontendActions.cpp:213:10:
error: moving a local object in a return statement prevents copy elision [-Werror,-Wpessimizing-move]
  213 |   return std::move(Consumers);
      |          ^
/Users/jiefu/llvm-project/clang/lib/Frontend/FrontendActions.cpp:213:10: note: remove std::move call here
  213 |   return std::move(Consumers);
      |          ^~~~~~~~~~         ~
1 error generated.
2024-03-08 10:19:07 +08:00
Chuanqi Xu
da00c60dae
[C++20] [Modules] Introduce reduced BMI (#75894)
Close https://github.com/llvm/llvm-project/issues/71034

See

https://discourse.llvm.org/t/rfc-c-20-modules-introduce-thin-bmi-and-decls-hash/74755

This patch introduces reduced BMI, which doesn't contain the definitions
of functions and variables if its definitions won't contribute to the
ABI.

Testing is a big part of the patch. We want to make sure the reduced BMI
contains the same behavior with the existing and relatively stable
fatBMI. This is pretty helpful for further reduction.

The user interfaces part it left to following patches to ease the
reviewing.
2024-03-08 10:12:51 +08:00
aniplcc
2acccf6717
[Clang] Update value for __cpp_implicit_move (#84216) (#84228)
Fixes #84216
2024-03-07 14:39:04 +01:00
Ulrich Weigand
70677c81de Revert "[libomptarget] Build plugins-nextgen for SystemZ (#83978)"
This reverts commit 3ecd38c8e1d34b1e4639a1de9f0cb56c7957cbd2.
2024-03-06 21:37:43 +01:00
Ulrich Weigand
3ecd38c8e1
[libomptarget] Build plugins-nextgen for SystemZ (#83978)
The plugin was not getting built as the build_generic_elf64 macro
assumes the LLVM triple processor name matches the CMake processor name,
which is unfortunately not the case for SystemZ.

Fix this by providing two separate arguments instead.

Actually building the plugin exposed a number of other issues causing
various test failures. Specifically, I've had to add the SystemZ target
to
- CompilerInvocation::ParseLangArgs
- linkDevice in ClangLinuxWrapper.cpp
- OMPContext::OMPContext (to set the device_kind_cpu trait)
- LIBOMPTARGET_ALL_TARGETS in libomptarget/CMakeLists.txt
- a check_plugin_target call in libomptarget/src/CMakeLists.txt

Finally, I've had to set a number of test cases to UNSUPPORTED on
s390x-ibm-linux-gnu; all these tests were already marked as UNSUPPORTED
for x86_64-pc-linux-gnu and aarch64-unknown-linux-gnu and are failing on
s390x for what seem to be the same reason.

In addition, this also requires support for BE ELF files in
plugins-nextgen: https://github.com/llvm/llvm-project/pull/83976
2024-03-06 20:50:01 +01:00
Michael Spencer
ee044d5e65
[clang] Diagnose config_macros before building modules (#83641)
Before this patch, if a module fails to build because of a missing
config_macro, the user will never see the config macro warning. This
patch diagnoses this before building, and each subsequent time a module
is imported.

rdar://123921931
2024-03-05 10:15:21 -08:00
Jan Svoboda
164c098568 [clang][deps] Implement move-conversion for CowCompilerInvocation (follow-up) 2024-03-01 16:53:12 -08:00
Jan Svoboda
39b67c0321 [clang] NFC: Extract CompilerInstance function 2024-03-01 16:53:12 -08:00
Felix (Ting Wang)
5b05870953
[PowerPC] Support local-dynamic TLS relocation on AIX (#66316)
Supports TLS local-dynamic on AIX, generates below sequence of code:

```
.tc foo[TC],foo[TL]@ld # Variable offset, ld relocation specifier
.tc mh[TC],mh[TC]@ml # Module handle for the caller
lwz 3,mh[TC]\(2\) $$ For 64-bit: ld 3,mh[TC]\(2\)
bla .__tls_get_mod # Modifies r0,r3,r4,r5,r11,lr,cr0
#r3 = &TLS for module
lwz 4,foo[TC]\(2\) $$ For 64-bit: ld 4,foo[TC]\(2\)
add 5,3,4 # Compute &foo
.rename mh[TC], "\_$TLSML" # Symbol for the module handle must have the name "_$TLSML"
```

---------

Co-authored-by: tingwang <tingwang@tingwangs-MBP.lan>
Co-authored-by: tingwang <tingwang@tingwangs-MacBook-Pro.local>
2024-03-01 08:09:40 +08:00
Chuanqi Xu
2e5af56b05 [C++20] [Modules] Allow to compile a pcm with and without -fPIC
seperately

We can compile a module unit in 2 phase compilaton:

```
clang++ -std=c++20 a.cppm --precompile -o a.pcm
clang++ -std=c++20 a.pcm -c -o a.o
```

And it is a general requirement that we need to compile a translation
unit with and without -fPIC for static and shared libraries.

But for C++20 modules with 2 phase compilation, it may be waste of time
to compile them 2 times completely. It may be fine to generate one BMI
and compile it with and without -fPIC seperately.

e.g.,

```
clang++ -std=c++20 a.cppm --precompile -o a.pcm
clang++ -std=c++20 a.pcm -c -o a.o
clang++ -std=c++20 a.pcm -c -fPIC -o a-PIC.o
```

Then we can save the time to parse a.cppm repeatedly.
2024-02-23 11:05:15 +08:00
Cyndy Ishida
0a518db99e
[InstallAPI] Set InstallAPI as a standalone tool instead of CC1 action (#82293)
Installapi has important distinctions when compared to the clang driver,
so much that, it doesn't make much sense to try to integrate into it.

This patch partially reverts the CC1 action & driver support to replace
with its own driver as a clang tool.

For distribution, we could use `LLVM_TOOL_LLVM_DRIVER_BUILD` mechanism
for integrating the functionality into clang such that the toolchain
size is less impacted.
2024-02-21 09:39:31 -08:00
Aaron Ballman
052ee74dae
[C23] Add __TYPE_FMTB__ and __TYPE_FMTb__ predefined macros (#82361)
This adds predefined formatting macros in C23 mode for printing unsigned
integers in binary format (e.g, UINT_FAST64_FMTB). These are used to
implement the PRIb (et al) macros in inttypes.h

Fixes https://github.com/llvm/llvm-project/issues/81896

(Was previously reviewed in
[82037](https://github.com/llvm/llvm-project/pull/82037), this is fixing
some failures found post-commit.)
2024-02-20 09:32:23 -05:00
Aaron Ballman
bfbd0da01d
Revert "[C23] Add __TYPE_FMTB__ and __TYPE_FMTb__ predefined macros" (#82070)
Reverts llvm/llvm-project#82037

Breaks various buildbots:
http://45.33.8.238/linux/131051/step_7.txt
https://lab.llvm.org/buildbot/#/builders/231/builds/20751
others
2024-02-16 18:53:22 -05:00
Aaron Ballman
b3050f518c
[C23] Add __TYPE_FMTB__ and __TYPE_FMTb__ predefined macros (#82037)
This adds predefined formatting macros in C23 mode for printing unsigned
integers in binary format (e.g, __UINT_FAST64_FMTB__). These are used to
implement the PRIb (et al) macros in inttypes.h

Fixes https://github.com/llvm/llvm-project/issues/81896
2024-02-16 17:18:27 -05:00
PiJoules
ad49657a42
[clang] Add fixed point precision macros (#81207)
This defines the builtin macros specified in `7.18a.3 Precision macros`
of ISO/IEC TR 18037:2008. These are the `__*__` versions of them and the
formal definitions in stdfix.h can use them.
2024-02-14 14:11:56 -08:00
Cyndy Ishida
09e98950bf
[clang][InstallAPI] Introduce basic driver to write out tbd files (#81571)
This introduces a basic outline of installapi as a clang driver option.
It captures relevant information as cc1 args, which are common arguments
already passed to the linker to encode into TBD file outputs. This is
effectively an upstream for what already exists as `tapi installapi` in
Xcode toolchains, but directly in Clang. This patch does not handle any
AST traversing on input yet.

InstallAPI is broadly an operation that takes a series of header files
that represent a single dynamic library and generates a TBD file out of
it which represents all the linkable symbols and necessary attributes
for statically linking in clients. It is the linkable object in all
Apple SDKs and when building dylibs in Xcode. `clang -installapi` also
will support verification where it compares all the information recorded
for the TBD files against the already built binary, to catch possible
mismatches like when a declaration is missing a definition for an
exported symbol.
2024-02-13 18:52:11 -08:00
Jan Svoboda
da95d926f6
[clang][lex] Always pass suggested module to InclusionDirective() callback (#81061)
This patch provides more information to the
`PPCallbacks::InclusionDirective()` hook. We now always pass the
suggested module, regardless of whether it was actually imported or not.
The extra `bool ModuleImported` parameter then denotes whether the
header `#include` will be automatically translated into import the the
module.

The main change is in `clang/lib/Lex/PPDirectives.cpp`, where we take
care to not modify `SuggestedModule` after it's been populated by
`LookupHeaderIncludeOrImport()`. We now exclusively use the `SM`
(`ModuleToImport`) variable instead, which has been equivalent to
`SuggestedModule` until now. This allows us to use the original
non-modified `SuggestedModule` for the callback itself.

(This patch turns out to be necessary for
https://github.com/apple/llvm-project/pull/8011).
2024-02-08 10:19:18 -08:00
Shourya Goel
4e58f03f29
[Clang] Fix : More Detailed "No expected directives found" (#78338)
Updated the error message to use the proper prefix when
no expected directives are found by changing the hard coded expected in
the message to a dynamic value in two error messages.

Fixes #58290
2024-02-07 09:10:17 -05:00
alexfh
a986f5e218
Fix clang crash when printing highlighted code in diagnostic (after #66514) (#80442)
Implements the fix proposed by Evgeny Eltsin on
https://github.com/llvm/llvm-project/pull/66514#issuecomment-1924039038.

No test case provided, since the bug is extremely sensitive to the
preprocessor
state (headers, macros, including the ones defined on command line), and
it
turned out to be non-trivial to create an isolated test.
2024-02-02 16:31:45 +01:00
Timm Baeder
6d1d2c67e7
[clang] Fix a possible out-of-bounds read (#80023)
Fixes #79964
2024-02-02 11:15:57 +01:00
Kazu Hirata
b67ce7e349 [clang] Use StringRef::starts_with (NFC) 2024-01-31 23:54:09 -08:00
Michael Spencer
7847e44594
[clang][DependencyScanner] Remove unused -ivfsoverlay files (#73734)
`-ivfsoverlay` files are unused when building most modules. Enable
removing them by,
* adding a way to visit the filesystem tree with extensible RTTI to
  access each `RedirectingFileSystem`.
* Adding tracking to `RedirectingFileSystem` to record when it
  actually redirects a file access.
* Storing this information in each PCM.

Usage tracking is only enabled when iterating over the source manager
and affecting modulemaps. Here each path is stated to cause an access.
During scanning these stats all hit the cache.
2024-01-30 15:39:18 -08:00
yronglin
0aff71c178
[Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (#76361)
Implement P2718R0 "Lifetime extension in range-based for loops"
(https://wg21.link/P2718R0)

Differential Revision: https://reviews.llvm.org/D153701

---------

Signed-off-by: yronglin <yronglin777@gmail.com>
2024-01-30 06:48:14 +08:00
Kazu Hirata
a3f379e4e9 [Frontend] Use StringRef::consume_back (NFC) 2024-01-28 18:03:33 -08:00
Timm Baeder
718aac9f7a
[clang][Diagnostics] Highlight code snippets (#66514)
Add some primitive syntax highlighting to our code snippet output.

This adds "checkpoints" to the Preprocessor, which we can use to start lexing from. When printing a code snippet, we lex from the nearest checkpoint and highlight the tokens based on their token type.
2024-01-27 17:52:20 +01:00
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