112408 Commits

Author SHA1 Message Date
Victor Campos
226a9d73ee
Add documentation for Multilib custom flags (#114998)
This patch is the fourth step to extend the current multilib system to
support the selection of library variants which do not correspond to
existing command-line options.

Proposal can be found in
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

The multilib mechanism supports libraries that target code generation or
language options such as --target, -mcpu, -mfpu, -mbranch-protection.
However, some library variants are particular to features that do not
correspond to any command-line options. Examples include variants for
multithreading and semihosting.

This work introduces a way to instruct the multilib system to consider
these features in library selection. This particular patch updates the
documentation.
2025-01-16 09:53:04 +00:00
Victor Campos
3a9380f21d
[Multilib] Custom flags processing for library selection (#110659)
This patch is the third step to extend the current multilib system to
support the selection of library variants which do not correspond to
existing command-line options.

Proposal can be found in
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

The multilib mechanism supports libraries that target code generation or
language options such as --target, -mcpu, -mfpu, -mbranch-protection.
However, some library variants are particular to features that do not
correspond to any command-line options. Examples include variants for
multithreading and semihosting.

This work introduces a way to instruct the multilib system to consider
these features in library selection. This particular patch is comprised
of the core processing of these flags.

- Custom flags in the command-line are read and forwarded to the
multilib system. If multiple flag values are present for the same flag
declaration, the last one wins. Default flag values are inserted for
flag declarations for which no value was given.
- Feed `MacroDefines` back into the driver. Each item `<string>` in the
`MacroDefines` list is formatted as `-D<string>`.

Library variants should list their requirement on one or more custom
flags like they do for any other flag. The new command-line option is
passed as-is to the multilib system, therefore it should be listed in
the format `-fmultilib-flag=<str>`.

Moreover, a variant that does not specify a requirement on any
particular flag can be matched against any value of that flag.

If the user specifies `-fmultilib-flag=<name>` with a name that is
invalid, but close enough to any valid flag value name in terms of edit
distance, a suggesting error is shown:
```
error: unsupported option '-fmultilib-flag=invalidname'; did you mean '-fmultilib-flag=validname'?
```
The candidate with the smallest edit distance is chosen for the
suggestion, up to a certain maximum value (implementation detail), after
which a non-suggesting error is shown instead:
```
error: unsupported option '-fmultilib-flag=invalidname'
```
2025-01-16 09:35:56 +00:00
Younan Zhang
fd4f94ddbf
[Clang] Correct the order of substituted arguments in CTAD alias guides (#123022)
We missed a case of type constraints referencing deduced template
parameters when constructing a deduction guide for the type alias. This
patch fixes the issue by swapping the order of constructing 'template
arguments not appearing in the type alias parameters' and 'template
arguments that are not yet deduced'.

Fixes https://github.com/llvm/llvm-project/issues/122134
2025-01-16 16:37:57 +08:00
David Truby
0195ec452e
[flang] Add -f[no-]unroll-loops flag (#122906) 2025-01-16 06:43:32 +00:00
Chuanqi Xu
731db2a03e Revert "[C++20] [Modules] Support module level lookup (#122887)"
This reverts commit 7201cae106260aeb3e9bbbb7d5291ff30f05076a.
2025-01-16 10:23:11 +08:00
Alex Voicu
c805df6999
[NFC][clang][HIP] Remove flag from SPIR-V Translator invocation (#122995)
Remove spurious `--spirv-allow-extra-diexpressions` flag from the
translator invocation, as it's already implied by using
`nonsemantic-shader-200`.
2025-01-16 01:05:03 +00:00
David Blaikie
504dd57767 DebugInfo: Avoid emitting null members for nodebug nested typedefs
Only comes up for CodeView, since it forcibly emits even unused nested
typedefs.

Part of issue #122350
2025-01-15 23:20:40 +00:00
Ashley Coleman
4f48abff0f
[HLSL] Implement elementwise firstbitlow builtin (#116858)
Closes https://github.com/llvm/llvm-project/issues/99116

Implements `firstbitlow` by extracting common functionality from
`firstbithigh` into a shared function while also fixing a bug for an edge
case where `u64x3` and larger vectors will attempt to create vectors
larger than the SPRIV max of 4.
---------

Co-authored-by: Steven Perron <stevenperron@google.com>
2025-01-15 15:36:50 -07:00
erichkeane
2c75bda426 [OpenACC] Split up SemaOpenACC.cpp
This file is getting quite large, so this patch splits the 'clause'
specific parts off into its own file to keep them better organized.
2025-01-15 13:51:05 -08:00
Hubert Tong
1c3df5308a
[NFC] Explicitly use clang::Module in test file
https://github.com/llvm/llvm-project/pull/122887 uses `Module` to refer
to `clang::Module` in a test that has `using namespace llvm;`.

This causes lookup ambiguity with `llvm::Module` if the headers involved
expose that name (e.g., for downstream codebases).
2025-01-15 17:44:25 -04:00
Sharjeel Khan
e9255dda23
[Driver][ARM] Change Android's NEON FPU hardcoding to "== 7" as it pessimizes future ArmV8 code (#122969)
Android hardcoded NEON FPU for ARM version ">=" 7. This hardcoding was
pessimizing ARMv8 code as it was locking it to NEON FPU instead of
something more powerful.
2025-01-15 13:23:23 -08:00
Erich Keane
bf17016a92
Add 'enum_select' diagnostic selection to clang. (#122505)
This causes us to generate an enum to go along with the select
diagnostic, which allows for clearer diagnostic error emit lines.

The syntax for this is:

%enum_select<EnumerationName>{%OptionalEnumeratorName{Text}|{Text2}}0

Where the curley brackets around the select-text are only required if an
Enumerator name is provided.

The TableGen here emits this as a normal 'select' to the frontend, which
permits us to reuse all of the existing 'select' infrastructure.
Documentation is the same as well.

---------

Co-authored-by: Aaron Ballman <aaron@aaronballman.com>
2025-01-15 12:59:08 -08:00
Brian Cain
f325e4b2d8
[Hexagon] Add default clang symlinks to CLANG_LINKS_TO_CREATE (#123011)
Since this cache value overrides the defaults, we end up with `clang`
linked to `clang-20`, and some `${triple}-clang*` links, but we're
missing `clang++`. This makes for a toolchain with inconsistent behavior
when used in someone's `$PATH`.

We'll add the default symlinks to our list so that C and C++ programs
are both built as expected when `clang` and `clang++` are invoked.
2025-01-15 12:53:32 -06:00
Egor Zhdan
feb787244e
[APINotes] Avoid duplicated attributes for class template instantiations
If a C++ class template is annotated via API Notes, the instantiations
had the attributes repeated twice. This is because Clang was adding the
attribute twice while processing the same class template. This change
makes sure we don't try to add attributes from API Notes twice.

There is currently no way to annotate specific instantiations using API
Notes.

rdar://142539959
2025-01-15 18:50:23 +00:00
Steven Wu
18650480cb
[clang][Serialization] Add the missing block info (#122976)
HEADER_SEARCH_ENTRY_USAGE and VFS_USAGE were missing from the block info
block. Add the missing info so `llvm-bcanalyzer` can read them
correctly.
2025-01-15 09:58:23 -08:00
Kazu Hirata
1c5f87486a [Driver] Fix a warning
This patch fixes:

  clang/include/clang/Driver/Driver.h:82:3: error: definition of
  implicit copy assignment operator for 'CUIDOptions' is deprecated
  because it has a user-declared copy constructor
  [-Werror,-Wdeprecated-copy]
2025-01-15 08:52:53 -08:00
Sarah Spall
07a184768c
[HLSL] Make bool in hlsl i32 (#122977)
make a bool's memory representation i32 in hlsl
add new test
fix broken test
Closes #122932
2025-01-15 08:39:23 -08:00
Yaxun (Sam) Liu
8ac35bda18
[CUDA][HIP] Support CUID in new driver (#122859)
CUID is needed by CUDA/HIP for supporting accessing static device
variables in host function.

Currently CUID is only supported by the old driver for CUDA/HIP. The new
driver does not support it, which causes CUDA/HIP programs using static
device variables in host functions to fail with the new driver for
CUDA/HIP.

This patch refactors the CUID support in the old driver so that CUID is
supported by both the old and the new drivers for CUDA/HIP.
2025-01-15 10:58:25 -05:00
Kazu Hirata
acdcdbcad9
[Sema] Migrate away from PointerUnion::dyn_cast (NFC) (#123014)
Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect EnumUnderlying to be nonnull.
2025-01-15 07:56:19 -08:00
Kazu Hirata
3a3a1e4627
[CodeGen] Migrate away from PointerUnion::dyn_cast (NFC) (#123013)
Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect Data to be nonnull.
2025-01-15 07:55:52 -08:00
Kazu Hirata
3fd296ece6
[AST] Migrate away from PointerUnion::dyn_cast (NFC) (#123012)
Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect P to be nonnull.
2025-01-15 07:55:28 -08:00
Kiran Chandramohan
44ba43aa2b
Revert "[Flang][Driver] Add a flag to control zero initialization of global v…" (#123067)
Reverts llvm/llvm-project#122144

Reverting due to CI failure
https://lab.llvm.org/buildbot/#/builders/89/builds/14422
2025-01-15 15:23:34 +00:00
Kiran Chandramohan
c593e3d0f7
[Flang][Driver] Add a flag to control zero initialization of global v… (#122144)
…ariables

Patch adds a flag to control zero initialization of global variables
without default initialization. The default is to zero initialize.
2025-01-15 15:06:57 +00:00
Boaz Brickner
6ca560a909
[clang] Add support for passing FileSystem to buildASTFromCodeWithArgs() (#123042)
This would allow tools that don't use the real file system to use this
function.
2025-01-15 14:56:07 +01:00
Un1q32
e00d1dd6ea
[ARM] Fix armv6kz LDREX definition (#122965)
Fixes #37901

This behavior is consistent with GCC
2025-01-15 13:31:54 +00:00
LoS
e33f456ae5
Fixed some warn-override tests in SemaCXX (#122680)
The `.cpp` extension have been added to test files, so that they can be
runned. Besides, the `warn-suggest-override.cpp` tests have been fixed.

---------

Co-authored-by: LoS <aurumpuro@gmail.com>
2025-01-15 12:26:36 +01:00
Victor Campos
85fdf50146
[Multilib] Custom flags YAML parsing (#122903)
This patch is the first step to extend the current multilib system to
support the selection of library variants which do not correspond to
existing command-line options.

Proposal can be found in
https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058

The multilib mechanism supports libraries that target code generation or
language options such as `--target`, `-mcpu`, `-mfpu`,
`-mbranch-protection`. However, some library variants are particular to
features that do not correspond to any command-line options. Examples
include variants for multithreading and semihosting.

This work introduces a way to instruct the multilib system to consider
these features in library selection. This particular patch comprises a
new section in `multilib.yaml` to declare flags for which no option
exists. Henceforth this sort of flag will be called `custom flag` for
clarity.

The `multilib.yaml` file will have a new section called Flags which
contains the declarations of the target’s custom flags:

```yaml
Flags:
- Name: multithreaded
  Values:
  - Name: no-multithreaded
    MacroDefines: [__SINGLE_THREAD__]
  - Name: multithreaded
  Default: no-multithreaded

- Name: io
  Values:
    - Name: io-none
    - Name: io-semihosting
      MacroDefines: [SEMIHOSTING]
    - Name: io-linux-syscalls
      MacroDefines: [LINUX_SYSCALLS, HOSTED=1]
   Default: io-none
```
- Name: the name to categorize a flag.
- Values: a list of possible values.
- Default: it specifies which value this flag should take if not
specified in the command-line invocation. It must be one value from the
Values field.

Each flag Value follows this description:
- Name (required): the name of the custom flag value (string). This is
the string to be used in `-fmultilib-flag=<string>`.
- MacroDefines (optional): a list of strings to be used as macro
definitions. Each string
  is fed into the driver as ``-D<string>``.

A Default value is useful to save users from specifying custom flags
that have a most commonly used value.

The namespace of flag values is common across all flags. This means that
flag values must be unique.
2025-01-15 10:11:39 +00:00
Timm Baeder
4cec0ba929
[clang][bytecode][NFC] Simplify VisitCXXDefaultArgExpr (#123024)
We have `discard()` these days.
2025-01-15 10:09:10 +01:00
Chuanqi Xu
2c34632a99 [C++20] [Modules] [Driver] Support -print-library-module-manifest-path for libstdc++
Given libstdc++ has landed std module, the build systems may need clang
to find the configuration file to understand how to build the std
module. This patch did this. Tested with locally installed GCC-trunk.
2025-01-15 17:01:18 +08:00
Timm Baeder
d1d25641f4
[clang][bytecode] Handle UETT_PtrAuthTypeDiscriminator (#122941) 2025-01-15 08:41:20 +01:00
Chuanqi Xu
7201cae106
[C++20] [Modules] Support module level lookup (#122887)
Close https://github.com/llvm/llvm-project/issues/90154

This patch is also an optimization to the lookup process to utilize the
information provided by `export` keyword.

Previously, in the lookup process, the `export` keyword only takes part
in the check part, it doesn't get involved in the lookup process. That
said, previously, in a name lookup for 'name', we would load all of
declarations with the name 'name' and check if these declarations are
valid or not. It works well. But it is inefficient since it may load
declarations that may not be wanted.

Note that this patch actually did a trick in the lookup process instead
of bring module information to DeclarationName or considering module
information when deciding if two declarations are the same. So it may
not be a surprise to me if there are missing cases. But it is not a
regression. It should be already the case. Issue reports are welcomed.

In this patch, I tried to split the big lookup table into a lookup table
as before and a module local lookup table, which takes a combination of
the ID of the DeclContext and hash value of the primary module name as
the key. And refactored `DeclContext::lookup()` method to take the
module information. So that a lookup in a DeclContext won't load
declarations that are local to **other** modules.

And also I think it is already beneficial to split the big lookup table
since it may reduce the conflicts during lookups in the hash table.

BTW, this patch introduced a **regression** for a reachability rule in
C++20 but it was false-negative. See
'clang/test/CXX/module/module.interface/p7.cpp' for details.

This patch is not expected to introduce any other
regressions for non-c++20-modules users since the module local lookup
table should be empty for them.

---

On the API side, this patch unfortunately add a maybe-confusing argument
`Module *NamedModule` to
`ExternalASTSource::FindExternalVisibleDeclsByName()`. People may think
we can get the information from the first argument `const DeclContext
*DC`. But sadly there are declarations (e.g., namespace) can appear in
multiple different modules as a single declaration. So we have to add
additional information to indicate this.
2025-01-15 15:15:35 +08:00
Nathan Ridge
9ac6a55ec5
[clang][AST] Assert that DependentNameType's Name and NNS are not null (#122418)
Also clarify the comment above DependentNameType::getIdentifier()
2025-01-14 23:06:51 -05:00
Vitaly Buka
e7f756d468
[NFC][BoundsChecking] Address #122576 review comments (#122773) 2025-01-14 18:22:54 -08:00
Kazu Hirata
466753b109
[AST] Avoid repeated map lookups (NFC) (#122858) 2025-01-14 15:26:36 -08:00
Kazu Hirata
a1f8ce683a
[StaticAnalyzer] Migrate away from PointerUnion::dyn_cast (NFC) (#122856)
Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect Storage to be nonnull.
2025-01-14 15:26:08 -08:00
Kazu Hirata
e673f9d00d
[Sema] Migrate away from PointerUnion::dyn_cast (NFC) (#122855)
Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect DeclOrVector to be nonnull.
2025-01-14 15:25:30 -08:00
Kazu Hirata
2b961b0643
[AST] Migrate away from PointerUnion::dyn_cast (NFC) (#122854)
Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //        isa<T>, cast<T> and the llvm::dyn_cast<T>

Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect Source to be nonnull.
2025-01-14 15:25:08 -08:00
Eli Friedman
7aec7caca3 Add explicit triple to test_type.py.
Fixes on 32-bit hosts.
2025-01-14 14:49:45 -08:00
Eli Friedman
1682deed0f
[libclang] Add API to query more information about base classes. (#120300)
The first API is clang_visitCXXBaseClasses: this allows visiting the
base classes without going through the generic child visitor (which is
awkward, and doesn't work for template instantiations).

The second API is clang_getOffsetOfBase; this allows computing the
offset of a base in the class layout, the same way
clang_Cursor_getOffsetOfField computes the offset of a field.

Also, add a Python binding for the existing function
clang_isVirtualBase.
2025-01-14 13:57:44 -08:00
Michael Buch
3d24c77f14
[clang][DebugInfo] Emit DW_AT_object_pointer on function definitions with explicit this (#122897)
We currently don't emit `DW_AT_object_pointer` on function declarations
or definitions. GCC suffers from the same issue:
https://godbolt.org/z/h4jeT54G5

Fixing this will help LLDB in identifying static vs. non-static member
functions (see https://github.com/llvm/llvm-project/issues/120856).

If I interpreted the DWARFv5 spec correctly, it doesn't mandate this
attribute be present *only* for implicit object parameters:
```
If the member function entry describes a non-static member function,
then that entry has a DW_AT_object_pointer attribute whose value is a reference to
the formal parameter entry that corresponds to the object for which the
function is called.

That parameter also has a DW_AT_artificial attribute whose value is true.
```

This patch attaches the `DW_AT_object_pointer` for function
*defintions*. The declarations will be handled in a separate patch.

The part about `DW_AT_artificial` seems overly restrictive, and not true
for explicit object parameters. We probably should relax this part of
the DWARF spec.

Partially fixes https://github.com/llvm/llvm-project/issues/120974
2025-01-14 21:12:13 +00:00
higher-performance
5deabab060
Rename [[clang::requires_explicit_initialization]] to [[clang::require_explicit_initialization]] (#122947)
This makes it consistent with
`[[clang::require_constant_initialization]]`.

(The attribute was just added to Clang a few minutes ago, so there are
no users yet.)
2025-01-14 14:43:41 -05:00
higher-performance
1594413d5e
Add Clang attribute to ensure that fields are initialized explicitly (#102040)
This is a new Clang-specific attribute to ensure that field
initializations are performed explicitly.

For example, if we have
```
struct B {
  [[clang::explicit]] int f1;
};
```
then the diagnostic would trigger if we do `B b{};`:
```
field 'f1' is left uninitialized, but was marked as requiring initialization
```

This prevents callers from accidentally forgetting to initialize fields,
particularly when new fields are added to the class.
2025-01-14 13:31:12 -05:00
Ikhlas Ajbar
71f238a221
[Hexagon] Add missing builtins for V79 (#122916)
This patch adds new builtins that were added in V79 architecture.
2025-01-14 12:21:40 -06:00
Timm Bäder
a0bd40e5a3 Revert "[clang][bytecode] Mark global decls with diagnostics invalid (#122895)"
This reverts commit c1de9b920935e7d2fcc8dd7b39c1b7285783e948.

It looks like this breaks the memory-sanitizer builder:
https://lab.llvm.org/buildbot/#/builders/94/builds/3745
2025-01-14 18:37:36 +01:00
Deric Cheung
06c6baeb52
[HLSL] Implement D3DCOLORtoUBYTE4 intrinsic (#122202)
Fixes #99092.

1. Defines the function `D3DCOLORtoUBYTE4` in
`clang/lib/Headers/hlsl/hlsl_intrinsics.h`.
2. Implements the function `D3DCOLORtoUBYTE4` as `d3d_color_to_ubyte4`
in `clang/lib/Headers/hlsl/hlsl_detail.h`
3. Adds a HLSL codegen test to
`clang/test/CodeGenHLSL/builtins/D3DCOLORtoUBYTE4.hlsl`
4. Adds sema tests to
`clang/test/SemaHLSL/BuiltIns/D3DCOLORtoUBYTE4-errors.hlsl`
2025-01-14 09:11:54 -08:00
Sander de Smalen
97cf5aa1b2
[Clang] Add AArch64 SME changes to release notes (NFC) (#122899) 2025-01-14 16:21:58 +00:00
Timm Baeder
58fa55c04b
[clang][bytecode] Add init link for the RVO ptr (#122904) 2025-01-14 17:18:04 +01:00
sstwcw
fbef1f835f
[clang-format][NFC] Make formatting Verilog faster (#121139)
A regular expression was used in the lexing process. It made the program
take more than linear time with regards to the length of the input. It
looked like the entire buffer could be scanned for every token lexed.
Now the regular expression is replaced with code. Previously it took 20
minutes for the program to format 125 000 lines of code on my computer.
Now it takes 315 milliseconds.
2025-01-14 15:37:06 +00:00
CarolineConcatto
5ec7ecd2f2
[LLVM][AArch64] Add new feature +sme-mop4 and +sme-tmop (#121935)
The 2024-12 ISA spec release[1] add these features:
FEAT_SME_MOP4(sme-mop4) to enable SME Quarter-tile outer product
instructions
and
FEAT_SME_TMOP(sme-tmop) to enable SME Structured sparsity outer product
instructions
to allow these instructions to be available outside Armv9.6/sme2p2

[1]
https://developer.arm.com/Architectures/A-Profile%20Architecture#Downloads
2025-01-14 14:26:08 +00:00
Timm Baeder
c1de9b9209
[clang][bytecode] Mark global decls with diagnostics invalid (#122895)
Even if their evaluation succeeds, mark them as invalid. This fixes some
long standing differences to the ast walker interpeter.
2025-01-14 15:10:48 +01:00