Commit Graph

91718 Commits

Author SHA1 Message Date
Ties Stuij e32b818db1 [ARM][clang] Define feature test macro for the PACBTI-M extension
If the extension string "+pacbti" was given in -march=... or -mcpu=... options the compiler shall define the following preprocessor macros:

    __ARM_FEATURE_PAUTH with value 1.
    __ARM_FEATURE_BTI with value 1.

This patch is part of a series that adds support for the PACBTI-M extension of
the Armv8.1-M architecture, as detailed here:

https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/armv8-1-m-pointer-authentication-and-branch-target-identification-extension

The PACBTI-M specification can be found in the Armv8-M Architecture Reference
Manual:

https://developer.arm.com/documentation/ddi0553/latest

The following people contributed to this patch:

- Momchil Velikov
- Ties Stuij

Reviewed By: miyuki

Differential Revision: https://reviews.llvm.org/D112431
2021-12-09 10:39:06 +00:00
mydeveloperday 2a73a1ac57 [clang-format] PR48916 PointerAlignment not working when using C++20 init-statement in for loop
https://bugs.llvm.org/show_bug.cgi?id=48916

Left and Right Alignment inside a loop is misaligned.

Reviewed By: HazardyKnusperkeks, curdeius

Differential Revision: https://reviews.llvm.org/D115050
2021-12-09 10:37:02 +00:00
Jan Svoboda 13a351e862 [clang][deps] Use MemoryBuffer in minimizing FS
This patch avoids unnecessarily copying contents of `mmap`-ed files into `CachedFileSystemEntry` by storing `MemoryBuffer` instead. The change leads to ~50% reduction of peak memory footprint when scanning LLVM+Clang via `clang-scan-deps`.

Depends on D115331.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D115043
2021-12-09 11:32:13 +01:00
Jan Svoboda d0262c2394 [llvm] Add null-termination capability to SmallVectorMemoryBuffer
Most of `MemoryBuffer` interfaces expose a `RequiresNullTerminator` parameter that's being used to:
* determine how to open a file (`mmap` vs `open`),
* assert newly initialized buffer indeed has an implicit null terminator.

This patch adds the paramater to the `SmallVectorMemoryBuffer` constructors, meaning:
* null terminator can now be added to `SmallVector`s that didn't have one before,
* `SmallVectors` that had a null terminator before keep it even after the move.

In line with existing code, the new parameter is defaulted to `true`. This patch makes sure all calls to the `SmallVectorMemoryBuffer` constructor set it to `false` to preserve the current semantics.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D115331
2021-12-09 11:32:13 +01:00
Martin Storsjö 120d44d1a0 [clang] Fix a misadjusted path style comparison in a unittest
This was changed incorrectly by accident in
9902362701.

Differential Revision: https://reviews.llvm.org/D113254
2021-12-09 11:47:43 +02:00
Jan Svoboda 58822837cd [clang][deps] Use lock_guard instead of unique_lock
This patch changes uses of `std::unique_lock` to `std::lock_guard`.

The `std::unique_lock` template provides some advanced capabilities (deferred locking, time-constrained locking attempts, etc.) we don't use in the caching filesystem. Plain `std::lock_guard` will do here.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D115332
2021-12-09 10:42:50 +01:00
Chuanqi Xu 352e36e10d [Coroutines] Remove unused coroutine builtin/intrinsics llvm.coro.param (NFC-ish)
I found that the coroutine intrinsic llvm.coro.param in documentation
(https://llvm.org/docs/Coroutines.html#id101) didn't get used actually
since there isn't lowering codes in LLVM. I also checked the
implementation of libstdc++ and libc++. Both of them didn't use
llvm.coro.param. So I am pretty sure that the llvm.coro.param intrinsic
is unused. I think it would be better t to remove it to avoid possible
misleading understandings.

Note: according to [class.copy.elision]/p1.3, this optimization is
allowed by the C++ language specification. Let's make it someday.

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D115222
2021-12-09 14:40:25 +08:00
Chuanqi Xu 9791b58951 [C++20 Modules] Don't create global module fragment for extern linkage declaration in GMF already
Previously we would create global module fragment for extern linkage
declaration which is alreday in global module fragment. However, it is
clearly redundant to do so. This patch would check if the extern linkage
declaration are already in GMF before we create a GMF for it.
2021-12-09 13:55:15 +08:00
Duncan P. N. Exon Smith cfd1d49dc0 OpenMP: Avoid using SmallVector::set_size()
Update `OpenMPIRBuilder::collapseLoops()` to call `resize()` instead of
`set_size()`. The latter asserts on capacity limits and cannot grow,
which seems likely to be unintentional here (if it is, I think a local
assertion would be good for clarity).

Also update `CodeGenFunction::EmitOMPCollapsedCanonicalLoopNest()` to
use `pop_back_n()` instead of `set_size()`.

Differential Revision: https://reviews.llvm.org/D115378
2021-12-08 15:22:50 -08:00
Aaron Ballman ca70b807ae Removing some unused parameters from this test; NFC 2021-12-08 08:35:07 -05:00
Jun Zhang 8680f951c2 Add __builtin_elementwise_ceil
This patch implements one of the missing builtin functions specified
in https://reviews.llvm.org/D111529.
2021-12-08 08:29:33 -05:00
Henry Linjamäki 9ae5810b53 [HIPSPV] Convert HIP kernels to SPIR-V kernels
This patch translates HIP kernels to SPIR-V kernels when the HIP
compilation mode is targeting SPIR-S. This involves:

* Setting Cuda calling convention to CC_OpenCLKernel (which maps to
  SPIR_KERNEL in LLVM IR later on).

* Coercing pointer arguments with default address space (AS) qualifier
  to CrossWorkGroup AS (__global in OpenCL). HIPSPV's device code is
  ultimately SPIR-V for OpenCL execution environment (as
  starter/default) where Generic or Function (OpenCL's private) is not
  supported as storage class for kernel pointer types. This leaves the
  CrossWorkGroup to be the only reasonable choice for HIP buffers.

Reviewed By: yaxunl

Differential Revision: https://reviews.llvm.org/D109818
2021-12-08 12:18:15 +03:00
Jan Svoboda 5b6c08379b [clang][deps] Reset some benign codegen options
Some command-line codegen arguments are likely to differ between identical modules discovered from different translation units. This patch removes them to make builds deterministic and/or reduce the number of built modules.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D112923
2021-12-08 11:53:50 +01:00
Hans Wennborg 0a54c325be Add note about inlining dllimport functions to the attribute docs
Differential revision: https://reviews.llvm.org/D115252
2021-12-08 11:15:39 +01:00
Ties Stuij e6d0b851f8 [ARM][libunwind] add PACBTI-M support for libunwind
This patch implements the following:

- Emit PACBTI-M build attributes in libunwind asm files

- Authenticate LR in DWARF32 using PACBTI

Use Armv8.1-M.Main PACBTI extension to authenticate the return address
(stored in the LR register) before moving it to the PC (IP) register.

The AUTG instruction is used with the candidate return address, the CFA,
and the authentication code that is retrieved from the saved
pseudo-register RA_AUTH_CODE.

- Authenticate LR in EHABI using PACBTI

Authenticate the contents of the LR register using Armv8.1-M.Main PACBTI
extension.

A new frame unwinding instruction is introduced (0xb4). This
instruction pops out of the stack the return address authentication
code, which is then used in conjunction with the SP and the next-to-be
instruction pointer to perform authentication.

This authentication code is popped into a new register,
UNW_ARM_PSEUDO_PAC, which is a pseudo-register.

This patch is part of a series that adds support for the PACBTI-M extension of
the Armv8.1-M architecture, as detailed here:

https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/armv8-1-m-pointer-authentication-and-branch-target-identification-extension

The PACBTI-M specification can be found in the Armv8-M Architecture Reference
Manual:

https://developer.arm.com/documentation/ddi0553/latest

The following people contributed to this patch:

- Momchil Velikov
- Victor Campos
- Ties Stuij

Reviewed By: #libunwind, danielkiss, mstorsjo

Differential Revision: https://reviews.llvm.org/D112430
2021-12-08 09:44:45 +00:00
Chuanqi Xu 96b92d5b3e [NFC] Only attach a declaration to global module fragment if it appears in a module 2021-12-08 17:16:31 +08:00
Chuanqi Xu e166755a69 [C++20] [Modules] [Concepts] Recognize same concepts more precisely in Serialization
The compiler would judge two concepts is same by their addresses.
However, when we use modules, the addresses wouldn't be the same all the
time since one is parsed in their TU and another is imported in another
TU.
This patch fixes this by using isSameEntity to judge the two concepts.

Reviewed By: rsmith

Differential Revision: https://reviews.llvm.org/D114769
2021-12-08 15:00:04 +08:00
Chuanqi Xu 4168efe1b2 [NFC] Fix C++20 module test in PPC and warning 2021-12-08 14:25:51 +08:00
Chuanqi Xu 60f826663d [C++20] [Modules] Namespace Declaration shouldn't have module linkage
According to [basic.namespace.general]/p2, a namespace declaration
shouldn't have a module linkage.
> A namespace is never attached to a named module and never has a name
> with module linkage.

Without this patch, the compiler would crash for the test in assertion
enabled build due to inconsistent linkage for redeclaration for
namespaces.

Reviewed by: rsmith

Differential Revision: https://reviews.llvm.org/D115132
2021-12-08 13:54:04 +08:00
Chuanqi Xu e587372f85 [C++20] [Module] Support extern C/C++ semantics
According to [module.unit]p7.2.3, a declaration within a linkage-specification
should be attached to the global module.
This let user to forward declare types across modules.

Reviewed by: rsmith, aaron.ballman

Differential Revision: https://reviews.llvm.org/D110215
2021-12-08 13:29:16 +08:00
lh123 ec64d10340 [clangd] Add desugared type to hover
Add desugared type to hover when the desugared type and the pretty-printed type are different.

```c++
template<typename T>
struct TestHover {
  using Type = T;
};

int main() {
  TestHover<int>::Type a;
}
```

```
variable a

Type: TestHover<int>::Type (aka int)
```

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D114522
2021-12-08 13:28:12 +08:00
Phoebe Wang 4a2c827b17 [X86][clang] Emit diagnostic for float and double when we have features -x87 and -sse on 64-bits
A follow up of D114162.

Reviewed By: asavonic

Differential Revision: https://reviews.llvm.org/D114782
2021-12-08 09:50:26 +08:00
James Farrell 219672b8dd Revert "Revert "Use VersionTuple for parsing versions in Triple, fixing issues that caused the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible.""
This reverts commit 63a6348cad.

Differential Revision: https://reviews.llvm.org/D115254
2021-12-07 23:15:21 +00:00
Yaxun (Sam) Liu d55f05d9f7 [CUDA][HIP] Add pre-defined macro `__CLANG_RDC__`
nvcc defines __CUDACC_RDC__ for both host and
device compilation when -rdc=true is specified
(https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#nvcc-identification-macro)

This patch defines __CLANG_RDC__ when -fgpu-rdc
is specified for CUDA/HIP.

Reviewed by: Artem Belevich

Differential Revision: https://reviews.llvm.org/D114812
2021-12-07 18:08:16 -05:00
Bill Wendling c4582a689c [Analysis] Ignore casts and unary ops for uninitialized values
A series of unary operators and casts may obscure the variable we're
trying to analyze. Ignore them for the uninitialized value analysis.
Other checks determine if the unary operators result in a valid l-value.

Link: https://github.com/ClangBuiltLinux/linux/issues/1521

Reviewed By: nickdesaulniers

Differential Revision: https://reviews.llvm.org/D114848
2021-12-07 11:49:18 -08:00
Corentin Jabot 2334314550 Do not check if we are in a discared context in non-immediate contexts
This fixes in a regression introduced by 6eeda06c1.

When deducing the return type of nested function calls, only the
return type of the outermost expression should be ignored.

Instead of assuming all contextes nested in a discared statements
are themselves discarded, only assume that in immediate contexts.

Similarly, only consider contextes immediately in an immediate or
discarded statement as being themselves immediate.
2021-12-07 12:13:35 -05:00
Aaron Ballman a18632adc8 Add diagnostic groups for attribute extensions
Some users have a need to control attribute extension diagnostics
independent of other extension diagnostics. Consider something like use
of [[nodiscard]] within C++11:
```
[[nodiscard]]
int f();
```
If compiled with -Wc++17-extensions enabled, this will produce warning:
use of the 'nodiscard' attribute is a C++17 extension. This diagnostic
is correct -- using [[nodiscard]] in C++11 mode is a C++17 extension.
And the behavior of __has_cpp_attribute(nodiscard) is also correct --
we support [[nodiscard]] in C++11 mode as a conforming extension. But
this makes use of -Werror or -pedantic-errors` builds more onerous.

This patch adds diagnostic groups for attribute extensions so that
users can selectively disable attribute extension diagnostics. I
believe this is preferable to requiring users to specify additional
flags because it means -Wc++17-extensions continues to be the way we
enable all C++17-related extension diagnostics. It would be quite easy
for someone to use that flag thinking they're protected from some
portability issues without realizing it skipped attribute extensions if
we went the other way.

This addresses PR33518.
2021-12-07 11:49:53 -05:00
Aaron Ballman 7d5315fc4c Fix Sphinx formatting in release notes 2021-12-07 07:56:40 -05:00
Cullen Rhodes 698584f89b [IR] Remove unbounded as possible value for vscale_range minimum
The default for min is changed to 1. The behaviour of -mvscale-{min,max}
in Clang is also changed such that 16 is the max vscale when targeting
SVE and no max is specified.

Reviewed By: sdesmalen, paulwalker-arm

Differential Revision: https://reviews.llvm.org/D113294
2021-12-07 09:52:21 +00:00
Gabor Marton 978431e80b [Analyzer] SValBuilder: Simlify a SymExpr to the absolute simplest form
Move the SymExpr simplification fixpoint logic into SValBuilder.

Differential Revision: https://reviews.llvm.org/D114938
2021-12-07 10:02:32 +01:00
Daniele Castagna abbdc13e68 [CUDA][SPIRV] Use OpenCLKernel CC for CUDA -> SPIRV
Select the OpenCLKernel calling convention for kernels when compiling
CUDA targeting SPIR-V.

In this way the generated LLVM IR will have a spir_kernel calling
convention that will be translated to an OpEntryPoint when converting
to SPIRV.

Reviewed By: jlebar, tra

Differential Revision: https://reviews.llvm.org/D114407
2021-12-06 15:06:57 -08:00
Yaxun (Sam) Liu 3b172f60c6 [HIP] Fix -fgpu-rdc for Windows
This patch fixes issues for -fgpu-rdc for Windows MSVC
toolchain:

Fix COFF specific section flags and remove section types
in llvm-mc input file for Windows.

Escape fatbin path in llvm-mc input file.

Add -triple option to llvm-mc.

Put __hip_gpubin_handle in comdat when it has linkonce_odr
linkage.

Reviewed by: Artem Belevich

Differential Revision: https://reviews.llvm.org/D115039
2021-12-06 16:42:23 -05:00
Balázs Kéri 341a30a4ba [clang][ASTImporter] Update lookup table correctly at deduction guides.
Declaration context of template parameters of a FunctionTemplateDecl
may be different for each one parameter if the template is a
deduction guide. This case is handled correctly after this change.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D114418
2021-12-06 20:40:16 +01:00
Nick Desaulniers 73ee4e1cbd [clang][ARM] only check -mtp=cp15 for non-asm sources
This diagnostic is really to highlight lack of support for hard thread
pointers in post-RA instruction scheduling for non-armv6k+ targets;
something that isn't run for assembler sources.

Fixes: https://github.com/ClangBuiltLinux/linux/issues/1502
Link: https://lore.kernel.org/all/814585495.6773.1636629846970@jenkins.jenkins/

Reviewed By: ardb

Differential Revision: https://reviews.llvm.org/D114124
2021-12-06 11:31:23 -08:00
Aaron Ballman ead449aee4 Fixing this test which failed due to different warnings 2021-12-06 14:13:29 -05:00
Aaron Ballman 0ef8ad08db Fix a failing test case after 6c75ab5f66
The test is the same whether it's testing _BitInt or _ExtInt, so use
the type which is not deprecated.
2021-12-06 13:53:43 -05:00
Aaron Ballman 1f257accd7 Speculatively fix the LLDB build bots from 6c75ab5f66
It looks like some renames got missed.
2021-12-06 13:30:15 -05:00
Aaron Ballman 1feb8ab0d3 Update the status of N2412 in C (we do not implement large parts of it) 2021-12-06 13:14:13 -05:00
Martin Probst 327d966365 clang-format: [JS] test case for numeric separators.
ES2021 allows numeric literals using `_` as a separator. This already
works, but had no test.

Differential Revision: https://reviews.llvm.org/D115147
2021-12-06 19:01:24 +01:00
Aaron Ballman 6c75ab5f66 Introduce _BitInt, deprecate _ExtInt
WG14 adopted the _ExtInt feature from Clang for C23, but renamed the
type to be _BitInt. This patch does the vast majority of the work to
rename _ExtInt to _BitInt, which accounts for most of its size. The new
type is exposed in older C modes and all C++ modes as a conforming
extension. However, there are functional changes worth calling out:

* Deprecates _ExtInt with a fix-it to help users migrate to _BitInt.
* Updates the mangling for the type.
* Updates the documentation and adds a release note to warn users what
is going on.
* Adds new diagnostics for use of _BitInt to call out when it's used as
a Clang extension or as a pre-C23 compatibility concern.
* Adds new tests for the new diagnostic behaviors.

I want to call out the ABI break specifically. We do not believe that
this break will cause a significant imposition for early adopters of
the feature, and so this is being done as a full break. If it turns out
there are critical uses where recompilation is not an option for some
reason, we can consider using ABI tags to ease the transition.
2021-12-06 12:52:01 -05:00
Balazs Benics a6816b957d [analyzer][solver] Fix assertion on (NonLoc, Op, Loc) expressions
Previously, the `SValBuilder` could not encounter expressions of the
following kind:

  NonLoc OP Loc
  Loc OP NonLoc

Where the `Op` is other than `BO_Add`.

As of now, due to the smarter simplification and the fixedpoint
iteration, it turns out we can.
It can happen if the `Loc` was perfectly constrained to a concrete
value (`nonloc::ConcreteInt`), thus the simplifier can do
constant-folding in these cases as well.

Unfortunately, this could cause assertion failures, since we assumed
that the operator must be `BO_Add`, causing a crash.

---

In the patch, I decided to preserve the original behavior (aka. swap the
operands (if the operator is commutative), but if the `RHS` was a
`loc::ConcreteInt` call `evalBinOpNN()`.

I think this interpretation of the arithmetic expression is closer to
reality.

I also tried naively introducing a separate handler for
`loc::ConcreteInt` RHS, before doing handling the more generic `Loc` RHS
case. However, it broke the `zoo1backwards()` test in the `nullptr.cpp`
file. This highlighted for me the importance to preserve the original
behavior for the `BO_Add` at least.

PS: Sorry for introducing yet another branch into this `evalBinOpXX`
madness. I've got a couple of ideas about refactoring these.
We'll see if I can get to it.

The test file demonstrates the issue and makes sure nothing similar
happens. The `no-crash` annotated lines show, where we crashed before
applying this patch.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D115149
2021-12-06 18:38:58 +01:00
James Farrell 63a6348cad Revert "Use VersionTuple for parsing versions in Triple, fixing issues that caused the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible."
This reverts commit 5032467034.
2021-12-06 17:35:26 +00:00
Jonas Devlieghere 4cb79294e8 Revert "[clang][DebugInfo] Allow function-local statics and types to be scoped within a lexical block"
This reverts commit e403f4fdc8 because it
breaks TestSetData.py on GreenDragon:

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/39089/
2021-12-06 09:34:53 -08:00
Jon Chesterfield 6bb2a4f3e6 [openmp] Default to new rtl for amdgpu
Reverts D114965 as the compiler backend appears to be working again

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D115157
2021-12-06 16:56:14 +00:00
Simon Moll f6ba645039 Revert "[Clang] Ignore CLANG_DEFAULT_LINKER for custom-linker toolchains"
Reverted until all Toolchains are fixed for the new behavior.

This reverts commit 34a43f2115.
2021-12-06 16:44:36 +01:00
Ties Stuij 53154a83ae [ARM][clang] Add back branch protection tests
When committing the PACBTI-M frontend support
patch (https://reviews.llvm.org/D112421), the tests in
arm-invalid-branch-protection.c were failing on certain test setups, so it was
removed to make the llvm test suite pass. The fix is to require
arm-registered-target.

This patch is part of a series that adds support for the PACBTI-M extension of
the Armv8.1-M architecture, as detailed here:

https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/armv8-1-m-pointer-authentication-and-branch-target-identification-extension

The PACBTI-M specification can be found in the Armv8-M Architecture Reference
Manual:

https://developer.arm.com/documentation/ddi0553/latest

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D115141
2021-12-06 15:03:33 +00:00
James Farrell 5032467034 Use VersionTuple for parsing versions in Triple, fixing issues that caused the original change to be reverted. This makes it possible to distinguish between "16" and "16.0" after parsing, which previously was not possible.
This reverts commit 40d5eeac6c.

Differential Revision: https://reviews.llvm.org/D114885
2021-12-06 14:57:47 +00:00
Simon Moll 34a43f2115 [Clang] Ignore CLANG_DEFAULT_LINKER for custom-linker toolchains
Before, the CLANG_DEFAULT_LINKER cmake option was a global override for
the linker that shall be used on all toolchains.  The linker binary
specified that way may not be available on toolchains with custom
linkers. Eg, the only linker for VE is named 'nld' - any other linker
invalidates the toolchain.

This patch removes the hard override and instead lets the generic
toolchain implementation default to CLANG_DEFAULT_LINKER.  Toolchains
can now deviate with a custom linker name or deliberatly default to
CLANG_DEFAULT_LINKER.

Reviewed By: MaskRay, phosek

Differential Revision: https://reviews.llvm.org/D115045
2021-12-06 13:31:51 +01:00
Dmitri Gribenko ab31d003e1 [clang][docs][dataflow] Added an introduction to dataflow analysis
This documentation supports the dataflow analysis framework (see "[RFC]
A dataflow analysis framework for Clang AST" on cfe-dev).

Since the implementation of the framework has not been committed yet,
right now the doc describes dataflow analysis in general.

Since this is the first markdown document in clang/docs, I added support
for Markdown to clang/docs/conf.py in the same way as it is done in
llvm/docs.

Reviewed By: xazax.hun

Differential Revision: https://reviews.llvm.org/D114231
2021-12-06 12:16:35 +01:00
Ties Stuij 0fbb17458a [ARM] Implement setjmp BTI placement for PACBTI-M
This patch intends to guard indirect branches performed by longjmp
by inserting BTI instructions after calls to setjmp.

Calls with 'returns-twice' are lowered to a new pseudo-instruction
named t2CALL_BTI that is later expanded to a bundle of {tBL,t2BTI}.

This patch is part of a series that adds support for the PACBTI-M extension of
the Armv8.1-M architecture, as detailed here:

https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/armv8-1-m-pointer-authentication-and-branch-target-identification-extension

The PACBTI-M specification can be found in the Armv8-M Architecture Reference
Manual:

https://developer.arm.com/documentation/ddi0553/latest

The following people contributed to this patch:

- Alexandros Lamprineas
- Ties Stuij

Reviewed By: labrinea

Differential Revision: https://reviews.llvm.org/D112427
2021-12-06 11:07:10 +00:00