Commit Graph

96393 Commits

Author SHA1 Message Date
Joseph Huber 937aaead87 [CUDA] Fix arguments after removing unused private variable
Summary:
A previous patch removed the use of the `OK` private variable in CUDA
which resulted in usused variable warnings. this was fixed in
f886f7e8ef but did not change the
constructor to accurately represent its removal. This patch removes it
from the interface entirely.
2022-08-26 15:28:34 -05:00
Sterling Augustine f886f7e8ef Remove unused private variable. 2022-08-26 12:43:05 -07:00
Sterling Augustine 5eab94f7eb Eliminate unused-variable warning. 2022-08-26 12:40:55 -07:00
ziqingluo-90 a5e354ec4d [analyzer] Fixing a bug raising false positives of stack block object
leaking in ARC mode

When ARC (automatic reference count) is enabled, (objective-c) block
objects are automatically retained and released thus they do not leak.
Without ARC, they still can leak from an expiring stack frame like
other stack variables.
With this commit, the static analyzer now puts a block object in an
"unknown" region if ARC is enabled because it is up to the
implementation to choose whether to put the object on stack initially
(then move to heap when needed) or in heap directly under ARC.
Therefore, the `StackAddrEscapeChecker` has no need to know
specifically about ARC at all and it will not report errors on objects
in "unknown" regions.

Reviewed By: NoQ (Artem Dergachev)

Differential Revision: https://reviews.llvm.org/D131009
2022-08-26 12:19:32 -07:00
Abraham Corea Diaz 82e893c47c [clang] Enable output of SARIF diagnostics
Enables Clang to emit diagnostics in SARIF format when
`-fdiagnostics-format=sarif`. Adds a new DiagnosticConsumer named
SARIFDiagnosticPrinter and a new DiagnosticRenderer named SARIFDiagnostic
to constuct and emit a SARIF object containing the run's basic diagnostic info.

Reviewed By: cjdb, denik, aaron.ballman

Differential Revision: https://reviews.llvm.org/D131632
2022-08-26 18:49:29 +00:00
Joseph Huber 47166968db [OpenMP] Deprecate the old driver for OpenMP offloading
Recently OpenMP has transitioned to using the "new" driver which
primarily merges the device and host linking phases into a single
wrapper that handles both at the same time. This replaced a few tools
that were only used for OpenMP offloading, such as the
`clang-offload-wrapper` and `clang-nvlink-wrapper`. The new driver
carries some marked benefits compared to the old driver that is now
being deprecated. Things like device-side LTO, static library
support, and more compatible tooling. As such, we should be able to
completely deprecate the old driver, at least for OpenMP. The old driver
support will still exist for CUDA and HIP, although both of these can
currently be compiled on Linux with `--offload-new-driver` to use the new
method.

Note that this does not deprecate the `clang-offload-bundler`, although
it is unused by OpenMP now, it is still used by the HIP toolchain both
as their device binary format and object format.

When I proposed deprecating this code I heard some vendors voice
concernes about needing to update their code in their fork. They should
be able to just revert this commit if it lands.

Reviewed By: jdoerfert, MaskRay, ye-luo

Differential Revision: https://reviews.llvm.org/D130020
2022-08-26 13:47:09 -05:00
Leonard Chan cdb30f7a26 [clang] Do not instrument the rtti_proxies under hwasan
We run into a duplicate symbol error when instrumenting the rtti_proxies
generated as part of the relative vtables ABI with hwasan:

```
ld.lld: error: duplicate symbol: typeinfo for icu_71::UObject
(.rtti_proxy)
>>> defined at brkiter.cpp
>>>
arm64-hwasan-shared/obj/third_party/icu/source/common/libicuuc.brkiter.cpp.o:(typeinfo
for icu_71::UObject (.rtti_proxy))
>>> defined at locavailable.cpp
>>>
arm64-hwasan-shared/obj/third_party/icu/source/common/libicuuc.locavailable.cpp.o:(.data.rel.ro..L_ZTIN6icu_717UObjectE.rtti_proxy.hwasan+0xE00000000000000)
```

The issue here is that the hwasan alias carries over the visibility and
linkage of the original proxy, so we have duplicate external symbols
that participate in linking. Similar to D132425 we can just disable
hwasan for the proxies for now.

Differential Revision: https://reviews.llvm.org/D132691
2022-08-26 18:22:17 +00:00
Leonard Chan 93e5cf6b9c [clang] Do not instrument relative vtables under hwasan
Full context in
https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=107017.

Instrumenting hwasan with globals results in a linker error under the
relative vtables abi:

```
ld.lld: error:
libunwind.cpp:(.rodata..L_ZTVN9libunwind12UnwindCursorINS_17LocalAddressSpaceENS_15Registers_arm64EEE.hwasan+0x8):
relocation R_AARCH64_PLT32 out of range: 6845471433603167792 is not in
[-2147483648, 2147483647]; references
libunwind::AbstractUnwindCursor::~AbstractUnwindCursor()
>>> defined in
libunwind/src/CMakeFiles/unwind_shared.dir/libunwind.cpp.obj
```

This is because the tag is included in the vtable address when
calculating the offset between the vtable and virtual function. A
temporary solution until we can resolve this is to just disable hwasan
instrumentation on relative vtables specifically, which can be done in
the frontend.

Differential Revision: https://reviews.llvm.org/D132425
2022-08-26 18:21:40 +00:00
Shafik Yaghmour 21dfe482e1 [Clang] Fix assert in Sema::LookupTemplateName so that it does not attempt an unconditional cast to TagType
In Sema::LookupTemplateName(...) seeks to assert that the ObjectType is complete
or being defined. If the type is incomplete it will attempt to unconditionally
cast it to a TagType and not all incomplete types are a TagType. For example the
type could be void or it could be an IncompleteArray.

This change adds an additional check to confirm it is a TagType before attempting
to check if it is incomplete or being defined

Differential Revision: https://reviews.llvm.org/D132712
2022-08-26 09:40:43 -07:00
Xiang Li a0ecb4a299 [HLSL] Move DXIL validation version out of ModuleFlags
Put DXIL validation version into separate NamedMetadata to avoid update ModuleFlags.

Currently DXIL validation version is saved in ModuleFlags in clang codeGen.
Then in DirectX backend, the data will be extracted from ModuleFlags and cause rebuild of ModuleFlags.
This patch will build NamedMetadata for DXIL validation version and remove the code to rebuild ModuleFlags.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D130207
2022-08-26 09:20:45 -07:00
Corentin Jabot 463e30f51f [Clang] Fix crash in coverage of if consteval.
Clang crashes when encountering an `if consteval` statement.
This is the minimum fix not to crash.
The fix is consistent with the current behavior of if constexpr,
which does generate coverage data for the discarded branches.
This is of course not correct and a better solution is
needed for both if constexpr and if consteval.
See https://github.com/llvm/llvm-project/issues/54419.

Fixes #57377

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D132723
2022-08-26 17:46:53 +02:00
Aaron Ballman be19952720 Fix the lldb test bots
This addresses an accidental change in behavior from
41667a8b9b to get the bots back to green.
However, I think there's an issue with LLDB assuming it's valid to
enable support for keywords in language modes that don't support the
keyword (as other parts of Clang are not expecting to be able to do
that).

This should fix (and others):
https://lab.llvm.org/buildbot/#/builders/68/builds/38374
2022-08-26 11:19:42 -04:00
Aaron Ballman 8360174fb1 Fix the Sphinx build bot
This addresses an accidental break from
41667a8b9b
2022-08-26 10:04:57 -04:00
Benjamin Kramer 01bebedaf0 [Basic] Drop header-only dependency from Basic to Lex
It's still a bit weird for IdentifierTable to depend on Lex diagnostics,
but we can get away with including the enum info that's in Basic already.
2022-08-26 16:03:22 +02:00
Muhammad Usman Shahid 41667a8b9b Diagnosing the Future Keywords
The patch diagnoses an identifier as a future keyword if it exists in a
future language mode, such as:

int restrict;

in C modes earlier than C99. We now give a warning to the user that
such an identifier is a future keyword. Handles keywords from C as well
as C++.

Differential Revision: https://reviews.llvm.org/D131683
2022-08-26 09:20:05 -04:00
Utkarsh Saxena 80e7dec561 Typo fix in Release notes. 2022-08-26 14:36:45 +02:00
Matheus Izvekov 4a56470d0d
Revert "Clang: fix AST representation of expanded template arguments."
This reverts commit 1d1a56929b.
2022-08-26 13:09:55 +02:00
Pavel Samolysov f964417c32 Revert "[Pipelines] Introduce DAE after ArgumentPromotion"
The commit breaks the compiler when a function is used as a function
parameter (hm... for a function from the standard C library?):

```
static float strtof(char *, char *) {}
void a() { strtof(a, 0); }
```

This reverts commit 879f5118fc.
2022-08-26 13:43:09 +03:00
Utkarsh Saxena 4a043c6376 PotentiallyEvaluatedContext in a ImmediateFunctionContext.
Body of `consteval` should be in an `ImmediateFunctionContext` instead of `ConstantEvaluated`.
PotentiallyEvaluated expressions in Immediate functions are in a `ImmediateFunctionContext` as well.

Fixes https://github.com/llvm/llvm-project/issues/51182
Original divergence: https://godbolt.org/z/vadGT5j6f

Differential Revision: https://reviews.llvm.org/D132659
2022-08-26 10:30:10 +02:00
Ilya Biryukov 5fef4c6d39 [clang] NFC. Small tweak to release notes
Forgotten in the last patch.
2022-08-26 10:17:44 +02:00
Luke Nihlen 7aa3270622 [clang] Add cxx scope if needed for requires clause.
Fixes issue #55216.

Patch by Luke Nihlen! (luken@google.com, luken-google@)

Reviewed By: #clang-language-wg, aaron.ballman

Differential Revision: https://reviews.llvm.org/D132503
2022-08-26 10:15:54 +02:00
Chuanqi Xu 17631ac676 [Coroutines] Store the index for final suspend point if there is unwind coro end
Closing https://github.com/llvm/llvm-project/issues/57339

The root cause for this issue is an pre-mature optimization to eliminate
the index for the final suspend point since we feel like we can judge
if a coroutine is suspended at the final suspend by if resume_fn_addr is
null. However this is not true if the coroutine exists via an exception
in promise.unhandled_exception(). According to
[dcl.fct.def.coroutine]p14:

> If the evaluation of the expression promise.unhandled_exception()
> exits via an exception, the coroutine is considered suspended at the
> final suspend point.

But from the perspective of the implementation, we can't set the coro
index to the final suspend point directly since it breaks the states.

To fix the issue, we block the optimization if we find there is any
unwind coro end, which indicates that it is possible that the coroutine
exists via an exception from promise.unhandled_exception().

Test Plan: folly
2022-08-26 14:05:46 +08:00
owenca 8712ed5af1 [clang-format][NFC] Call eof() and isEOF() in UnwrappedLineParser 2022-08-25 22:07:03 -07:00
Fangrui Song 1f5215668a [Driver][test] Replace legacy -target with --target= 2022-08-25 19:30:21 -07:00
Chris Bieneman 18385cffc5 [HLSL] Add abs library function
This change exposes the abs library function for HLSL scalar types. Abs
is supported for all scalar, vector and matrix types. This patch only
adds a subset of scalar type support.

Fixes #57100 (https://llvm.org/pr57100)

The full documentation of the HLSL abs function is available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-abs

Reviewed By: bogner

Differential Revision: https://reviews.llvm.org/D131718
2022-08-25 18:56:51 -05:00
Hsiangkai Wang a869014305 [AArch64] Filter out invalid code model in frontend.
AArch64 only supports tiny, small, and large code model. Show error
messages when users specify other code model.

Fix https://github.com/llvm/llvm-project/issues/53402

Differential Revision: https://reviews.llvm.org/D132538
2022-08-25 23:28:28 +00:00
Roy Jacobson b1c960fc6d [Clang] Implement P0848 (Conditionally Trivial Special Member Functions)
This patch implements P0848 in Clang.

During the instantiation of a C++ class, in `Sema::ActOnFields`, we evaluate constraints for all the SMFs and compare the constraints to compute the eligibility. We defer the computation of the type's [copy-]trivial bits from addedMember to the eligibility computation, like we did for destructors in D126194. `canPassInRegisters` is modified as well to better respect the ineligibility of functions.

Note: Because of the non-implementation of DR1734 and DR1496, I treat deleted member functions as 'eligible' for the purpose of [copy-]triviallity. This is unfortunate, but I couldn't think of a way to make this make sense otherwise.

Reviewed By: #clang-language-wg, cor3ntin, aaron.ballman

Differential Revision: https://reviews.llvm.org/D128619
2022-08-26 00:52:52 +03:00
Chris Bieneman 22c477f934 [HLSL] Initial codegen for SV_GroupIndex
Semantic parameters aren't passed as actual parameters, instead they are
populated from intrinsics which are generally lowered to reads from
dedicated hardware registers.

This change modifies clang CodeGen to emit the intrinsic calls and
populate the parameter's LValue with the result of the intrinsic call
for SV_GroupIndex.

The result of this is to make the actual passed argument ignored, which
will make it easy to clean up later in an IR pass.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D131203
2022-08-25 11:17:54 -05:00
John Ericson 34fe6ddce1 Revert "[CMake] Avoid `LLVM_BINARY_DIR` when other more specific variable are better-suited"
This reverts commit ad8c34bc30.
2022-08-25 11:13:46 -04:00
David Majnemer bd28bd59a3 [clang-cl] /kernel should toggle bit 30 in @feat.00
The linker is supposed to detect when an object with /kernel is linked
with another object which is not compiled with /kernel. The linker
detects this by checking bit 30 in @feat.00.
2022-08-25 14:17:26 +00:00
Ben Langmuir c0a5512161 [clang][deps] Minor ModuleDepCollector refactorings NFC
* Factor module map and module file path functions out
* Use a secondary mapping to lookup module deps by ID instead of the
  preprocessor module map.
* Sink DirectPrebuiltModularDeps into MDC.

Differential Revision: https://reviews.llvm.org/D132617
2022-08-25 06:51:06 -07:00
Benjamin Kramer 9be8630ca9 Add a missing override keyword. NFC.
clang/lib/Basic/Targets/X86.h:293:8: warning: 'shouldEmitFloat16WithExcessPrecision' overrides a member function but is not marked 'override' [-Winconsistent-missing-override]
  bool shouldEmitFloat16WithExcessPrecision() const {
       ^
clang/include/clang/Basic/TargetInfo.h:915:16: note: overridden virtual function is here
  virtual bool shouldEmitFloat16WithExcessPrecision() const { return false; }
               ^
2022-08-25 14:50:28 +02:00
Zahira Ammarguellat 5def954a5b Support of expression granularity for _Float16.
Differential Revision: https://reviews.llvm.org/D113107
2022-08-25 08:26:53 -04:00
Timm Bäder fdfc0dfa8e [clang][Interp] Implement pointer (de)ref operators
Implement pointer references, dereferences and assignments.

Differential Revision: https://reviews.llvm.org/D132111
2022-08-25 14:20:32 +02:00
isuckatcs e3e9082b01 [analyzer] Fix for incorrect handling of 0 length non-POD array construction
Prior to this patch when the analyzer encountered a non-POD 0 length array,
it still invoked the constructor for 1 element, which lead to false positives.
This patch makes sure that we no longer construct any elements when we see a
0 length array.

Differential Revision: https://reviews.llvm.org/D131501
2022-08-25 12:42:02 +02:00
Tobias Hieta 5218a542ac
[NFC] Fix a misleading comment CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION 2022-08-25 09:56:55 +02:00
Pavel Samolysov 879f5118fc [Pipelines] Introduce DAE after ArgumentPromotion
The ArgumentPromotion pass uses Mem2Reg promotion at the end to cutting
down generated `alloca` instructions as well as meaningless `store`s and
this behavior can leave unused (dead) arguments. To eliminate the dead
arguments and therefore let the DeadCodeElimination remove becoming dead
inserted `GEP`s as well as `load`s and `cast`s in the callers, the
DeadArgumentElimination pass should be run after the ArgumentPromotion
one.

Differential Revision: https://reviews.llvm.org/D128830
2022-08-25 10:55:47 +03:00
H. Vetinari 0f28d48566
SONAME introduce option CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION
This reverts commit bc39d7bdd4.

rename CLANG_SONAME to LIBCLANG_SOVERSION

[clang][cmake] introduce option CLANG_FORCE_MATCHING_LIBCLANG_SOVERSION

Differential Revision: https://reviews.llvm.org/D132486
2022-08-25 08:36:01 +02:00
Roy Jacobson 70770a16bc Revert "[Clang] Implement P0848 (Conditionally Trivial Special Member Functions)"
See bug report here: https://github.com/llvm/llvm-project/issues/57351
This reverts commit 7171615099.
2022-08-25 09:11:06 +03:00
Ben Langmuir e8febb23a0 [clang][deps] Remove CompilerInvocation from ModuleDeps
The invocation is only ever used to serialize cc1 arguments from, so
instead serialize the arguments inside the dep scanner to simplify the
interface.

Differential Revision: https://reviews.llvm.org/D132616
2022-08-24 19:51:12 -07:00
Ben Langmuir bdc20d61b8 [clang][tooling] Allow -cc1 arguments in ToolInvocation
ToolInvocation is useful even if you already have a -cc1 invocation,
since it provides a standard way to setup diagnostics, parse arguments,
and handoff to a ToolAction. So teach it to support -cc1 commands by
skipping the driver bits.

Differential Revision: https://reviews.llvm.org/D132615
2022-08-24 19:51:12 -07:00
Sami Tolvanen cff5bef948 KCFI sanitizer
The KCFI sanitizer, enabled with `-fsanitize=kcfi`, implements a
forward-edge control flow integrity scheme for indirect calls. It
uses a !kcfi_type metadata node to attach a type identifier for each
function and injects verification code before indirect calls.

Unlike the current CFI schemes implemented in LLVM, KCFI does not
require LTO, does not alter function references to point to a jump
table, and never breaks function address equality. KCFI is intended
to be used in low-level code, such as operating system kernels,
where the existing schemes can cause undue complications because
of the aforementioned properties. However, unlike the existing
schemes, KCFI is limited to validating only function pointers and is
not compatible with executable-only memory.

KCFI does not provide runtime support, but always traps when a
type mismatch is encountered. Users of the scheme are expected
to handle the trap. With `-fsanitize=kcfi`, Clang emits a `kcfi`
operand bundle to indirect calls, and LLVM lowers this to a
known architecture-specific sequence of instructions for each
callsite to make runtime patching easier for users who require this
functionality.

A KCFI type identifier is a 32-bit constant produced by taking the
lower half of xxHash64 from a C++ mangled typename. If a program
contains indirect calls to assembly functions, they must be
manually annotated with the expected type identifiers to prevent
errors. To make this easier, Clang generates a weak SHN_ABS
`__kcfi_typeid_<function>` symbol for each address-taken function
declaration, which can be used to annotate functions in assembly
as long as at least one C translation unit linked into the program
takes the function address. For example on AArch64, we might have
the following code:

```
.c:
  int f(void);
  int (*p)(void) = f;
  p();

.s:
  .4byte __kcfi_typeid_f
  .global f
  f:
    ...
```

Note that X86 uses a different preamble format for compatibility
with Linux kernel tooling. See the comments in
`X86AsmPrinter::emitKCFITypeId` for details.

As users of KCFI may need to locate trap locations for binary
validation and error handling, LLVM can additionally emit the
locations of traps to a `.kcfi_traps` section.

Similarly to other sanitizers, KCFI checking can be disabled for a
function with a `no_sanitize("kcfi")` function attribute.

Relands 67504c9549 with a fix for
32-bit builds.

Reviewed By: nickdesaulniers, kees, joaomoreira, MaskRay

Differential Revision: https://reviews.llvm.org/D119296
2022-08-24 22:41:38 +00:00
Benjamin Kramer bbf19a6745 [AST] Use std::apply to pop front of tuples. NFCI. 2022-08-25 00:03:08 +02:00
Adrian Vogelsgesang 91389000ab [LLDB] Add data formatter for std::coroutine_handle
This patch adds a formatter for `std::coroutine_handle`, both for libc++
and libstdc++. For the type-erased `coroutine_handle<>`, it shows the
`resume` and `destroy` function pointers. For a non-type-erased
`coroutine_handle<promise_type>` it also shows the `promise` value.

With this change, executing the `v t` command on the example from
https://clang.llvm.org/docs/DebuggingCoroutines.html now outputs

```
(task) t = {
  handle = coro frame = 0x55555555b2a0 {
    resume = 0x0000555555555a10 (a.out`coro_task(int, int) at llvm-example.cpp:36)
    destroy = 0x0000555555556090 (a.out`coro_task(int, int) at llvm-example.cpp:36)
  }
}
```

instead of just

```
(task) t = {
  handle = {
    __handle_ = 0x55555555b2a0
  }
}
```

Note, how the symbols for the `resume` and `destroy` function pointer
reveal which coroutine is stored inside the `std::coroutine_handle`.
A follow-up commit will use this fact to infer the coroutine's promise
type and the representation of its internal coroutine state based on
the `resume` and `destroy` pointers.

The same formatter is used for both libc++ and libstdc++. It would
also work for MSVC's standard library, however it is not registered
for MSVC, given that lldb does not provide pretty printers for other
MSVC types, either.

The formatter is in a newly added  `Coroutines.{h,cpp}` file because there
does not seem to be an already existing place where we could share
formatters across libc++ and libstdc++. Also, I expect this code to grow
as we improve debugging experience for coroutines further.

**Testing**

* Added API test

Differential Revision: https://reviews.llvm.org/D132415
2022-08-24 14:40:53 -07:00
Jan Svoboda 94e64df576 [clang][modules] Consider M affecting after mapping M.Private to M_Private
When Clang encounters `@import M.Private` during implicit build, it precompiles module `M` and looks through its submodules. If the `Private` submodule is not found, Clang assumes `@import M_Private`. In the dependency scanner, we don't capture the dependency on `M`, since it's not imported. It's an affecting module, though: compilation of the import statement will fail when implicit modules are disabled and `M` is not precompiled and explicitly provided. This patch fixes that.

Depends on D132430.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D132502
2022-08-24 14:36:06 -07:00
Chris Bieneman bdf1327fea [HLSL] Entry functions require param annotation
HLSL entry function parameters must have parameter annotations. This
allows appropriate intrinsic values to be populated into parameters
during code generation.

This does not handle entry function return values, which will be
handled in a subsequent commit because we don't currently support any
annotations that are valid for function returns.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D131625
2022-08-24 14:35:11 -05:00
Sami Tolvanen a79060e275 Revert "KCFI sanitizer"
This reverts commit 67504c9549 as using
PointerEmbeddedInt to store 32 bits breaks 32-bit arm builds.
2022-08-24 19:30:13 +00:00
Sami Tolvanen 67504c9549 KCFI sanitizer
The KCFI sanitizer, enabled with `-fsanitize=kcfi`, implements a
forward-edge control flow integrity scheme for indirect calls. It
uses a !kcfi_type metadata node to attach a type identifier for each
function and injects verification code before indirect calls.

Unlike the current CFI schemes implemented in LLVM, KCFI does not
require LTO, does not alter function references to point to a jump
table, and never breaks function address equality. KCFI is intended
to be used in low-level code, such as operating system kernels,
where the existing schemes can cause undue complications because
of the aforementioned properties. However, unlike the existing
schemes, KCFI is limited to validating only function pointers and is
not compatible with executable-only memory.

KCFI does not provide runtime support, but always traps when a
type mismatch is encountered. Users of the scheme are expected
to handle the trap. With `-fsanitize=kcfi`, Clang emits a `kcfi`
operand bundle to indirect calls, and LLVM lowers this to a
known architecture-specific sequence of instructions for each
callsite to make runtime patching easier for users who require this
functionality.

A KCFI type identifier is a 32-bit constant produced by taking the
lower half of xxHash64 from a C++ mangled typename. If a program
contains indirect calls to assembly functions, they must be
manually annotated with the expected type identifiers to prevent
errors. To make this easier, Clang generates a weak SHN_ABS
`__kcfi_typeid_<function>` symbol for each address-taken function
declaration, which can be used to annotate functions in assembly
as long as at least one C translation unit linked into the program
takes the function address. For example on AArch64, we might have
the following code:

```
.c:
  int f(void);
  int (*p)(void) = f;
  p();

.s:
  .4byte __kcfi_typeid_f
  .global f
  f:
    ...
```

Note that X86 uses a different preamble format for compatibility
with Linux kernel tooling. See the comments in
`X86AsmPrinter::emitKCFITypeId` for details.

As users of KCFI may need to locate trap locations for binary
validation and error handling, LLVM can additionally emit the
locations of traps to a `.kcfi_traps` section.

Similarly to other sanitizers, KCFI checking can be disabled for a
function with a `no_sanitize("kcfi")` function attribute.

Reviewed By: nickdesaulniers, kees, joaomoreira, MaskRay

Differential Revision: https://reviews.llvm.org/D119296
2022-08-24 18:52:42 +00:00
Jan Svoboda 002bfdd6b1 [clang][modules] Track affecting modules
When compiling a module, its semantics and Clang's behavior are affected by other modules. These modules are typically the **imported** ones. However, during implicit build, some modules end up being compiled and read without being actually imported. This patch starts tracking such modules and serializing them into `.pcm` files. This enables the dependency scanner to construct explicit compilations that mimic implicit build.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D132430
2022-08-24 11:09:50 -07:00
Petr Hosek 74af56c1c3 [Clang] Avoid using unwind library in the MSVC environment
We're seeing the following warnings with --rtlib=compiler-rt:

  lld-link: warning: ignoring unknown argument '--as-needed'
  lld-link: warning: ignoring unknown argument '-lunwind'
  lld-link: warning: ignoring unknown argument '--no-as-needed'

MSVC doesn't use the unwind library, so just omit it.

Differential Revision: https://reviews.llvm.org/D132440
2022-08-24 17:34:47 +00:00
John Ericson ad8c34bc30 [CMake] Avoid `LLVM_BINARY_DIR` when other more specific variable are better-suited
A simple sed doing these substitutions:

- `${LLVM_BINARY_DIR}/(\$\{CMAKE_CFG_INTDIR}/)?lib(${LLVM_LIBDIR_SUFFIX})?\>` -> `${LLVM_LIBRARY_DIR}`
- `${LLVM_BINARY_DIR}/(\$\{CMAKE_CFG_INTDIR}/)?bin\>` -> `${LLVM_TOOLS_BINARY_DIR}`

where `\>` means "word boundary".

The only manual modifications were reverting changes in

- `compiler-rt/cmake/Modules/CompilerRTUtils.cmake
- `runtimes/CMakeLists.txt`

because these were "entry points" where we wanted to tread carefully not not introduce a "loop" which would end with an undefined variable being expanded to nothing.

This hopefully increases readability overall, and also decreases the usages of `LLVM_LIBDIR_SUFFIX`, preparing us for D130586.

Reviewed By: sebastian-ne

Differential Revision: https://reviews.llvm.org/D132316
2022-08-24 10:14:05 -04:00
Joseph Huber ba57828e11 [CUDA][OpenMP] Fix the new driver crashing on multiple device-only outputs
The new driver supports device-only compilation for the offloading
device. The way this is handlded is a little different from the old
offloading driver. The old driver would put all the outputs in the final
action list akin to a linker job. The new driver however generated these
in the middle of the host's job so we instead put them all in a single
offloading action. However, we only handled these kinds of offloading
actions correctly when there was only a single input. When we had
multiple inputs we would instead attempt to get the host job, which
didn't exist, and crash.

This patch simply adds some extra logic to generate the jobs for all
dependencies if there is not host action.

Reviewed By: yaxunl

Differential Revision: https://reviews.llvm.org/D132248
2022-08-24 08:47:55 -05:00
Louis Dionne b1320f7c9b [clang] Explicitly add libcxx and libcxxabi runtimes during Stage2 builds
For the time being, we are still building libc++ and libc++abi's headers
during stage 2 builds. Encode that in the cache file so that CI jobs don't
have to manually specify LLVM_ENABLE_RUNTIMES when doing a stage 2 build.
2022-08-24 09:13:29 -04:00
Louis Dionne 3e84cdbee4 [NFC] Colocate cache values for controling libc++ headers build in stage 2 2022-08-24 08:50:52 -04:00
Pavel Samolysov 6703ad1e0c Revert "[Pipelines] Introduce DAE after ArgumentPromotion"
This reverts commit 3f20dcbf70.
2022-08-24 12:44:13 +03:00
Martin Storsjö 0a4c6c9f98 [clang] Allow using -rtlib=platform to switching to the default rtlib on all targets
Normally, passing -rtlib=platform overrides any earlier -rtlib
options, and overrides any hardcoded CLANG_DEFAULT_RTLIB option.
However, some targets, MSVC and Darwin, have custom logic for
disallowing specific -rtlib= option values; amend these checks for
allowing the -rtlib=platform option.

Differential Revision: https://reviews.llvm.org/D132444
2022-08-24 11:39:03 +03:00
Petr Hosek d3b14ccafb Revert "[Clang] Avoid using unwind library in the MSVC environment"
This reverts commit eca29d4a37 since
the test fails in the per-target-runtime-dir layout.
2022-08-24 08:24:18 +00:00
Pavel Samolysov 3f20dcbf70 [Pipelines] Introduce DAE after ArgumentPromotion
The ArgumentPromotion pass uses Mem2Reg promotion at the end to cutting
down generated `alloca` instructions as well as meaningless `store`s and
this behavior can leave unused (dead) arguments. To eliminate the dead
arguments and therefore let the DeadCodeElimination remove becoming dead
inserted `GEP`s as well as `load`s and `cast`s in the callers, the
DeadArgumentElimination pass should be run after the ArgumentPromotion
one.

Differential Revision: https://reviews.llvm.org/D128830
2022-08-24 10:36:12 +03:00
David Green 8dc1eee77d [AArch64][SVE] Remove -O1 from SVE intrinsic tests.
This removes -O1 from the SVE ACLE intrinsics tests and replaces it with
-O0 and "opt -mem2reg -instcombine -tailcallelim". Instrcombine and
TailCallElim are only added to keep the differences smaller and can be
removed in a followup patches. The only remaining differences in the
tests are tbaa nodes not being emitted under -O0, and the removable of
some tailcall flags.
2022-08-24 08:18:01 +01:00
Bing1 Yu 6d8ddf53cc [X86] Emulate _rdrand64_step with two rdrand32 if it is 32bit
Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D132141
2022-08-24 10:22:46 +08:00
Chris Bieneman 887bafb503 [HLSL] Infer language from file extension
This allows the language mode for HLSL to be inferred from the file
extension.
2022-08-23 20:52:29 -05:00
Bing1 Yu 0d8f9520c5 Revert "[X86] Emulate _rdrand64_step with two rdrand32 if it is 32bit"
This reverts commit 07e34763b0.
2022-08-24 09:38:46 +08:00
Bing1 Yu 07e34763b0 [X86] Emulate _rdrand64_step with two rdrand32 if it is 32bit
Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D132141
2022-08-24 09:28:55 +08:00
Petr Hosek eca29d4a37 [Clang] Avoid using unwind library in the MSVC environment
We're seeing the following warnings with --rtlib=compiler-rt:

  lld-link: warning: ignoring unknown argument '--as-needed'
  lld-link: warning: ignoring unknown argument '-lunwind'
  lld-link: warning: ignoring unknown argument '--no-as-needed'

MSVC doesn't use the unwind library, so just omit it.

Differential Revision: https://reviews.llvm.org/D132440
2022-08-24 00:09:01 +00:00
isuckatcs aac73a31ad [analyzer] Process non-POD array element destructors
The constructors of non-POD array elements are evaluated under
certain conditions. This patch makes sure that in such cases
we also evaluate the destructors.

Differential Revision: https://reviews.llvm.org/D130737
2022-08-24 01:28:21 +02:00
Louis Dionne 7dfcf9342b [CMake] Move cxx-headers to RUNTIME_DISTRIBUTION_COMPONENTS in Apple-stage2.cmake
We build libcxx using LLVM_ENABLE_RUNTIMES during Stage2, which requires
cxx-headers to be part of LLVM_RUNTIME_DISTRIBUTION_COMPONENTS instead
of LLVM_DISTRIBUTION_COMPONENTS.

rdar://99028431

Differential Revision: https://reviews.llvm.org/D132488
2022-08-23 17:02:51 -04:00
Vitaly Buka b5a9adf1f5 [clang] Create alloca to pass into static lambda
"this" parameter of lambda if undef, notnull and differentiable.
So we need to pass something consistent.

Any alloca will work. It will be eliminated as unused later by optimizer.

Otherwise we generate code which Msan is expected to catch.

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D132275
2022-08-23 13:53:17 -07:00
Alvin Wong 94778692ad [clang] Add support for __attribute__((guard(nocf)))
To support using Control Flow Guard with mingw-w64, Clang needs to
accept `__declspec(guard(nocf))` also for the GNU target. Since mingw
has `#define __declspec(a) __attribute__((a))` as built-in, the simplest
solution is to accept `__attribute__((guard(nocf)))` to be compatible with
MSVC and Clang's msvc target.

As a side effect, this also adds `[[clang::guard(nocf)]]` for C++.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D132302
2022-08-23 23:39:38 +03:00
Joseph Huber 2b8f722e63 [OpenMP] Add option to assert no nested OpenMP parallelism on the GPU
The OpenMP device runtime needs to support the OpenMP standard. However
constructs like nested parallelism are very uncommon in real application
yet lead to complexity in the runtime that is sometimes difficult to
optimize out. As a stop-gap for performance we should supply an argument
that selectively disables this feature. This patch adds the
`-fopenmp-assume-no-nested-parallelism` argument which explicitly
disables the usee of nested parallelism in OpenMP.

Reviewed By: carlo.bertolli

Differential Revision: https://reviews.llvm.org/D132074
2022-08-23 14:09:51 -05:00
Roy Jacobson 7171615099 [Clang] Implement P0848 (Conditionally Trivial Special Member Functions)
This patch implements P0848 in Clang.

During the instantiation of a C++ class, in `Sema::ActOnFields`, we evaluate constraints for all the SMFs and compare the constraints to compute the eligibility. We defer the computation of the type's [copy-]trivial bits from addedMember to the eligibility computation, like we did for destructors in D126194. `canPassInRegisters` is modified as well to better respect the ineligibility of functions.

Note: Because of the non-implementation of DR1734 and DR1496, I treat deleted member functions as 'eligible' for the purpose of [copy-]triviallity. This is unfortunate, but I couldn't think of a way to make this make sense otherwise.

Reviewed By: #clang-language-wg, cor3ntin, aaron.ballman

Differential Revision: https://reviews.llvm.org/D128619
2022-08-23 21:48:42 +03:00
Zahira Ammarguellat ba8b5ff874 Adding a note about the macro __FLT_EVAL_METHOD__; NFC
This is to clarify that the macro __FLT_EVAL_METHOD__ is not pre-
defined like other preprocessor macros. It will not appear when
preprocessor macros are dumped.

Differential Revision: https://reviews.llvm.org/D124033
2022-08-23 14:35:57 -04:00
Yuanfang Chen 088ba8efeb [Clang] follow-up D128745, use ClangABICompat15 instead of ClangABICompat14
Since the patch missed release 15.x and will be included in release 16.x. Also, simplify related tests.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D132414
2022-08-23 10:45:35 -07:00
Balazs Benics 6ca17b58f5 [analyzer] Drop deprecated flags
As proposed in D126215 (ffe7950ebc),
I'm dropping the `-analyzer-store` and
`-analyzer-opt-analyze-nested-blocks` clang frontend flags.
I'm also dropping the corresponding commandline handlers of `scanbuild`.

This behavior is planned to be part of `clang-16`.

Reviewed By: xazax.hun

Differential Revision: https://reviews.llvm.org/D132289
2022-08-23 18:39:21 +02:00
Fred Tingaud 16cb3be626 [analyzer] Deadstore static analysis: Fix false positive on C++17 assignments
Dead store detection automatically checks that an expression is a
CXXConstructor and skips it because of potential side effects. In C++17,
with guaranteed copy elision, this check can fail because we actually
receive the implicit cast of a CXXConstructor.
Most checks in the dead store analysis were already stripping all casts
and parenthesis and those that weren't were either forgotten (like the
constructor) or would not suffer from it, so this patch proposes to
factorize the stripping.
It has an impact on where the dead store warning is reported in the case
of an explicit cast, from

  auto a = static_cast<B>(A());
           ^~~~~~~~~~~~~~~~~~~

to

  auto a = static_cast<B>(A());
                          ^~~

which we think is an improvement.

Patch By: frederic-tingaud-sonarsource

Reviewed By: steakhal

Differential Revision: https://reviews.llvm.org/D126534
2022-08-23 18:33:26 +02:00
Ben Langmuir 3708a14842 [clang] Pull some utility functions into CompilerInvocation NFC
Move copying compiler arguments to a vector<string> and modifying
common module-related options into CompilerInvocation in preparation for
using some of them in more places and to avoid duplicating this code
accidentally in the future.

Differential Revision: https://reviews.llvm.org/D132419
2022-08-23 08:18:14 -07:00
Joseph Huber 86bfab2723 [OffloadPackager] Resolve copy elision warnings
Summary:
The buildbots are giving failures on the explicit move operations here.
Previously I had problems where not perfomring an explicit move would
cause problems with older compilers so we'll see if this works as
expected.
2022-08-23 10:01:54 -05:00
utsumi 2e2caea37f [Clang][OpenMP] Make copyin clause on combined and composite construct work (patch by Yuichiro Utsumi (utsumi.yuichiro@fujitsu.com))
Make copyin clause on the following constructs work.

- parallel for
- parallel for simd
- parallel sections

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

Patch by Yuichiro Utsumi (utsumi.yuichiro@fujitsu.com)

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D132209
2022-08-23 07:58:35 -07:00
David Majnemer 2c923b8863 [clang-cl] Expose the /volatile:{iso,ms} choice via _ISO_VOLATILE
MSVC allows interpreting volatile loads and stores, when combined with
/volatile:iso, as having acquire/release semantics. MSVC also exposes a
define, _ISO_VOLATILE, which allows users to enquire if this feature is
enabled or disabled.
2022-08-23 14:29:52 +00:00
Nico Weber 0565e65a69 [clang/test] Correctly specify simulator env in target flag in fsanitize.c
Putting "simulator" in the `-target` flag requires putting it in the
"environment" part of the triple, which is the 4th `-`-separated component.

Some places in the tests currently use "iossimulator" which puts it in the
OS field. The triple parsing code in llvm::Triple uses startswith("ios")
in parseOS(), so that successfully sets the OS to "iOS", and all these
triples use an intel arch, and iOS + intel triple implicitly make the
driver convert the environment to "simulator", so this happened to work --
but it led to the somewhat strange "simulator-simulator" in the diag
in the test.

No behavior change.

Differential Revision: https://reviews.llvm.org/D132399
2022-08-23 10:13:51 -04:00
Nico Weber cd24120c9d [clang] Remove a FIXME that we can't fix
I added this recently, but it looks like several tests very intentionally
check that `-mios-version-min=foo --target=x86_64-apple-ios` does simulator
builds. So we can't easily remove this hack, even though it makes little
sense in an arm mac world. (Here, you _have_ to say
`-mios-simulator-version-min=` or `--target=arm64-apple-ios-simulator`.)

The tests that check this:
  Clang :: Driver/darwin-ld.c
  Clang :: Driver/darwin-simulator-macro.c
  Clang :: Driver/darwin-version.c

No behavior change.

Differential Revision: https://reviews.llvm.org/D132400
2022-08-23 10:12:52 -04:00
Louis Dionne 342e0ebd0b Revert the removal of LLVM_ENABLE_PROJECTS for libc++ and libc++abi
This commit reverts the following commits:

- 952f90b72b
- e6a0800532 (D132298)
- 176db3b3ab (D132324)

These commits caused CI instability and need to be reverted in order
to figure things out again. See the discussion in https://llvm.org/D132324
for more information.
2022-08-23 09:58:30 -04:00
Joseph Huber ea0549d41b [OffloadPackager] Add necessary move statement on returned value
Summary:
Some older compilers cannot automatically elide the returned vector of
unique pointers, causing build errors. This patch explicitly moves the
returned value instead which should solve the problem.
2022-08-23 08:45:30 -05:00
Joseph Huber bf06295436 [OffloadPackager] Add option to extract files from images
We use the `clang-offload-packager` too bundle many files into a single
binary format containing metadata. This is used for offloading
compilation which may contain multiple device binaries of different
types and architectures in a single file. We use this special binary
format to store these files along with some necessary metadata around
them. We use this format because of the difficulty of determining the
filesize of the various binary inputs that will be passed to the
offloading toolchain rather than engineering a solution for each input.

Previously we only support packaing many files into a single binary.
This patch adds support for doing the reverse by using the same
`--image=` syntax. To unpackage a binary we now present an input file
instead of an output.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D129507
2022-08-23 12:57:16 +00:00
Chuanqi Xu 4332b049ed [docs] Add examples for printing asynchronous stack for coroutines
Previously when I wrote this document, I felt the completed scripts was
lengthy, redundant and not easy to read. So I didn't add complete
examples in the previous commit.

However, in the recent discussion with @avogelsgesang, I found people
may not know how to use debugging scripts to improve their debugging
efficiency. So now, I feel like it is helpful to put the examples even
if they are a little bit long.

Test Plan: make docs-clang-html

Reviewed By: avogelsgesang

Differential Revision: https://reviews.llvm.org/D132451
2022-08-23 17:37:12 +08:00
Balázs Kéri 23fbfb3f72 [clang][AST] RecursiveASTVisitor should visit owned TagDecl of friend type.
A FriendDecl node can have a friend record type that owns a RecordDecl
object. This object is different than the one got from TypeSourceInfo
object of the FriendDecl. When building a ParentMapContext this owned
tag decaration has to be encountered to have the parent set for it.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D131685
2022-08-23 09:15:55 +02:00
Weining Lu 15b65bcd65 [Clang][LoongArch] Add initial LoongArch target and driver support
With the initial support added, clang can compile `helloworld` C
to executable file for loongarch64. For example:

```
$ cat hello.c
int main() {
  printf("Hello, world!\n");
  return 0;
}
$ clang --target=loongarch64-unknown-linux-gnu --gcc-toolchain=xxx --sysroot=xxx hello.c
```

The output a.out can run within qemu or native machine. For example:

```
$ file ./a.out
./a.out: ELF 64-bit LSB pie executable, LoongArch, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-loongarch-lp64d.so.1, for GNU/Linux 5.19.0, with debug_info, not stripped
$ ./a.out
Hello, world!
```

Currently gcc toolchain and sysroot can be found here:
https://github.com/loongson/build-tools/releases/download/2022.08.11/loongarch64-clfs-5.1-cross-tools-gcc-glibc.tar.xz

Reference: https://github.com/loongson/LoongArch-Documentation
The last commit hash (main branch) is:
99016636af64d02dee05e39974d4c1e55875c45b

Note loongarch32 is not fully tested because there is no reference
gcc toolchain yet.

Differential Revision: https://reviews.llvm.org/D130255
2022-08-23 13:47:22 +08:00
Carlos Alberto Enciso 6c6c4f6a9b [CMake] Support passing arguments to build tool (bootstrap).
For bootstrap builds (CLANG_ENABLE_BOOTSTRAP=ON) allow
arguments to be passed to the native tool used in CMake
for the stage2 step.

Can be used to pass extra arguments for enhanced versions
of build tools, e.g. distributed build options.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D131665
2022-08-23 05:45:25 +01:00
owenca 47e70569fc [clang-format] Remove an extraneous test in TokenAnnotatorTest.cpp
This removes an obsolete test case introduced by mistake from
commit 2e36120726.
2022-08-22 21:18:37 -07:00
owenca 2e36120726 [clang-format] Fix regressions in WhitespaceSensitiveMacros
Fixes #54522.
Fixes #57158.

Differential Revision: https://reviews.llvm.org/D132001
2022-08-22 20:42:54 -07:00
Phoebe Wang 08388ad81e [X86][AVX512FP16] Relax limitation to AVX512FP16 intrinsics. NFCI
Since we have enabled the support for `_Float16` on SSE2, we can relax
the limitation for AVX512FP16 now. This helps for user to use AVX512FP16
mixed with unsupported versions, e.g., multiversioning.

Also fix lit fails due to missing const modifier. Found during this change.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D132342
2022-08-23 11:35:16 +08:00
Jan Svoboda be795ee16a [clang][deps] Allow switching between lazily/eagerly loaded PCMs
This patch introduces new option `-eager-load-pcm` to `clang-scan-deps`, which controls whether the resulting command-lines will load PCM files eagerly (at the start of compilation) or lazily (when handling import directive). This patch also switches the default from eager to lazy.

To reduce the potential for churn in LIT tests in the future, this patch also removes redundant checks of command-line arguments and introduces new test `modules-dep-args.c` as a substitute.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D132066
2022-08-22 18:22:27 -07:00
Christopher Di Bella e137fb6fb8 [clang][libcxx] renames `__remove_reference`
libc++ prior to LLVM 15 has a bug in it due to it excluding
`remove_reference_t` when `__remove_reference` is available as a
compiler built-in. This went unnoticed until D116203 because it wasn't
available in any compiler.

To work around this, we're renaming `__remove_reference` to
`__remove_reference_t`.

TEST=Tested locally, tested using emscripten
2022-08-22 23:15:10 +00:00
Yuanfang Chen f9969a3d28 [CodeGen] Sort llvm.global_ctors by lexing order before emission
Fixes https://github.com/llvm/llvm-project/issues/55804

The lexing order is already bookkept in DelayedCXXInitPosition but we
were not using it based on the wrong assumption that inline variable is
unordered. This patch fixes it by ordering entries in llvm.global_ctors
by orders in DelayedCXXInitPosition.

for llvm.global_ctors entries without a lexing order, ordering them by
the insertion order.

(This *mostly* orders the template instantiation in
https://reviews.llvm.org/D126341 intuitively, minus one tweak for which I'll
submit a separate patch.)

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D127233
2022-08-22 16:00:14 -07:00
Yaxun (Sam) Liu 9f6cb3e9fd [AMDGPU] Add builtin s_sendmsg_rtn
Reviewed by: Brian Sumner, Artem Belevich

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

Fixes: SWDEV-352017
2022-08-22 18:29:23 -04:00
Chris Bieneman 9a478d5232 [NFC] Rename dx.shader to hlsl.shader
This metadata annotation is HLSL-specific not DirectX specific. It will
need to be attached for shaders regardless of whether they are targeting
DXIL.
2022-08-22 16:03:40 -05:00
David Majnemer 0bf525bf90 [clang-cl] Add _M_FP_* #defines for floating point modes
This keeps clang compatible with MSVC defines for the FP environment.
These defines are used by the CRT and other libraries to interrogate
what to expect. Perhaps most importantly, they feed into the definition
of float_t and double_t which may result in ODR violations between MSVC
and clang.
2022-08-22 20:04:35 +00:00
Akira Hatanaka 5d794552bc [Sema][ObjC] Don't warn about implicitly-retained self in an unevaluated
context
2022-08-22 12:16:37 -07:00
David Majnemer 3d89323d18 [clang-cl] Increase /fp flag fidelity
They were mapped as follows:
- /fp:except to --ftrapping-math
- /fp:except- to --fno-trapping-math
- /fp:strict to --fno-fast-math
- /fp:precise to --fno-fast-math

Let's map them as follows:
- /fp:except to --ffp-exception-behavior=strict
- /fp:except- to --ffp-exception-behavior=ignore
- /fp:strict to --ffp-model=strict
- /fp:precise to --ffp-model=ignore

I believe the changes to /fp:except are technically a no-op but it makes
the mapping a lot clearer. The changes for /fp:strict and /fp:precise are not
no-ops, they now match MSVC's behavior.

While we are here, also add support for /fp:contract by mapping it to
-ffp-contract=on.
2022-08-22 18:32:58 +00:00
Usman Nadeem ef5ede52ef [Flang][Driver] Add support for PIC
This patch does the following:

 - Consumes the PIC flags (fPIC/fPIE/fropi/frwpi etc) in flang-new.
   tools::ParsePICArgs() in ToolChains/CommonArgs.cpp is used for this.
 - Adds FC1Option to "-mrelocation-model", "-pic-level", and "-pic-is-pie"
   command line options.
 - Adds the above options to flang/Frontend/CodeGenOptions' data structure.
 - Sets the relocation model in the target machine, and
 - Sets module flags for the respective PIC/PIE type in LLVM IR.

I have tried my best to replicate how clang does things.

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

Change-Id: I68fe64910be28147dc5617826641cea71b92d94d
2022-08-22 11:10:42 -07:00
Mike Rice 129904d504 [OpenMP][NFC] Use OMPInteropInfo in the OMPDeclareVariantAttr attribute
In preparation for allowing the prefer_type list in the append_args clause,
use the OMPInteropInfo in the attribute for 'declare variant'.

This requires adding a new Argument kind to the attribute code. This change
adds a specific attribute to pass an array of OMPInteropInfo. It implements
new tablegen needed to handle the interop-type part of the structure. When
prefer_type is added, more work will be needed to dump, instantiate, and
serialize the PreferTypes field in OMPInteropInfo.

Differential Revision: https://reviews.llvm.org/D132270
2022-08-22 10:41:16 -07:00
Nico Weber 3affbae530 clang/apple: Infer simulator env from -mios-simulator-version-min= flag
Before this patch, open-source clang would consider
`-target x86_64-apple-darwin -mios-simulator-version-min=11.0` as
targeting the iOS simulator, due to the mios flag informing it
that we want to target iOS, and logic in the driver then realizing
that x86 iOS builds must be the simulator.

However, for `-target arm64-apple-darwin -mios-simulator-version-min=11.0`
that didn't work and clang thought that it's building for actual iOS,
and not for the simulator.

Due to this, building compiler-rt for arm64 iossim would lead to
all .o files in RTSanitizerCommonSymbolizer.iossim.dir being built
for iOS instead of for iOS simulator, and clang would ask ld64 to
link for iOS, but using the iPhoneSimulator sysroot. This would then
lead to many warnings from ld64 looking like:

    ld: warning: building for iOS, but linking in .tbd file
        (.../iPhoneSimulator.sdk/usr/lib/libc++abi.tbd) built for iOS Simulator

Worse, with ld64.lld, this diagnostic is currently an error instead
of a warning.

This patch makes it so that the presence of -mios-simulator-version-min=
now informs clang that we're building for simulator. That way, all the
.o files are built for simulator, the linker is informed that we're
building for simulator, and everything Just Works.

(Xcode's clang already behaves like this, so this makes open-source clang
match Xcode clang.)

We can now likely remove the hack to treat non-mac darwin x86 as
simulator, but doing that feels slightly risky, so I'm leaving that
for a follow-up patch.

(This patch is made necessary by the existence of arm64 macs.)

Differential Revision: https://reviews.llvm.org/D132258
2022-08-22 12:19:34 -04:00
Chuanqi Xu 210a4197b4 [docs] Adjust the example command line in DebuggingCoroutines.rst
The original commandline example was not correct in some environments.
Adjust the example to avoid any misunderstanding.
2022-08-22 22:15:47 +08:00
Phoebe Wang df23fc4f7f [X86][AVX512FP16] Add the missing const modifiers. NFCI
This patch fixes lit fails after D132342.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D132372
2022-08-22 22:07:42 +08:00
Aaron Ballman e2ab6061a9 Add N2562 to the C status page
It was originally left off thinking the paper only impacts the C
standard library, but Clang supports diagnostics for incorrect use of
a format specifier, so this paper has some frontend impacts as well.
2022-08-22 09:46:12 -04:00
isuckatcs c81bf940c7 [analyzer] Handling non-POD multidimensional arrays in ArrayInitLoopExpr
This patch makes it possible for lambdas, implicit copy/move ctors
and structured bindings to handle non-POD multidimensional arrays.

Differential Revision: https://reviews.llvm.org/D131840
2022-08-22 13:53:53 +02:00
isuckatcs 3c482632e6 [analyzer] Remove pattern matching of lambda capture initializers
Prior to this patch we handled lambda captures based on their
initializer expression, which resulted in pattern matching. With
C++17 copy elision the initializer expression can be anything,
and this approach proved to be fragile and a source of crashes.
This patch removes pattern matching and only checks whether the
object is under construction or not.

Differential Revision: https://reviews.llvm.org/D131944
2022-08-22 13:00:31 +02:00
owenca d90c1bcdf9 Revert "[clang-format][NFC] Fix a bug in setting type FunctionLBrace"
This reverts commit 35f7dd601d.

Fixes #57200.
2022-08-21 23:26:51 -07:00
Vitaly Buka aaa987ddfb [clang] Fix warning after D116203
The warning was:
SemaType.cpp:9469:3: error: default label in switch
which covers all enumeration values
[-Werror,-Wcovered-switch-default]
2022-08-21 22:39:23 -07:00
Shao-Ce SUN 7167a4207e [RISCV] Add zihintntl instructions
Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D121670
2022-08-22 12:06:30 +08:00
Christopher Di Bella e9ef45635b [clang] adds unary type transformations as compiler built-ins
Adds

* `__add_lvalue_reference`
* `__add_pointer`
* `__add_rvalue_reference`
* `__decay`
* `__make_signed`
* `__make_unsigned`
* `__remove_all_extents`
* `__remove_extent`
* `__remove_const`
* `__remove_volatile`
* `__remove_cv`
* `__remove_pointer`
* `__remove_reference`
* `__remove_cvref`

These are all compiler built-in equivalents of the unary type traits
found in [[meta.trans]][1]. The compiler already has all of the
information it needs to answer these transformations, so we can skip
needing to make partial specialisations in standard library
implementations (we already do this for a lot of the query traits). This
will hopefully improve compile times, as we won't need use as much
memory in such a base part of the standard library.

[1]: http://wg21.link/meta.trans

Co-authored-by: zoecarver

Reviewed By: aaron.ballman, rsmith

Differential Revision: https://reviews.llvm.org/D116203
2022-08-22 03:03:32 +00:00
Ting Wang d2d77e050b [PowerPC][Coroutines] Add tail-call check with call information for coroutines
Fixes #56679.

Reviewed By: ChuanqiXu, shchenz

Differential Revision: https://reviews.llvm.org/D131953
2022-08-21 22:20:40 -04:00
owenca 41214456de [clang-format] Fix BeforeHash indent of comments above PPDirective
Fixes #56326.

Differential Revision: https://reviews.llvm.org/D132097
2022-08-21 18:23:14 -07:00
John Ericson 176db3b3ab [RFC] Remove support for building C++ with `LLVM_ENABLE_PROJECTS`
This has been officially deprecated since D112724, meaning the
deprecation warning is present in released 14 and 15.

This makes me think that now, shortly after the 15 release is branched,
is a good time to pull the trigger.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D132324
2022-08-21 08:10:56 -04:00
Iain Sandoe fee3cccc6c [C++20][Modules] Improve handing of Private Module Fragment diagnostics.
This adds a check for exported inline functions, that there is a definition in
the definition domain (which, in practice, can only be the module purview but
before any PMF starts) since the PMF definition domain cannot contain exports.

This is:
[dcl.inline]/7
If an inline function or variable that is attached to a named module is declared in
a definition domain, it shall be defined in that domain.

The patch also amends diagnostic output by excluding the PMF sub-module from the
set considered as sources of missing decls.  There is no point in telling the user
that the import of a PMF object is missing - since such objects are never reachable
to an importer.  We still show the definition (as unreachable), to help point out
this.

Differential Revision: https://reviews.llvm.org/D128328
2022-08-21 10:19:46 +01:00
Kazu Hirata 8b1b0d1d81 Revert "Use std::is_same_v instead of std::is_same (NFC)"
This reverts commit c5da37e42d.

This patch seems to break builds with some versions of MSVC.
2022-08-20 23:00:39 -07:00
Kazu Hirata c5da37e42d Use std::is_same_v instead of std::is_same (NFC) 2022-08-20 22:36:26 -07:00
Kazu Hirata ec5eab7e87 Use range-based for loops (NFC) 2022-08-20 21:18:32 -07:00
Kazu Hirata 8e494b85a5 Use llvm::drop_begin (NFC) 2022-08-20 21:18:30 -07:00
Kazu Hirata 258531b7ac Remove redundant initialization of Optional (NFC) 2022-08-20 21:18:28 -07:00
John Ericson 3adda398ce [clang][lldb][cmake] Use new `*_INSTALL_LIBDIR_BASENAME` CPP macro
Use this instead of `*_LIBDIR_SUFFIX`, from which it is computed.

This gets us ready for D130586, in which `*_LIBDIR_SUFFIX` is
deprecated.

Differential Revision: https://reviews.llvm.org/D132300
2022-08-20 12:52:21 -04:00
Kazu Hirata fc4d3a1109 [clang] Use Any::has_value instead of Any::hasValue (NFC) 2022-08-20 08:40:18 -07:00
Austin Kerbow b0f4678b90 [AMDGPU] Add iglp_opt builtin and MFMA GEMM Opt strategy
Adds a builtin that serves as an optimization hint to apply specific optimized
DAG mutations during scheduling. This also disables any other mutations or
clustering that may interfere with the desired pipeline. The first optimization
strategy that is added here is designed to improve the performance of small gemm
kernels on gfx90a.

Reviewed By: jrbyrnes

Differential Revision: https://reviews.llvm.org/D132079
2022-08-19 15:38:36 -07:00
Daniel Grumberg 57c9780d60 [clang][ExtractAPI] Record availability information on all platforms
Currently ExtractAPI only emits availability information for the
current platform. This makes it easy for clients to get all availability
information for a given symbol in one invocation as opposed to having to invoke
clang once per-platform and then merge the symbol-graphs.

Differential Revision: https://reviews.llvm.org/D130918
2022-08-19 14:54:52 -07:00
Wei Yi Tee b0befe3ac1 [clang][dataflow] Mark `getDeclCtx` function in dataflow `Environment` `const`.
Differential Revision: https://reviews.llvm.org/D132229
2022-08-19 20:07:21 +00:00
Erich Keane 95d94a6775 Revert "Re-apply "Deferred Concept Instantiation Implementation"""
This reverts commit d483730d8c.

This allegedly breaks a significant part of facebooks internal build.
Reverting while we wait for them to provide a reproducer of this from
@wlei.
2022-08-19 12:47:34 -07:00
Alex Bradbury bc53832080 [clang][RISCV] Fix incorrect ABI lowering for inherited structs under hard-float ABIs
The hard float ABIs have a rule that if a flattened struct contains
either a single fp value, or an int+fp, or fp+fp then it may be passed
in a pair of registers (if sufficient GPRs+FPRs are available).
detectFPCCEligibleStruct and the helper it calls,
detectFPCCEligibleStructHelper examine the type of the argument/return
value to determine if it complies with the requirements for this ABI
rule.

As reported in bug #57084, this logic produces incorrect results for C++
structs that inherit from other structs. This is because only the fields
of the struct were examined, but enumerating RD->fields misses any
fields in inherited C++ structs. This patch corrects that issue by
adding appropriate logic to enumerate any included base structs.

Differential Revision: https://reviews.llvm.org/D131677
2022-08-19 20:31:06 +01:00
Simon Pilgrim e41dd02052 Fix MSVC "not all control paths return a value" warning 2022-08-19 17:37:37 +01:00
Craig Topper 1a60e003df [RISCV] Use Triple::isRISCV/isRISCV32/isRISCV64 helps in some places. NFC
Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D132197
2022-08-19 09:11:22 -07:00
isuckatcs a47ec1b797 [analyzer][NFC] Be more descriptive when we replay without inlining
This patch adds a ProgramPointTag to the EpsilonPoint created
before we replay a call without inlining.

Differential Revision: https://reviews.llvm.org/D132246
2022-08-19 18:05:52 +02:00
Denis Fatkulin ee648c0ce0 [clang][index] Index unresolved member expression as reference
Unresolved member expressions aren't indexed as references.

Example code:

```
struct Foo {
  template <typename T> void bar(T t);
};
template <typename T> void test(Foo F, T t) {
  F.bar(t); // Not indexed
}
```

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D131091
2022-08-19 19:02:42 +03:00
Wei Yi Tee dbb95c2a85 [clang][dataflow] Debug string for value kinds.
Differential Revision: https://reviews.llvm.org/D131891
2022-08-19 15:00:01 +00:00
Muhammad Usman Shahid fd874e5fb1 Missing tautological compare warnings due to unary operators
The patch mainly focuses on the no warnings for -Wtautological-compare.
It work fine for the positive numbers but doesn't for the negative
numbers. This is because the warning explicitly checks for an
IntegerLiteral AST node, but -1 is represented by a UnaryOperator with
an IntegerLiteral sub-Expr.

Fixes #42918
Differential Revision: https://reviews.llvm.org/D130510
2022-08-19 10:46:29 -04:00
Timm Bäder 7614785e1d [clang][Interp] Rename Integral::T to Integral::ReprT
Just 'T' is a bit generic and causes confusion.
2022-08-19 16:14:37 +02:00
Timm Bäder 80bbc05436 [clang][Interp] Implement inv and neg unary operations
Implement negating and inverting values. Also implement
IntegralToBoolean casts so the operations are easier to test.

Differential Revision: https://reviews.llvm.org/D132098
2022-08-19 16:05:00 +02:00
Sam McCall ac31781759 [Sema] Tweak diagnostic logic so suppress-in-header logic works in tools too.
Certain idioms are ignored by -Wunused in header files only.
The current "is a header" check assumes that if headers are the main file, we're
building a PCH or a module or something. However in tools we may be parsing the
header in its own right, but still want to treat it as a header.

Fixes https://github.com/clangd/vscode-clangd/issues/360

Differential Revision: https://reviews.llvm.org/D129642
2022-08-19 15:16:10 +02:00
Caroline Concatto 9f21d6e953 [Clang][AArch64] Use generic extract/insert vector for svget/svset/svcreate tuples
This patch replaces svget, svset and svcreate aarch64 intrinsics for tuple
types with the generic llvm-ir intrinsics extract/insert vector

Differential Revision: https://reviews.llvm.org/D131547
2022-08-19 12:58:59 +01:00
Vaibhav Yenamandra 1bd2b2dce2 Add support for specifying the severity of a SARIF Result
* Extend SarifResult with level property, and allow rule configuration
* Create SarifReportingConfiguration which allow configuring rules with
a default priority, severity and an enable-toggle
* Support for setting the level property[1] of a result.

If unset, it defaults to "warning", which is the result of an empty
default configuration on rules[2]

[1]: https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317648
[2]: https://docs.oasis-open.org/sarif/sarif/v2.1.0/os/sarif-v2.1.0-os.html#_Toc34317855

Differential Revision: https://reviews.llvm.org/D131084
2022-08-19 07:14:50 -04:00
Caroline Concatto 4ef1f014a1 [Clang][AArch64] Replace aarch64_sve_ldN intrinsic by aarch64_sve_ldN.sret
Differential Revision: https://reviews.llvm.org/D131687
2022-08-19 11:42:18 +01:00
Alexander Malkov cd86a03246 [clang,flang] Add help text for -fsyntax-only
Fix for the problem with displaying options `-fsyntax-only` in clang and flang-new in help
Fix https://github.com/llvm/llvm-project/issues/57033

Before:
``` $ clang  -help | grep syntax
  -objcmt-migrate-property-dot-syntax
         Enable migration of setter/getter messages to property-dot syntax
```
After:
```
 $ clang -help | grep syntax
  -fsyntax-only           Run the preprocessor, parser and semantic analysis stages
  -objcmt-migrate-property-dot-syntax
         Enable migration of setter/getter messages to property-dot syntax
```

Reviewed By: vzakhari, awarzynski, MaskRay, alexiprof

Differential Revision: https://reviews.llvm.org/D131808
2022-08-19 09:54:29 +00:00
Iain Sandoe a2dd6130d4 [clang][Modules] Fix a regression in handling missing framework headers.
The commit of af2d11b1d5 missed a case where
the value of a suggested module needed to be reset to nullptr.  Fixed thus
and added a testcase to cover the circumstance.
2022-08-19 09:13:22 +01:00
Chuanqi Xu acaf6b9dc0 [NFC] Add [[maybe_unused]] to avoid warning in gcc9
GCC9 may issue warning for the 'unused' parameters in if constexpr.
This commit try to fix it by adding the [[maybe_unused]] attribute.
2022-08-19 14:43:22 +08:00
Timm Bäder 3d2ab237f1 [clang] Improve diagnostics for uninitialized constexpr variables
Instead of complaining about default initialization, tell users that
constexpr variables need to be initialized by a constant expression.

Differential Revision: https://reviews.llvm.org/D131662
2022-08-19 08:06:12 +02:00
David Blaikie d4e0fe62b1 Simplify RAV isSameMethod with constexpr if
Owing to the large number of instantiations of this function, this small
change has a small but meaningful difference on the total size of
(especially a debug) build of clang at -O0:
```
    FILE SIZE        VM SIZE
 --------------  --------------
  +0.9% +96.9Ki  +0.9% +96.9Ki    .data.rel.ro
  +0.7% +96.7Ki  +0.7% +96.7Ki    .rela.dyn
  +0.0% +18.3Ki  +0.0% +18.3Ki    .rodata
  +0.0%    +324  [ = ]       0    [2 Others]
  -0.2%    -392  -0.2%    -392    .gnu.version
  -0.0%    -441  [ = ]       0    .debug_abbrev
  -0.1%    -980  -0.1%    -980    .gnu.hash
  -0.2% -1.53Ki  -0.2% -1.53Ki    .hash
  -0.2% -4.59Ki  -0.2% -4.59Ki    .dynsym
  -0.1% -10.5Ki  [ = ]       0    .debug_rnglists
  -0.6% -59.0Ki  -0.6% -59.0Ki    .dynstr
  -0.2%  -191Ki  [ = ]       0    .debug_str_offsets
  -3.0%  -233Ki  -3.0%  -233Ki    .eh_frame_hdr
  -0.7%  -244Ki  [ = ]       0    .debug_addr
  -2.9%  -699Ki  [ = ]       0    .symtab
  -0.6%  -884Ki  [ = ]       0    .debug_line
  -3.0%  -932Ki  -3.0%  -932Ki    .eh_frame
  -1.0% -1.48Mi  -1.0% -1.48Mi    .text
  -0.6% -2.75Mi  [ = ]       0    .debug_info
  -7.3% -8.61Mi  [ = ]       0    .strtab
  -7.3% -17.2Mi  [ = ]       0    .debug_str
  -2.4% -33.0Mi  -0.9% -2.47Mi    TOTAL
```

If anyone's got other ideas for how to reduce this further - it's not
especially important, I just came across it while investigating a debug
info size regression, but thought it was interesting enough to poke
around at.
2022-08-19 04:00:21 +00:00
John Ericson e941b031d3 Revert "[cmake] Use `CMAKE_INSTALL_LIBDIR` too"
This reverts commit f7a33090a9.

Unfortunately this causes a number of failures that didn't show up in my
local build.
2022-08-18 22:46:32 -04:00
Yonghong Song 481d67d310 [Clang][BPF] Support record argument with direct values
Currently, record arguments are always passed by reference by allocating
space for record values in the caller. This is less efficient for
small records which may take one or two registers. For example,
for x86_64 and aarch64, for a record size up to 16 bytes, the record
values can be passed by values directly on the registers.

This patch added BPF support of record argument with direct values
for up to 16 byte record size. If record size is 0, that record
will not take any register, which is the same behavior for x86_64
and aarch64. If the record size is greater than 16 bytes, the
record argument will be passed by reference.

Differential Revision: https://reviews.llvm.org/D132144
2022-08-18 19:11:50 -07:00
Mike Rice 89167e3c5b [OpenMP][NFC] Refactor code for interop parts of 'init' and 'append_args' clauses
The 'init' clause allows an interop-modifier of prefer_type(list) and
and interop-types 'target' and 'targetsync'.

The 'append_args' clause uses an append-op that also includes
interop-types ('target' and 'targetsync') and will allow
a prefer_type list in the next OpenMP version.

This change adds a helper struct OMPInteropInfo and uses it in the parsing
of both the 'init' and 'append_args' clauses.

One OMPInteropInfo object represents the info in a single 'init' clause.
Since 'append_args' allows a variable number of interop items it will
require an array of OMPInteropInfo objects once that is supported.

Differential Revision: https://reviews.llvm.org/D132171
2022-08-18 17:13:30 -07:00
Fangrui Song c2a3888793 [IR] Use Min behavior for module flag "PIC Level"
Using Max for both "PIC Level" and "PIE Level" is inconsistent. PIC imposes less
restriction while PIE imposes more restriction. The result generally
picks the more restrictive behavior: Min for PIC.

This choice matches `ld -r`: a non-pic object and a pic object merge into a
result which should be treated as non-pic.

To allow linking "PIC Level" using Error/Max from old bitcode files, upgrade
Error/Max to Min.

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D130531
2022-08-18 16:28:55 -07:00
Craig Topper 37c47b2cac [RISCV] Change how mtune aliases are implemented.
The previous implementation translated from names like sifive-7-series
to sifive-7-rv32 or sifive-7-rv64. This also required sifive-7-rv32
and sifive-7-rv64 to be valid CPU names. As those are not real
CPUs it doesn't make sense to accept them in -mcpu.

This patch does away with the translation and adds sifive-7-series
directly to RISCV.td. Removing sifive-7-rv32 and sifive-7-rv64.
sifive-7-series is only allowed in -mtune.

I've also added "rocket" to RISCV.td but have not removed rocket-rv32
or rocket-rv64.

To prevent -mcpu=sifive-7-series or -mcpu=rocket being used with llc,
I've added a Feature32Bit to all rv32 CPUs. And made it an error to
have an rv32 triple without Feature32Bit. sifive-7-series and rocket
do not have Feature32Bit or Feature64Bit set so the user would need
to provide -mattr=+32bit or -mattr=+64bit along with the -mcpu to
avoid the error.

SiFive no longer names their newer products with 3, 5, or 7 series.
Instead we have p200 series, x200 series, p500 series, and p600 series.
Following the previous behavior would require a sifive-p500-rv32 and
sifive-p500-rv64 in order to support -mtune=sifive-p500-series. There
is currently no p500 product, but it could start getting confusing if
there was in the future.

I'm open to hearing alternatives for how to achieve my main goal
of removing sifive-7-rv32/rv64 as a CPU name.

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D131708
2022-08-18 16:22:25 -07:00
Chris Bieneman 0ac597f3ca [NFC] Move DXC driver tests
The DXC driver tests don't really belong mixed in with the toolchain
tests. This pulls them out to their own file and moves the
SimpleDiagnosticConsumer into a header so it can be used by both DXC and
toolchain tests.

fast-forwarded.
2022-08-18 16:06:41 -05:00
Alex Brachet c175d80be2 [clang][test] Recognize leading unscore for macos
Additionally mark this test unsupported for ps5 in addition
to ps4, niether support -fuse-ld=
2022-08-18 21:03:28 +00:00
Alex Brachet 377dddf4a0 [clang][Driver] Pass correct reproduce flag to lld-link
Additionally, the explicit linux target has been removed from the test.

Differential Revision: https://reviews.llvm.org/D131214
2022-08-18 20:12:23 +00:00
Prabhdeep Singh Soni bce94ea551 [OMPIRBuilder] Add support for safelen clause
This patch adds OMPIRBuilder support for the safelen clause for the
simd directive.

Reviewed By: shraiysh, Meinersbur

Differential Revision: https://reviews.llvm.org/D131526
2022-08-18 15:43:08 -04:00
John Ericson f7a33090a9 [cmake] Use `CMAKE_INSTALL_LIBDIR` too
We held off on this before as `LLVM_LIBDIR_SUFFIX` conflicted with it.
Now we return this.

`LLVM_LIBDIR_SUFFIX` is kept as a deprecated way to set
`CMAKE_INSTALL_LIBDIR`. The other `*_LIBDIR_SUFFIX` are just removed
entirely.

I imagine this is too potentially-breaking to make LLVM 15. That's fine.
I have a more minimal version of this in the disto (NixOS) patches for
LLVM 15 (like previous versions). This more expansive version I will
test harder after the release is cut.

Reviewed By: sebastian-ne, ldionne, #libc, #libc_abi

Differential Revision: https://reviews.llvm.org/D130586
2022-08-18 15:33:35 -04:00
Joseph Huber ca6d70b32e [LinkerWrapper][NFC] Clean-up error handling
Summary:
We should return and propagate these errors instead of reporting them
immediately. Also use llvm::copy instead.
2022-08-18 15:01:01 -04:00
Xiang Li 140b0bf899 [HLSL] Set main as default entry.
When there's no -E option, use main as entry function.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D124753
2022-08-18 11:57:36 -07:00
Wolfgang Pieb 8564e2fea5 [Inlining] Add a clang option to limit inlining of functions
Add the clang option -finline-max-stacksize=<N> to suppress inlining
of functions whose stack size exceeds the given value.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D131986
2022-08-18 11:56:24 -07:00
Ties Stuij 27cbfa7cc8 [Clang] Propagate const context info when emitting compound literal
This patch fixes a crash when trying to emit a constant compound literal.

For C++ Clang evaluates either casts or binary operations at translation time,
but doesn't pass on the InConstantContext information that was inferred when
parsing the statement.  Because of this, strict FP evaluation (-ftrapping-math)
which shouldn't be in effect yet, then causes checkFloatingpointResult to return
false, which in tryEmitGlobalCompoundLiteral will trigger an assert that the
compound literal wasn't constant.

The discussion here around 'manifestly constant evaluated contexts' was very
helpful to me when trying to understand what LLVM's position is on what
evaluation context should be in effect, together with the explanatory text in
that patch itself:
https://reviews.llvm.org/D87528

Reviewed By: rjmccall, DavidSpickett

Differential Revision: https://reviews.llvm.org/D131555
2022-08-18 11:25:20 +01:00
Utkarsh Saxena 0e0e8b6576 Do not evaluate dependent immediate invocations
We deferred the evaluation of dependent immediate invocations in https://reviews.llvm.org/D119375 until instantiation.
We should also not consider them referenced from a non-consteval context.

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

```
template<typename T>
class Bar {
  consteval static T x() { return 5; }
 public:
  Bar() : a(x()) {}

 private:
  int a;
};

Bar<int> g();
```
Is now accepted by clang. Previously it errored with: `cannot take address of consteval function 'x' outside of an immediate invocation  Bar() : a(x()) {}`

Differential Revision: https://reviews.llvm.org/D132031
2022-08-18 10:30:40 +02:00
Petr Hosek 6741f0f912 Revert "[Driver] Support libc++ in MSVC"
This reverts commit a4230319f7.

This is causing build failures in the 2-stage build.
2022-08-18 08:22:43 +00:00
Vitaly Buka fae656b2dd [test] Add 'hwasan' feature and disable a test 2022-08-17 23:50:35 -07:00
Vitaly Buka 4ceff69636 [test][Sema] Ignore stderr in test
Mixing stdout and stderr may break lines we try to match.
2022-08-17 23:50:35 -07:00
Timm Bäder a2a5470fc2 [clang][Interp] Implement boolean and nullptr literals
Handle CXX bool literals as well as nullptr literals and add a few tests
for each.

Differential Revision: https://reviews.llvm.org/D131942
2022-08-18 07:11:48 +02:00
Petr Hosek a4230319f7 [Driver] Support libc++ in MSVC
This implements support for using libc++ headers in MSVC toolchain.
We only support libc++ headers that are part of the toolchain, and
not headers installed elsewhere on the system.

Differential Revision: https://reviews.llvm.org/D101479
2022-08-18 04:04:40 +00:00
Vitaly Buka 3f5f2905c4 [test] Propagate HWASAN_OPTIONS 2022-08-17 18:59:49 -07:00
Vitaly Buka 36c9f5a58b [NFC][OpenMP] Simplify 2f9be69d84 2022-08-17 18:59:48 -07:00
owenca 777b6ad168 [clang-format] Handle return type auto followed by l_paren
Fixes #57160.

Differential Revision: https://reviews.llvm.org/D132008
2022-08-17 16:06:34 -07:00
Shafik Yaghmour 8de51375f1 [Clang] Tighten restrictions on enum out of range diagnostic to avoid constant initialization
The restrictions added in D131704 were not sufficient to avoid all non-constant
expression contexts. In particular constant initialization cases.

We need to check EvaluatingDecl to detect if the variable we are initializing is
constexpr or not.

At this point it looks like this is the remaining case affecting various projects
with this diagnostic.

Differential Revision: https://reviews.llvm.org/D131874
2022-08-17 14:14:00 -07:00
Aaron Ballman 74b5dad5e9 Add N2653 to the C2x status page
This was accidentally missing from the Feb 2022 paper section.
2022-08-17 11:30:31 -04:00
Paul Kirth 656c5d652c [clang][llvm][NFC] Change misexpect's tolerance option to be 32-bit
In D131869 we noticed that we jump through some hoops because we parse the
tolerance option used in MisExpect.cpp into a 64-bit integer. This is
unnecessary, since the value can only be in the range [0, 100).

This patch changes the underlying type to be 32-bit from where it is
parsed in Clang through to it's use in LLVM.

Reviewed By: jloser

Differential Revision: https://reviews.llvm.org/D131935
2022-08-17 14:38:53 +00:00
Erich Keane d483730d8c Re-apply "Deferred Concept Instantiation Implementation""
This reverts commit 258c3aee54.

This should fix the libc++ issue that caused the revert, by re-designing
slightly how we determined when we should evaluate the constraints.
Additionally, many of the other components to the original patch (the
NFC parts) were committed separately to shrink the size of this patch
for review.

Differential Revision: https://reviews.llvm.org/D126907
2022-08-17 06:24:40 -07:00
Aaron Ballman d7e06d5675 Update the status of some more C99 features
This also adds some test coverage to demonstrate we implement what was
standardized.
2022-08-17 08:11:56 -04:00
Serge Pavlov 956f8c0e10 [Driver] Override default location of config files
If directory for config files was specified in project configuration
using parameters CLANG_CONFIG_FILE_SYSTEM_DIR or CLANG_CONFIG_FILE_USER_DIR,
it was not overriden by command-line option `--config-system-dir=` or
`--config-user-dir=` that specified empty path.

This change corrects the behavior. It fixes the issue
https://github.com/llvm/llvm-project/issues/56836 ([clang] [test]
test/Driver/config-file-errs.c fails if CLANG_CONFIG_FILE_SYSTEM_DIR is
specified).
2022-08-17 18:52:53 +07:00
Yuanfang Chen b296aed8ae [clang] fix a typo in da6187f566 2022-08-17 01:27:12 -07:00
Denis Fatkulin 8837ef4d37
[clang] Apply FixIts to members declared via `using` in derived classes
FixIt don't switch to arrow in derrived members with `using`

Example code:
```
struct Bar {
  void foo();
};
struct Baz {
  using Bar::foo;
};
void test(Baz* ptr) {
  ptr.^
}

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D131088
2022-08-17 10:09:48 +02:00
Furkan Usta 4dd71b3cb9
[clang] Give priority to Class context while parsing declarations
Fixes https://github.com/clangd/clangd/issues/290.

Reviewed By: kadircet

Differential Revision: https://reviews.llvm.org/D130363
2022-08-17 10:06:39 +02:00
Carlos Alberto Enciso 177cbb1c9b [CMake] Explicit bootstrap options override any passthrough ones.
The https://reviews.llvm.org/D53014 added CMAKE_BUILD_TYPE to
the list of BOOTSTRAP_DEFAULT_PASSTHROUGH variables.

The downside is that both stage-1 and stage-2 configurations
are the same. So it is not possible to build different stage
configurations.

This patch allow explicit bootstrap options to override any
passthrough ones.

For instance, the following settings would build:
  stage-1 (Release) and stage-2(Debug)

-DCMAKE_BUILD_TYPE=Release -DBOOTSTRAP_CMAKE_BUILD_TYPE=Debug

Reviewed By: @beanz

Differential Revision: https://reviews.llvm.org/D131755
2022-08-17 08:16:10 +01:00
owenca 2185f64771 [clang-format] Handle comments between access specifier and colon
Fixes #56740.

Differential Revision: https://reviews.llvm.org/D131940
2022-08-16 20:18:21 -07:00
Yuanfang Chen da6187f566 [Clang] followup D128745, add a missing ClangABICompat check 2022-08-16 18:40:00 -07:00
David Blaikie 06c70e9b99 DebugInfo: Remove auto return type representation support
Seems this complicated lldb sufficiently for some cases that it hasn't
been worth supporting/fixing there - and it so far hasn't provided any
new use cases/value for debug info consumers, so let's remove it until
someone has a use case for it.

(side note: the original implementation of this still had a bug (I
should've caught it in review) that we still didn't produce
auto-returning function declarations in types where the function wasn't
instantiatied (that requires a fix to remove the `if
getContainedAutoType` condition in
`CGDebugInfo::CollectCXXMemberFunctions` - without that, auto returning
functions were still being handled the same as member function templates
and special member functions - never added to the member list, only
attached to the type via the declaration chain from the definition)

Further discussion about this in D123319

This reverts commit 5ff992bca208a0e37ca6338fc735aec6aa848b72: [DEBUG-INFO] Change how we handle auto return types for lambda operator() to be consistent with gcc

This reverts commit c83602fdf51b2692e3bacb06bf861f20f74e987f: [DWARF5][clang]: Added support for DebugInfo generation for auto return type for C++ member functions.

Differential Revision: https://reviews.llvm.org/D131933
2022-08-17 00:35:05 +00:00
Yonghong Song d9198f64d9 [Clang][BPF]: Force sign/zero extension for return values in caller
Currently bpf supports calling kernel functions (x86_64, arm64, etc.)
in bpf programs. Tejun discovered a problem where the x86_64 func
return value (a unsigned char type) is stored in 8-bit subregister %al
and the other 56-bits in %rax might be garbage. But based on current
bpf ABI, the bpf program assumes the whole %rax holds the correct value
as the callee is supposed to do necessary sign/zero extension.
This mismatch between bpf and x86_64 caused the incorrect results.

To resolve this problem, this patch forced caller to do needed
sign/zero extension for 8/16-bit return values as well. Note that
32-bit return values already had sign/zero extension even without
this patch.

For example, for the test case attached to this patch:

  $  cat t.c
  _Bool bar_bool(void);
  unsigned char bar_char(void);
  short bar_short(void);
  int bar_int(void);
  int foo_bool(void) {
        if (bar_bool() != 1) return 0; else return 1;
  }
  int foo_char(void) {
        if (bar_char() != 10) return 0; else return 1;
  }
  int foo_short(void) {
        if (bar_short() != 10) return 0; else return 1;
  }
  int foo_int(void) {
        if (bar_int() != 10) return 0; else return 1;
  }

Without this patch, generated call insns in IR looks like:
    %call = call zeroext i1 @bar_bool()
    %call = call zeroext i8 @bar_char()
    %call = call signext i16 @bar_short()
    %call = call i32 @bar_int()
So it is assumed that zero extension has been done for return values of
bar_bool()and bar_char(). Sign extension has been done for the return
value of bar_short(). The return value of bar_int() does not have any
assumption so caller needs to do necessary shifting to get correct
32bit values.

With this patch, generated call insns in IR looks like:
    %call = call i1 @bar_bool()
    %call = call i8 @bar_char()
    %call = call i16 @bar_short()
    %call = call i32 @bar_int()
There are no assumptions for return values of the above four function calls,
so necessary shifting is necessary for all of them.

The following is the objdump file difference for function foo_char().
Without this patch:
  0000000000000010 <foo_char>:
       2:       85 10 00 00 ff ff ff ff call -1
       3:       bf 01 00 00 00 00 00 00 r1 = r0
       4:       b7 00 00 00 01 00 00 00 r0 = 1
       5:       15 01 01 00 0a 00 00 00 if r1 == 10 goto +1 <LBB1_2>
       6:       b7 00 00 00 00 00 00 00 r0 = 0
  0000000000000038 <LBB1_2>:
       7:       95 00 00 00 00 00 00 00 exit

With this patch:
  0000000000000018 <foo_char>:
       3:       85 10 00 00 ff ff ff ff call -1
       4:       bf 01 00 00 00 00 00 00 r1 = r0
       5:       57 01 00 00 ff 00 00 00 r1 &= 255
       6:       b7 00 00 00 01 00 00 00 r0 = 1
       7:       15 01 01 00 0a 00 00 00 if r1 == 10 goto +1 <LBB1_2>
       8:       b7 00 00 00 00 00 00 00 r0 = 0
  0000000000000048 <LBB1_2>:
       9:       95 00 00 00 00 00 00 00 exit
The zero extension of the return 'char' value is done here.

Differential Revision: https://reviews.llvm.org/D131598
2022-08-16 16:08:01 -07:00
Alexander Shaposhnikov d68ba43ad2 [Intrinsics] Add initial support for NonNull attribute
Add initial support for NonNull attribute.
(https://github.com/llvm/llvm-project/issues/57113)

Test plan:

verify that for
__thread int x;
int main() {

int* y = &x;
return *y;
}
(with this patch) clang -O -fsanitize=null -S -emit-llvm -o -
doesn't emit a null-pointer check

Differential revision: https://reviews.llvm.org/D131872
2022-08-16 21:28:23 +00:00
Saleem Abdulrasool 585f62be1a CodeGen: correct handling of debug info generation for aliases
When aliasing a static array, the aliasee is going to be a GEP which
points to the value.  We should strip pointer casts before forming the
reference.  This was occluded by the use of opaque pointers.

This problem has existed since the introduction of the debug info
generation for aliases in b1ea0191a4.  The
test case would assert due to the invalid cast with or without
`-no-opaque-pointers` at that revision.

Fixes: #57179
2022-08-16 21:27:05 +00:00
Ben Langmuir 5482432bf6 [clang][deps] Compute command-lines for dependencies immediately
Instead of delaying the generation of command-lines to after all
dependencies are reported, compute them immediately. This is partly in
preparation for splitting the TU driver command into its constituent cc1
and other jobs, but it also just simplifies working with the compiler
invocation for modules if they are not "without paths".

Also change the computation of the default output path in
clang-scan-deps to scrape the implicit module cache from the
command-line rather than get it from the dependency, since that is now
unavailable at the time we make the callback.

Differential Revision: https://reviews.llvm.org/D131934
2022-08-16 14:25:27 -07:00
Roy Jacobson 68786f0632 [Sema] Fix friend destructor declarations after D130936
I accidentally broke friend destructor declarations in D130936.

Modify it to skip performing the destructor name check if we have a dependent friend declaration.

Reviewed By: hubert.reinterpretcast

Differential Revision: https://reviews.llvm.org/D131541
2022-08-16 22:28:19 +03:00
Lei Huang 7d8ae9f755 [NFC][PowerPC] Add missing NOCOMPAT checks for builtins-ppc-xlcompat.c
Followup patch to address request from https://reviews.llvm.org/D124093

Reviewed By: amyk

Differential Revision: https://reviews.llvm.org/D131622
2022-08-16 13:56:33 -05:00
Dmitri Gribenko 941959d69d [clang][dataflow] Use llvm::is_contained()
Reviewed By: samestep, xazax.hun

Differential Revision: https://reviews.llvm.org/D131975
2022-08-16 19:59:21 +02:00
Arthur Eubanks 9181ce623f [Windows] Put init_seg(compiler/lib) in llvm.global_ctors
Currently we treat initializers with init_seg(compiler/lib) as similar
to any other init_seg, they simply have a global variable in the proper
section (".CRT$XCC" for compiler/".CRT$XCL" for lib) and are added to
llvm.used. However, this doesn't match with how LLVM sees normal (or
init_seg(user)) initializers via llvm.global_ctors. This
causes issues like incorrect init_seg(compiler) vs init_seg(user)
ordering due to GlobalOpt evaluating constructors, and the
ability to remove init_seg(compiler/lib) initializers at all.

Currently we use 'A' for priorities less than 200. Use 200 for
init_seg(compiler) (".CRT$XCC") and 400 for init_seg(lib) (".CRT$XCL"),
which do not append the priority to the section name. Priorities
between 200 and 400 use ".CRT$XCC${Priority}". This allows for
some wiggle room for people/future extensions that want to add
initializers between compiler and lib.

Fixes #56922

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D131910
2022-08-16 08:16:18 -07:00
Fred Tingaud ba1c396e09 MSVC compatibility mode: fix error on unqualified templated base class initialization in case of partial specialization
I introduced a patch to handle unqualified templated base class
initialization in MSVC compatibility mode:
https://reviews.llvm.org/rGc894e85fc64dd8d83b460de81080fff93c5ca334
We identified a problem with this patch in the case where the base class
is partially specialized, which can lead to triggering an assertion in
the case of a mix between types and values.
The minimal test case is:

  template <typename Type, int TSize> class Vec {};
  template <int TDim> class Index : public Vec<int, TDim> {
    Index() : Vec() {}
  };
  template class Index<0>;

The detailed problem is that I was using the
`InjectedClassNameSpecialization`, to which the class template arguments
were then applied in order. But in the process, we were losing all the
partial specializations of the base class and creating an index mismatch
between the expected and passed arguments.

Patch By: frederic-tingaud-sonarsource

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D130709
2022-08-16 17:09:55 +02:00
Louis Dionne 65d83ba343 [clang][Darwin] Re-apply "Always set the default C++ Standard Library to libc++"
Newer SDKs don't even provide libstdc++ headers, so it's effectively
never valid to build for libstdc++ unless the user explicitly asks
for it (in which case they will need to provide include paths and more).

This is a re-application of c5ccb78ade which had been reverted in
33171df9cc because it broke the Fuchsia CI bots. The issue was that
the test was XPASSing because it didn't fail anymore when the
CLANG_DEFAULT_CXX_LIB was set to libc++, which seems to be done for
Fuchsia. Instead, the test only fails if CLANG_DEFAULT_CXX_LIB is
set to libstdc++.

As a fly-by fix, also adjust the triple used by various tests to
something that is supported. Those tests were shown to fail on
internal bots.

Differential Revision: https://reviews.llvm.org/D131274
2022-08-16 09:27:18 -04:00
YingChi Long ccbc22cd89
[Sema] fix false -Wcomma being emitted from void returning functions
Fixes https://github.com/llvm/llvm-project/issues/57151

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D131892
2022-08-16 20:44:38 +08:00
Nikita Popov 8f555a52e0 [cmake] Fix tablegen exports
This fixes some fallout from D131282. Currently, add_tablegen() will add the tablegen target to LLVM_EXPORTS and associates the install with LLVMExports. For non-standalone builds, this means that you end up with mlir-tblgen and clang-tblgen in LLVMExports.

However, these projects should instead be using MLIR_EXPORTS/MLIRTargets and CLANG_EXPORTS/ClangTargets. To fix this, add an extra EXPORT option and make use of get_target_export_arg() to create the correct export argument.

Reviewed By: ashay-github

Differential Revision: https://reviews.llvm.org/D131565
2022-08-16 14:17:23 +02:00
Clement Courbet 672311bd77 [CFG] Fix crash on CFG building when deriving from a template.
Differential Revision: https://reviews.llvm.org/D121365
2022-08-16 13:01:13 +02:00
Chuanqi Xu efa8783290 [NFC] Add unittest for inline functions in modules 2022-08-16 13:35:38 +08:00
Danil Sidoruk d8d331bc97 [clang-format] Fix aligning of java-style declarations
- Modify TokenAnnotator to work fine with java-style array declarations.
- Add test for aligning of java declarations.

Fixes #55931.

Differential Revision: https://reviews.llvm.org/D129628
2022-08-15 20:27:15 -07:00
Ben Shi f45d89d73d [Driver] Support linking to compiler-rt for target AVR
Reviewed By: aykevl

Differential Revision: https://reviews.llvm.org/D128133
2022-08-16 09:22:50 +08:00
Ben Shi 65c022a75f Revert "[Driver] Support linking to compiler-rt for target AVR"
This reverts commit 44a647d21d.
2022-08-16 07:55:41 +08:00
Sam Estep 2efc8f8d65 [clang][dataflow] Add an option for context-sensitive depth
This patch adds a `Depth` field (default value 2) to `ContextSensitiveOptions`, allowing context-sensitive analysis of functions that call other functions. This also requires replacing the `DeclCtx` field on `Environment` with a `CallString` field that contains a vector of decl contexts, to ensure that the analysis doesn't try to analyze recursive or mutually recursive calls (which would result in a crash, due to the way we handle `StorageLocation`s).

Reviewed By: xazax.hun

Differential Revision: https://reviews.llvm.org/D131809
2022-08-15 19:58:40 +00:00
Alan Zhao ff8aadf58d [clang][diagnostics] Don't warn about unreachable code in constexpr if
The point of a constexpr if statement is to determine which branch to
take at compile time, so warning on unreachable code is meaningless in
these situations.

Fixes #57123.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D131818
2022-08-15 15:24:39 -04:00
Arthur Eubanks 465d9084ec [test][clang] Opaquify pragma-init_seg.cpp 2022-08-15 10:45:24 -07:00
Aaron Ballman f37b285299 Removing an unused function; NFC
It turns out there are zero in-tree callers of CallExpr::getNumCommas()
so it's reasonable to remove.
2022-08-15 13:35:16 -04:00
Matheus Izvekov b8a1b698af
[clang] fix missing initialization of original number of expansions
When expanding undeclared function parameters, we should initialize
the original number of expansions, if known, before trying to expand
them, otherwise a length mismatch with an outer pack might not be
diagnosed.

Fixes PR56094.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D131802
2022-08-15 17:39:38 +02:00
Kazu Hirata f5a68feab3 Use llvm::none_of (NFC) 2022-08-14 16:25:39 -07:00
Kazu Hirata 6d9cd9199a Use llvm::all_of (NFC) 2022-08-14 16:25:36 -07:00
Yuanfang Chen 6afcc4a459 [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template
DR692 handles two cases: pack expansion (for class/var template) and function parameter pack. The former needs DR1432 as a fix, and the latter needs DR1395 as a fix. However, DR1432 has not yet made a wording change. so I made a tentative fix for DR1432 with the same spirit as DR1395.

Reviewed By: aaron.ballman, erichkeane, #clang-language-wg

Differential Revision: https://reviews.llvm.org/D128745
2022-08-14 14:37:40 -07:00
Justin Stitt 333771f355 [Sema] Avoid isNullPointerConstant invocation
DiagnoseNullConversion is needlessly calling isNullPointerConstant which
is an expensive routine due to its calls to a constant evaluator --
which we don't need.

Building the Linux Kernel (x86_64) with this fix has improved build
times by ~2.1%. This is mainly due to the following methods no longer
needing to be called anywhere near as often:
1) ExprConstant::CheckICE (reduced CPU cycles by ~90%)
2) IntExprEvaluator::VisitBinaryOperator (reduced CPU cycles by ~50%)

Reviewed By: rtrieu, nickdesaulniers

Differential Revision: https://reviews.llvm.org/D131532
2022-08-14 13:39:57 -07:00
Nico Weber aacf1a9742 Revert "[clang] adds unary type transformations as compiler built-ins"
This reverts commit bc60cf2368.
Doesn't build on Windows and breaks gcc 9 build, see
https://reviews.llvm.org/D116203#3722094 and
https://reviews.llvm.org/D116203#3722128

Also revert two follow-ups. One fixed a warning added in
bc60cf2368, the other
makes use of the feature added in bc60cf2368
in libc++:

Revert "[libcxx][NFC] utilises compiler builtins for unary transform type-traits"
This reverts commit 06a1d917ef.

Revert "[Sema] Fix a warning"
This reverts commit c85abbe879.
2022-08-14 15:58:21 -04:00
Kazu Hirata c85abbe879 [Sema] Fix a warning
This patch fixes:

  clang/lib/Sema/SemaType.cpp:9469:3: error: default label in switch
  which covers all enumeration values
  [-Werror,-Wcovered-switch-default]
2022-08-14 11:25:19 -07:00
Christopher Di Bella bc60cf2368 [clang] adds unary type transformations as compiler built-ins
Adds

* `__add_lvalue_reference`
* `__add_pointer`
* `__add_rvalue_reference`
* `__decay`
* `__make_signed`
* `__make_unsigned`
* `__remove_all_extents`
* `__remove_extent`
* `__remove_const`
* `__remove_volatile`
* `__remove_cv`
* `__remove_pointer`
* `__remove_reference`
* `__remove_cvref`

These are all compiler built-in equivalents of the unary type traits
found in [[meta.trans]][1]. The compiler already has all of the
information it needs to answer these transformations, so we can skip
needing to make partial specialisations in standard library
implementations (we already do this for a lot of the query traits). This
will hopefully improve compile times, as we won't need use as much
memory in such a base part of the standard library.

[1]: http://wg21.link/meta.trans

Co-authored-by: zoecarver

Reviewed By: aaron.ballman, rsmith

Differential Revision: https://reviews.llvm.org/D116203
2022-08-14 17:12:15 +00:00
Mark de Wever 2fd2f2644b [clang][doc] Removes an extra space. 2022-08-14 15:16:43 +02:00
Kazu Hirata 2febc32c9c Use llvm::erase_if (NFC) 2022-08-13 12:55:48 -07:00
Kazu Hirata 2b43bd0bd9 Remove unused forward declarations (NFC) 2022-08-13 12:55:47 -07:00
Zachary Henkel 64f0f7e646 __has_trivial_copy should map to __is_trivially_copyable
Found during clang 15 RC1 testing due to the new diagnostic added by @royjacobson since clang 14.  Uncertain if this fix meets the bar to also be applied to the release branch.

If accepted, I'll need someone with commit access to submit on my behalf.

Reviewed By: royjacobson, aaron.ballman, erichkeane

Differential Revision: https://reviews.llvm.org/D131730
2022-08-13 22:54:52 +03:00
Vitaly Buka 2f9be69d84 [OpenMP] Fix another after scope after D129608
https://lab.llvm.org/buildbot/#/builders/5/builds/26770
2022-08-13 12:13:54 -07:00
Kazu Hirata 2117fcb1c0 Use Optional::transform instead of Optional::map (NFC)
I'm planning to deprecate map in favor of transform for consistency
with std::optional::transform in C++23.
2022-08-13 11:48:26 -07:00
Vitaly Buka f385eaf48f [OpenMP] Fix use after scope after D129608
Broken builder https://lab.llvm.org/buildbot/#/builders/5/builds/26764
2022-08-13 09:40:51 -07:00
Aaron Ballman ba79c2a250 Update the implementation status of some C11 features
This also starts to add some test coverage for specific papers to
validate conformance against.
2022-08-13 10:17:47 -04:00
Ben Shi 44a647d21d [Driver] Support linking to compiler-rt for target AVR
Reviewed By: aykevl

Differential Revision: https://reviews.llvm.org/D128133
2022-08-13 20:40:21 +08:00
Fangrui Song 452fbbda39 [Driver] Use addOptInFlag. NFC 2022-08-13 00:51:04 -07:00
jackh ef71383b0c [clang-format] Distinguish logical and after bracket from reference
Fix commit `b646f0955574` and remove redundant code.

Differential Revision: https://reviews.llvm.org/D131750
2022-08-13 11:52:23 +08:00
Jennifer Yu 2ca27206f9 [OpenMP] Fix segmentation fault when data field is used in is_device_pt
Currently, the field just emit map info for this pointer variable. It is
failed at run time. For the fields, the PartialStruct is created and it
needs call to emitCombinedEntry which create the base that covers all
the pieces.

The change is to generate map info as regular fields.

Differential Revision: https://reviews.llvm.org/D129608
2022-08-12 17:10:26 -07:00
Usman Nadeem 405ad84793 Update hwasan test to fix failure on older Android API versions.
In Android API < 30 there is no HWAsan instrumentation support for globals
so the test fails if API < 30 or if the target triple does not specify the API version.

Add -triple=aarch64-linux-android31 to enable global instrumentation. This is the
same triple as is used in the RUN line for -fsanitize=memtag-globals.

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

Change-Id: I300703bd126b10e3c52505e23c78c5a48acb0309
2022-08-12 16:30:08 -07:00
isuckatcs b4e3e3a3eb [analyzer] Fix a crash on copy elided initialized lambda captures
Inside `ExprEngine::VisitLambdaExpr()` we wasn't prepared for a
copy elided initialized capture's `InitExpr`. This patch teaches
the analyzer how to handle such situation.

Differential Revision: https://reviews.llvm.org/D131784
2022-08-13 00:22:01 +02:00
Sam Estep b3f1a6bf10 [clang][dataflow] Encode options using llvm::Optional
This patch restructures `DataflowAnalysisOptions` and `TransferOptions` to use `llvm::Optional`, in preparation for adding more sub-options to the `ContextSensitiveOptions` struct introduced here.

Reviewed By: sgatev, xazax.hun

Differential Revision: https://reviews.llvm.org/D131779
2022-08-12 16:29:41 +00:00
YingChi Long e5825190b8
[clang] fix frontend crash when evaluating type trait
Before this patch type traits are checked in Parser, so use type traits
directly did not cause assertion faults. However if type traits are initialized
from a template, we didn't perform arity checks before evaluating. This
patch moves arity checks from Parser to Sema, and performing arity
checks in Sema actions, so type traits get checked corretly.

Crash input:

```
template<class... Ts> bool b = __is_constructible(Ts...);
bool x = b<>;
```

After this patch:

```
clang/test/SemaCXX/type-trait-eval-crash-issue-57008.cpp:5:32: error: type trait requires 1 or more arguments; have 0 arguments
template<class... Ts> bool b = __is_constructible(Ts...);
                               ^~~~~~~~~~~~~~~~~~
clang/test/SemaCXX/type-trait-eval-crash-issue-57008.cpp:6:10: note: in instantiation of variable template specialization 'b<>' requested here
bool x = b<>;
         ^
1 error generated.
```

See https://godbolt.org/z/q39W78hsK.

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

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D131423
2022-08-13 00:02:19 +08:00
Ilya Biryukov fba88adc89 [Sema] Always perform ADL when searching for transormed operators in C++20
This fixes compilation errors in the following code with
latest libc++ and libstdc++:
```cpp

int main() {
  std::tuple<std::string> s;
  std::tuple<std::string_view> sv;
  s < sv;
}
```

See https://gcc.godbolt.org/z/vGvEhxWvh for the error.

This used to happen because repeated template instantiations during
C++20 constraint satisfaction will cause a call to `RebuildCXXRewrittenBinaryOperator`
with `PerformADL` set to false, see 59351fe340/clang/lib/Sema/TreeTransform.h (L2737)

Committing urgently to unbreak breakages we see in our configurations.
The change seems relatively safe and the right thing to do.

However, I will follow-up with tests and investigation on whether we
need to do this extra semantic checking in the first place next week.
2022-08-12 16:07:02 +02:00
Joe Loser e8578968f6
[ADT] Replace STLForwardCompat.h's C++17 equivalents
STLForwardCompat.h defines several utilities and type traits to mimic that of
the ones in the C++17 standard library. Now that LLVM is built with the C++17
standards mode, remove use of these equivalents in favor of the ones from the
standard library.

Differential Revision: https://reviews.llvm.org/D131717
2022-08-12 06:55:59 -06:00
Maciej Gabka 48e1250a91 [clang][SVE] Undefine preprocessor macro defined in
arm_sve.h defines and uses __ai macro which needs to be undefined (as it is
already in arm_neon.h).

Reviewed By: paulwalker-arm

Differential Revision: https://reviews.llvm.org/D131580
2022-08-12 12:25:49 +00:00
Utkarsh Saxena 72ac7cac3f Handle explicitly defaulted consteval special members.
Followup patch for D128083

Previously, using a non-consteval constructor from an consteval constructor would code generates the consteval constructor.
Example
```
template <typename T>
struct S {
  T i;
  consteval S() = default;
};
struct Foo {
    Foo() {}
};
void func() {
  S<Foo> three; // incorrectly accepted by clang.
}
```

This happened because clang erroneously disregards `consteval` specifier for a `consteval explicitly defaulted special member functions in a class template` if it has dependent data members without a `consteval default constructor`.

According to
```
C++14 [dcl.constexpr]p6 (CWG DR647/CWG DR1358):
If the instantiated template specialization of a constexpr function
template or member function of a class template would fail to satisfy
the requirements for a constexpr function or constexpr constructor, that
specialization is still a constexpr function or constexpr constructor,
even though a call to such a function cannot appear in a constant
expression.
```

Therefore the `consteval defaulted constructor of a class template` should be considered `consteval` even if the data members' default constructors are not consteval.
Keeping this constructor `consteval` allows complaining while processing the call to data member constructors.
(Same applies for other special member functions).

This works fine even when we have more than one default constructors since we process the constructors after the templates are instantiated.

This does not address initialization issues raised in
[2602](https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2602) and compiler divergence seen in https://godbolt.org/z/va9EMvvMe

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

Differential Revision: https://reviews.llvm.org/D131479
2022-08-12 12:13:06 +02:00
Martin Storsjö e6db064394 [doc] Remove release notes from the main branch for changes that were backported to 15.x 2022-08-12 11:21:51 +03:00
Chuanqi Xu e190b7cc90 [Coroutines] Maintain the position of final suspend
Closing https://github.com/llvm/llvm-project/issues/56329

The problem happens when we try to simplify the suspend points. We might
break the assumption that the final suspend lives in the last slot of
Shape.CoroSuspends. This patch tries to main the assumption and fixes
the problem.
2022-08-12 13:05:08 +08:00
Tom Stellard 74384c7fce Disable update_cc_test_checks.py tests in stand-alone builds
The script is located in the llvm/ sub-directory, so it is not available
for when doing a stand-alone build.

See https://discourse.llvm.org/t/rfc-stand-alone-build-support/61291

Differential Revision: https://reviews.llvm.org/D123967
2022-08-11 20:53:37 -07:00
Chuanqi Xu 0bc993edf4 [AST] [Modules] Introduce Decl::getNonTransparentDeclContext to handle exported friends
Closing https://github.com/llvm/llvm-project/issues/56826.

The root cause for pr56826 is: when we collect the template args for the
friend, we need to judge if the friend lives in file context. However,
if the friend lives in ExportDecl lexically, the judgement here is
invalid.

The solution is easy. We should judge the non transparent context and
the ExportDecl is transparent context. So the solution should be good.

A main concern may be the patch doesn't handle all the places of the
same defect. I think it might not be bad since the patch itself should
be innocent.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D131651
2022-08-12 11:50:35 +08:00
Ivan Murashko 557e32e002 [clang] SIGSEGV fix at clang::ASTContext::getRawCommentForDeclNoCacheImpl
The `File` might point to an invalid `FileID` when the AST is broken. That leads to clang/clangd crashes while processing comments. The relevant part of the crash is below
```
 #4 0x00007f1d7fbf95bc std::_Rb_tree<unsigned int, std::pair<unsigned int const, clang::RawComment*>, std::_Select1st<std::pair<unsigned int const, clang::RawComment*>>, std::less<unsigned int>, std::allocator<std::pair<unsigned int const
, clang::RawComment*>>>::_M_lower_bound(std::_Rb_tree_node<std::pair<unsigned int const, clang::RawComment*>> const*, std::_Rb_tree_node_base const*, unsigned int const&) const /usr/include/c++/8/bits/stl_tree.h:1911:2
 #5 0x00007f1d7fbf95bc std::_Rb_tree<unsigned int, std::pair<unsigned int const, clang::RawComment*>, std::_Select1st<std::pair<unsigned int const, clang::RawComment*>>, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, clang::RawComment*>>>::lower_bound(unsigned int const&) const /usr/include/c++/8/bits/stl_tree.h:1214:56
 #6 0x00007f1d7fbf95bc std::map<unsigned int, clang::RawComment*, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, clang::RawComment*>>>::lower_bound(unsigned int const&) const /usr/include/c++/8/bits/stl_map.h:1264:36
 #7 0x00007f1d7fbf95bc clang::ASTContext::getRawCommentForDeclNoCacheImpl(clang::Decl const*, clang::SourceLocation, std::map<unsigned int, clang::RawComment*, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, clang::RawComment*>>> const&) const /home/ivanmurashko/local/llvm-project/clang/lib/AST/ASTContext.cpp:226:57
```

The corresponding LIT test that reproduces the crash was also added

Same issue is described at https://bugs.llvm.org/show_bug.cgi?id=49707

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D131675
2022-08-12 00:05:59 +01:00
Shafik Yaghmour 106774515b [Clang] Fix for Tighten restrictions on enum out of range diagnostic
Ok it looks like this is a bit more subtle, I broke the llvm-test-suite file
paq8p.cpp again. We need both conditions to be true Info.EvalMode ==
EvalInfo::EM_ConstantExpression && Info.InConstantContext. We need to be in a
context that requires a constant value but also in a constant expression context.

Differential Revision: https://reviews.llvm.org/D131704
2022-08-11 15:34:58 -07:00
Shafik Yaghmour 2608f553b8 [Clang] Tighten restrictions on enum out of range diagnostic
In D131528 using Info.EvalMode == EvalInfo::EM_ConstantExpression is not strict
enough to restrict the diagnostic to only constant expression contexts. It is
sometimes set in cases where we are still determining if we are in a constant
expression context.

Using InConstantContext will tighten the restriction.

Differential Revision: https://reviews.llvm.org/D131704
2022-08-11 13:44:26 -07:00
Denys Petrov adcd4b1c0b [analyzer] [NFC] Fix comments into more regular form. 2022-08-11 21:28:23 +03:00
Alex Bradbury d17de5479c [clang][RISCV][test] Add test that shows incorrect ABI lowering
As reported in <https://github.com/llvm/llvm-project/issues/57084>,
under hard float ABIs there are issues with lowering structs that
inherit from other structs.

See <https://reviews.llvm.org/D131677> for a fix.
2022-08-11 18:51:37 +01:00
Aaron Ballman b48fb85fe6 Fix crash-on-valid with consteval temporary construction through list initialization
Clang currently crashes when lowering a consteval list initialization
of a temporary. This is partially working around an issue in the
template instantiation code (TreeTransform::TransformCXXTemporaryObjectExpr())
that does not yet know how to handle list initialization of temporaries
in all cases. However, it's also helping reduce fragility by ensuring
we always have a valid QualType when trying to emit a constant
expression during IR generation.

Fixes #55871

Differential Revision: https://reviews.llvm.org/D131194
2022-08-11 13:44:24 -04:00
Craig Topper dacbddf562 [RISCV] Move isValidCPUName to RISCVTargetInfo. NFC
Instead of having separate implementations for RV32 and RV64,
use the triple to control the Is64Bit parameter.

Do the same for isValidTuneCPUName, fillValidCPUList, and
fillValidTuneCPUList.
2022-08-11 10:01:56 -07:00
Mike Rice dd4c838da3 [OpenMP] Allow data members in interop init/use/destroy clauses
Previously a diagnostic was given if the expression was not strictly a
DeclRef. Now also allow use of data members inside member functions.

Differential Revision: https://reviews.llvm.org/D131222
2022-08-11 09:39:12 -07:00
Simon Pilgrim 08a880509e [X86] Add RDPRU instruction CPUID bit masks
As mentioned on D128934 - we weren't including the CPUID bit handling for the RDPRU instruction

AMD's APMv3 (24594) lists it as CPUID Fn8000_0008_EBX Bit#4
2022-08-11 16:07:36 +01:00
Simon Pilgrim 6e19e6ce36 [clang][X86] Add RDPRU predefined macro tests for znver2/znver3 targets
These were missed in D128934
2022-08-11 15:48:39 +01:00
Balazs Benics 5e876c54f2 [analyzer] exploded-graph-rewriter: Fix python3 string encoding issues
This encapsulates 3 changes:
 - `DotDumpVisitor` now aggregates strings instead of *bytes* for both
   `python2` and `python3`. This difference caused crashes when it tried
    to write out the content as *strings*, similarly described at D71746.
 - `graphviz.pipe()` expects the input in *bytes* instead of unicode
   strings. And it results in *bytes*. Due to string concatenations and
   similar operations, I'm using unicode string as the default, and
   converting to *bytes* on demand.
 - `write_temp_file()` now appends the `egraph-` prefix and more
   importantly, it will create the temp file in the **current working
   directory** instead of in the *temp*. This change makes `Firefox` be
   able to open the file even if the `security.sandbox.content.level` is
   set to the (default) most restricting `4`.
   See https://support.mozilla.org/si/questions/1259285

An artifact of the bad byte handling was previously in the `HTML`
produced by the script that it displayed the `b'` string at the top left
corner. Now it won't anymore :)

I've tested that the following command works on `Ubuntu 22.04`:
```
exploded-graph-rewriter my-egraph.dot
```
Both `python2` and `python3` works as expected.

PS: I'm not adding tests, as the current test infra does not support
testing HTML outputs for this script.
Check the `clang/test/Analysis/exploded-graph-rewriter/lit.local.cfg`.
We always pass the `--dump-dot-only` flag to the script.
Along with that, the default invocation will not only create this HTML
report but also try to open it. In addition to this, I'm not sure if the
buildbots have `graphviz` installed and also if this package is installed
on `pip`.
Unless we change some of these, we cannot test this change.
Given that D71746 had no tests, I'm not too worried about this either.

Reviewed By: NoQ

Differential Revision: https://reviews.llvm.org/D131553
2022-08-11 16:07:52 +02:00
Jun Zhang efc75a2bae
Remove redundant condition check, NFC
Signed-off-by: Jun Zhang <jun@junz.org>
2022-08-11 21:47:19 +08:00
David Truby 13a784f368 [clang][AArch64][SVE] Change SVE_VECTOR_OPERATORS macro for VLA vectors
The __ARM_FEATURE_SVE_VECTOR_OPERATORS macro should be changed to
indicate that this feature is now supported on VLA vectors as well as
VLS vectors. There is a complementary PR to the ACLE spec here
https://github.com/ARM-software/acle/pull/213

Reviewed By: peterwaller-arm

Differential Revision: https://reviews.llvm.org/D131573
2022-08-11 13:23:52 +00:00
David Truby bbb30bd54a [clang][AArch64][SVE] Clarify documentation for sizeof operator on SVE
Previously the table in LanguageExtensions said that sizeof worked on
SVE types but this is only correct for fixed-length vectors so a
clarification has been added.
2022-08-11 13:22:23 +00:00
Sam Estep d09d4bd66c [clang][dataflow] Don't crash when caller args are missing storage locations
This patch modifies `Environment`'s `pushCall` method to pass over arguments that are missing storage locations, instead of crashing.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D131600
2022-08-11 13:00:42 +00:00
Sam Estep eb91fd5cbc [clang][dataflow] Analyze constructor bodies
This patch adds the ability to context-sensitively analyze constructor bodies, by changing `pushCall` to allow both `CallExpr` and `CXXConstructExpr`, and extracting the main context-sensitive logic out of `VisitCallExpr` into a new `transferInlineCall` method which is now also called at the end of `VisitCXXConstructExpr`.

Reviewed By: ymandel, sgatev, xazax.hun

Differential Revision: https://reviews.llvm.org/D131438
2022-08-11 12:46:20 +00:00
Aaron Ballman 7309e8cfbe Do not use the same identifier for a data member as a type; NFC
This should help address a build failure found after
09117b2189

../tools/clang/lib/Sema/SemaDeclCXX.cpp: In member function ‘void clang::Sema::DiagnoseStaticAssertDetails(const clang::Expr*)’:
../tools/clang/lib/Sema/SemaDeclCXX.cpp:16666:19: error: declaration of ‘const clang::Expr* clang::Sema::DiagnoseStaticAssertDetails(const clang::Expr*)::<unnamed struct>::Expr’ changes meaning of ‘Expr’ [-fpermissive]
16666 |       const Expr *Expr;
      |                   ^~~~
In file included from ../tools/clang/include/clang/AST/DeclCXX.h:22,
                 from ../tools/clang/include/clang/AST/ASTLambda.h:18,
                 from ../tools/clang/lib/Sema/SemaDeclCXX.cpp:15:
../tools/clang/include/clang/AST/Expr.h:109:7: note: ‘Expr’ declared here as ‘class clang::Expr’
  109 | class Expr : public ValueStmt {
      |       ^~~~
2022-08-11 07:32:32 -04:00
Florian Hahn ef110a491f
[Builtins] Do not claim most libfuncs are readnone with trapping math.
At the moment, Clang only considers errno when deciding if a builtin
is const. This ignores the fact that some library functions may raise
floating point exceptions, which may modify global state, e.g. when
updating FP status registers.

To model the fact that some library functions/builtins may raise
floating point exceptions, this patch adds a new 'g' modifier for
builtins. If a builtin is marked with 'g', it cannot be considered
const, unless FP exceptions are ignored.

So far I've not added CHECK lines for all calls in math-libcalls.c. I'll
do that once we agree on the overall direction.

A consequence seems to be that we fail to select some of the constrained
math builtins now, but I am not entirely sure what's going on there.

Reviewed By: john.brawn

Differential Revision: https://reviews.llvm.org/D129231
2022-08-11 12:29:01 +01:00
Wei Yi Tee 2cb51449f0 [clang][dataflow] Store DeclContext of block being analysed in Environment if available.
Differential Revision: https://reviews.llvm.org/D131065
2022-08-11 07:36:57 +00:00
Martin Storsjö 5d89f90443 [clang] [HLSL] Fix GCC warnings about virtual methods that are hidden
This fixes the following warnings produced by GCC 9:

In file included from ../tools/clang/include/clang/Sema/ExternalSemaSource.h:15,
                 from ../tools/clang/include/clang/Sema/HLSLExternalSemaSource.h:17,
                 from ../tools/clang/lib/Sema/HLSLExternalSemaSource.cpp:12:
../tools/clang/include/clang/AST/ExternalASTSource.h:211:16: warning: ‘virtual void clang::ExternalASTSource::CompleteType(clang::ObjCInterfaceDecl*)’ was hidden [-Woverloaded-virtual]
  211 |   virtual void CompleteType(ObjCInterfaceDecl *Class);
      |                ^~~~~~~~~~~~
In file included from ../tools/clang/lib/Sema/HLSLExternalSemaSource.cpp:12:
../tools/clang/include/clang/Sema/HLSLExternalSemaSource.h:49:8: warning:   by  virtual void clang::HLSLExternalSemaSource::CompleteType(clang::TagDecl*)’ [-Woverloaded-virtual]
   49 |   void CompleteType(TagDecl *Tag) override;
      |        ^~~~~~~~~~~~

Differential Revision: https://reviews.llvm.org/D130969
2022-08-11 10:15:13 +03:00
Timm Bäder ebe0674acb [clang] Try to fix builders
Try to fix these errors:

SemaDeclCXX.cpp:16666:19: error: declaration of ‘const clang::Expr* clang::Sema::DiagnoseStaticAssertDetails(const clang::Expr*)::<unnamed struct>::Expr’ changes meaning of ‘Expr’ [-fpermissive]
16666 |       const Expr *Expr;
      |                   ^~~~
2022-08-11 09:07:44 +02:00
Timm Bäder 09117b2189 [clang][sema] Print more information about failed static assertions
For failed static assertions, try to take the expression apart and print
useful information about why it failed. In particular, look at binary
operators and print the compile-time evaluated value of the LHS/RHS.

Differential Revision: https://reviews.llvm.org/D130894
2022-08-11 08:44:38 +02:00
Corentin Jabot bcc90f6268 [Clang] Update cxx_dr_status [NFC]
Update the DR status page with the C++ Standard Core
Issues List revision 109.
2022-08-11 08:24:31 +02:00
Clement Courbet 156c0754bc [clang][transformer] Finish plumbing `Note` all the way to the output.
Right now we can only add a single warning, notes are not possible.

Apparently some provisions were made to allow notes, but they were never
propagated all the way to the diagnostics.

Differential Revision: https://reviews.llvm.org/D128807
2022-08-11 07:54:44 +02:00
Gergely Meszaros 3f801e07fa [clang-format] git-clang-format --staged should format the index
When --staged (or --cached) use the index for formatting as well, not just
for the line numbers to format. Without this change git-clang-format gets
the changed line numbers based on the index, but then formats these lines on
the working tree version of the file.

This is a problem when the working tree and index differ. One common case
would be (and is the motivation behind this patch) when applying the
suggested changes git-clang-format --staged, then forgetting to add the
applied changes. When git-clang-format --staged --diff is used in a
pre-commit hook in this scenario, then the hook would allow committing the
improperly formatted changes, as the file is correctly formatted in the work
tree.

Fixes #56797.

Differential Revision: https://reviews.llvm.org/D130108
2022-08-10 19:30:41 -07:00
Jan Svoboda d5fcf8a5e2 [clang][deps] NFC: Move dependency consumer into header file 2022-08-10 15:25:09 -07:00
Evgenii Stepanov 8d3c960295 Revert "[clang][dataflow] Store DeclContext of block being analysed in Environment if available."
Use of uninitialized memory.
https://lab.llvm.org/buildbot/#/builders/74/builds/12713

This reverts commit 8a4c40bfe8.
2022-08-10 14:22:04 -07:00
Evgenii Stepanov 7587065043 Revert "[clang][dataflow] Analyze constructor bodies"
https://lab.llvm.org/buildbot/#/builders/74/builds/12713

This reverts commit 000c8fef86.
2022-08-10 14:21:56 -07:00
Evgenii Stepanov 26089d4da4 Revert "[clang][dataflow] Don't crash when caller args are missing storage locations"
https://lab.llvm.org/buildbot/#/builders/74/builds/12713

This reverts commit 43b298ea12.
2022-08-10 14:21:46 -07:00
Martin Storsjö c843c921a1 [clang] Require strict matches for defines for PCH in GCC style directories
When clang includes a PCH, it tolerates some amount of differences
between the defines used when creating and when including the PCH
- this seems to be intentionally allowed in
c379c07240 (and later extended in
b636875196).

When using a PCH (or when picking a PCH out of a directory containing
multiple candidates) Clang used to accept the header if there were
defines on the command line when creating the PCH that are missing
when using the PCH, or vice versa, defines only set when using the
PCH.

The only cases where Clang explicitly rejected the use of a PCH
is if there was an explicit conflict between the options, e.g.
-DFOO=1 vs -DFOO=2, or -DFOO vs -UFOO.

The latter commit added a FIXME that we really should check whether
mismatched defines actually were used somewhere in the PCH, so that
the define would affect the outcome. This FIXME has stood unaddressed
since 2012.

This differs from GCC, which rejects PCH files if the defines differ
at all.

When explicitly including a single PCH file, the relaxed policy
of allowing minor differences is harmless for correct use cases
(but may fail to diagnose mismtaches), and potentially allow using
PCHs in wider cases (where the user intentionally know that the
differences in defines are harmless for the PCH).

However, for GCC style PCH directories, with a directory containing
multiple PCH variants and the compiler should pick the correct match
out of them, Clang's relaxed logic was problematic. The directory
could contain two otherwise identical PCHs, but one built with -DFOO
and one without. When attempting to include a PCH and iterating over
the candidates in the directory, Clang would essentially pick the
first one out of the two, even if there existed a better, exact
match in the directory.

Keep the relaxed checking when specificlly including one named
PCH file, but require strict matches when trying to pick the right
candidate out of a GCC style directory with alternatives.

This fixes https://github.com/lhmouse/mcfgthread/issues/63.

Differential Revision: https://reviews.llvm.org/D126676
2022-08-10 22:47:27 +03:00
Jan Svoboda 71e32d5cf0 [clang][deps] Always generate module paths
Since D129389 (and downstream PR https://github.com/apple/llvm-project/pull/4965), the dependency scanner is responsible for generating full command-lines, including the modules paths. This patch removes the flag that was making this an opt-in behavior in clang-scan-deps.

Reviewed By: benlangmuir

Differential Revision: https://reviews.llvm.org/D131420
2022-08-10 11:58:28 -07:00
Shafik Yaghmour 4e458765aa [Clang] Restrict non fixed enum to a value outside the range of the enumeration values warning to context requiring a constant expression
In D131307 we allowed the diagnostic to be turned into a warning for a
transition period.

This had the side effect of triggering the warning in contexts not required to
be constant expression. This change will restrict the diagnostic to constant
expression contexts. This should reduce the fallout of this diagnostic.

Differential Revision: https://reviews.llvm.org/D131528
2022-08-10 11:12:01 -07:00
Aaron Ballman af01f717c4 Default implicit function pointer conversions diagnostic to be an error
Implicitly converting between incompatible function pointers in C is
currently a default-on warning (it is an error in C++). However, this
is very poor security posture. A mismatch in parameters or return
types, or a mismatch in calling conventions, etc can lead to
exploitable security vulnerabilities. Rather than allow this unsafe
practice with a warning, this patch strengthens the warning to be an
error (while still allowing users the ability to disable the error or
the warning entirely to ease migration). Users should either ensure the
signatures are correctly compatible or they should use an explicit cast
if they believe that's more reasonable.

Differential Revision: https://reviews.llvm.org/D131351
2022-08-10 13:54:17 -04:00
Yuanfang Chen ec08114133 [NFC][Clang] make AtomicConstraint::ParameterMapping const
It was not const due to the way it is initialized. This is needed for
a following patch.
2022-08-10 10:51:39 -07:00
Sam Estep 43b298ea12 [clang][dataflow] Don't crash when caller args are missing storage locations
This patch modifies `Environment`'s `pushCall` method to pass over arguments that are missing storage locations, instead of crashing.

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D131600
2022-08-10 17:50:34 +00:00
Ofek Shilon 73a1b162a4 Add docs for function attributes hot/cold
Following https://reviews.llvm.org/D92493, this add docs for the hot
and cold function attributes.

Differential Revision: https://reviews.llvm.org/D130933
2022-08-10 13:48:43 -04:00
Denys Petrov 7e2b995e0c [analyzer] [NFC] Add more test cases for equality tracking
Summary: Cover `ConstraintAssignor::assign(EquivalenceClass, RangeSet)` function with more regression tests.

Differential Revision: https://reviews.llvm.org/D131514
2022-08-10 19:52:55 +03:00
Manoj Gupta 06fc5a7714 Driver: Refactor and support per target dirs in baremetal
Refactor baremetal driver code to reduce the bespoke
additions and base class overrides.
This lets us use the per target runtimes like other clang
targets. E.g. clang -target armv7m-cros-none-eabi will now
be able to use the runtimes installed at
<resource_dir>/lib/armv7m-cros-none-eabi instead of the hardcoded
path <resource_dir>/lib/baremetal.
The older code paths should still continue to work as before if
<resource_dir>/lib/<tuple> does not exist.

Reviewed By: MaskRay, barannikov88

Differential Revision: https://reviews.llvm.org/D131225
2022-08-10 09:13:30 -07:00
Ivan Murashko e78c80e3d6 [clang] SourceManager: fix at SourceManager::getFileIDLoaded for the case of invalid SLockEntry
There is a fix for the search procedure at `SourceManager::getFileIDLoaded`. It might return an invalid (not loaded) entry. That might cause clang/clangd crashes. At my case the scenario was the following:
- `SourceManager::getFileIDLoaded` returned an invalid file id for a non loaded entry and incorrectly set `SourceManager::LastFileIDLookup` to the value
- `getSLocEntry` returned `SourceManager::FakeSLocEntryForRecovery` introduced at [D89748](https://reviews.llvm.org/D89748).
- The result entry is not tested at `SourceManager::isOffsetInFileID`and as result the call `return SLocOffset < getSLocEntryByID(FID.ID+1).getOffset();` returned `true` value because `FID.ID+1` pointed to a non-fake entry
- The tested offset was marked as one that belonged to the fake `SLockEntry`

Such behaviour might cause a weird clangd crash when preamble contains some header files that were removed just after the preamble created. Unfortunately it's not so easy to reproduce the crash in the form of a LIT test thus I provided the fix only.

Test Plan:
```
ninja check-clang
```

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D130847
2022-08-10 16:37:42 +01:00
David Truby e4642d78a8 [clang] Correct documentation for NEON and SVE operator support
Previously the language extension documentation didn't mention SVE and
was incomplete in listing the C/C++ operators supported on NEON. This
corrects the documentation to be in line with the implementation.
2022-08-10 15:16:38 +01:00
Sam Estep 000c8fef86 [clang][dataflow] Analyze constructor bodies
This patch adds the ability to context-sensitively analyze constructor bodies, by changing `pushCall` to allow both `CallExpr` and `CXXConstructExpr`, and extracting the main context-sensitive logic out of `VisitCallExpr` into a new `transferInlineCall` method which is now also called at the end of `VisitCXXConstructExpr`.

Reviewed By: ymandel, sgatev, xazax.hun

Differential Revision: https://reviews.llvm.org/D131438
2022-08-10 14:01:45 +00:00
Wei Yi Tee 8a4c40bfe8 [clang][dataflow] Store DeclContext of block being analysed in Environment if available.
Differential Revision: https://reviews.llvm.org/D131065
2022-08-10 11:27:03 +00:00
David Truby 286d59ef6f [clang][AArch64][SVE] Add unary +/- operators for SVE types
This patch enables the unary promotion and negation operators on
SVE types.

Differential Revision: https://reviews.llvm.org/D130984
2022-08-10 10:32:43 +00:00
Clement Courbet 5331e1229a [clang][transformer] Fix crash on replacement-less ASTEdit.
Given that we provide an EditGenerator edit(ASTEdit), we can't ever be
sure that the user won't give us an empty replacement.

Differential Revision: https://reviews.llvm.org/D128887
2022-08-10 09:08:05 +02:00
Freddy Ye e4888a37d3 [X86][BF16] Enable __bf16 for x86 targets.
X86 psABI has updated to support __bf16 type, the ABI of which is the
same as FP16. See https://discourse.llvm.org/t/patch-add-optional-bfloat16-support/63149

Reviewed By: pengfei

Differential Revision: https://reviews.llvm.org/D130964
2022-08-10 09:00:47 +08:00
YingChi Long 55d3b79d15
[clang] add APValue type check in `TryPrintAsStringLiteral`
Fixes https://github.com/llvm/llvm-project/issues/57013

https://reviews.llvm.org/D115031 improved printing of non-type template
parameter args. But checking if the end of Inits is 0 without checking
if APValue is an integer, causes clang to segfault. This patch adds
the code to check the type. (May not be a proper bugfix.)

Reviewed By: aaron.ballman, lichray

Differential Revision: https://reviews.llvm.org/D131466
2022-08-10 08:42:59 +08:00
malavikasamak c74a204826 [analyzer] Fix false positive in use-after-move checker
Differential Revision: https://reviews.llvm.org/D131525
2022-08-09 17:26:30 -07:00
Shawn Zhong 82afc9b169 Fix -Wbitfield-constant-conversion on 1-bit signed bitfield
A one-bit signed bit-field can only hold the values 0 and -1; this
corrects the diagnostic behavior accordingly.

Fixes #53253
Differential Revision: https://reviews.llvm.org/D131255
2022-08-09 11:43:50 -04:00
Thorsten Schütt e486e48c3d [clang] fix deprecation 2022-08-09 17:42:55 +02:00
Aaron Ballman 4c02ab8c97 Change prototype merging error into a warning for builtins
As was observed in https://reviews.llvm.org/D123627#3707635, it's
confusing that a user can write:
```
float rintf(void) {}
```
and get a warning, but writing:
```
float rintf() {}
```
gives an error. This patch changes the behavior so that both are
warnings, so that users who have functions which conflict with a
builtin identifier can still use that identifier as they wish.

Differential Revision: https://reviews.llvm.org/D131499
2022-08-09 11:36:48 -04:00
Ariel Burton f53f2f232f Extend ptr32 support to be applied on typedef
Earlier, if the QualType was sugared, then we would error out
as it was not a pointer type, for example,

typedef int *int_star;

int_star __ptr32 p;

Now, if ptr32 is given we apply it if the raw Canonical Type
(i.e., the desugared type) is a PointerType, instead of only
checking whether the sugared type is a pointer type.

As before, we still disallow ptr32 usage if the pointer is used
as a pointer to a member.

Differential Revision: https://reviews.llvm.org/D130123
2022-08-09 11:08:52 -04:00
Matheus Izvekov 1d1a56929b
Clang: fix AST representation of expanded template arguments.
Extend clang's SubstTemplateTypeParm to represent the pack substitution index.

Fixes PR56099.

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Differential Revision: https://reviews.llvm.org/D128113
2022-08-09 14:26:16 +02:00
Ilya Biryukov 07529996d9 [Sema] Merge variable template specializations
Clang used to produce redefinition errors, see tests for examples.

Reviewed By: ChuanqiXu

Differential Revision: https://reviews.llvm.org/D131258
2022-08-09 12:17:41 +02:00
Simon Pilgrim af0052ef74 Fix MSVC "not all control paths return a value" warning. NFC. 2022-08-09 09:55:57 +01:00
Balázs Kéri d4ff9eff76 [clang][ASTImporter] Improve import of functions with auto return type.
ASTImporter used to crash in some cases when a function is imported with
`auto` return type and the return type has references into the function.
The handling of such cases is improved and crash should not occur any more
but it is not fully verified, there are very many different types of
cases to care for.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D130705
2022-08-09 09:20:06 +02:00
Fangrui Song 32197830ef [clang][clang-tools-extra] LLVM_NODISCARD => [[nodiscard]]. NFC 2022-08-09 07:11:18 +00:00
Kazu Hirata 8e207e4c09 [Basic] Deprecate MapEntryOptionalStorage::{hasValue,getValue}
MapEntryOptionalStorage is an underlying storage class for
OptionalStorage<clang::DirectoryEntryRef>.

This patch deprecates:

  OptionalStorage<clang::DirectoryEntryRef>::hasValue
  OptionalStorage<clang::DirectoryEntryRef>::getValue

as there is no known users of these two methods.

Differential Revision: https://reviews.llvm.org/D131368
2022-08-08 21:33:09 -07:00
Fangrui Song 8d9d27db47 [Driver] Add -Xclang= as an alias for -Xclang
Driver options taking a value typically use `=` as the separator, instead of a
space. Unfortunately many older driver options do not stick with the rule, but I
find -Xclang used a lot and will be convenient if -Xclang= exists.

For build systems using a string array instead of a string to indicate compiler options,
`["-Xclang=-foo"]` is more convenient than `["-Xclang", "-foo"]`.
If a tool wants to filter out -Xclang=-foo, it is trivial for the `=` form, but
complex for the space separated form.

Reviewed By: jhuber6

Differential Revision: https://reviews.llvm.org/D131455
2022-08-08 19:05:24 -07:00
Shafik Yaghmour cc104113dd [Clang] Allow downgrading to a warning the diagnostic for setting a non fixed enum to a value outside the range of the enumeration values
In D130058 we diagnose the undefined behavior of setting the value outside the
range of the enumerations values for an enum without a fixed underlying type.

Based on feedback we will provide users to the ability to downgrade this
diagnostic to a waring to allow for a transition period. We expect to turn this
diagnostic to an error in the next release.

Differential Revision: https://reviews.llvm.org/D131307
2022-08-08 16:23:07 -07:00
Ben Langmuir 33af4b22f8 [clang][deps] Stop sharing FileManager across module builds in scanner
Sharing the FileManager across implicit module builds currently leaks
paths looked up in an importer into the built module itself. This can
cause non-deterministic results across scans. It is especially bad for
modules since the path can be saved into the pcm file itself, leading to
stateful behaviour if the cache is shared.

This should not impact the number of real filesystem accesses in the
scanner, since it is already caching in the
DependencyScanningWorkerFilesystem.

Note: this change does not affect whether or not the FileManager is
shared across TUs in the scanner, which is a separate issue.

Differential Revision: https://reviews.llvm.org/D131412
2022-08-08 12:13:54 -07:00
Joseph Huber b71b22e48d [LinkerWrapper] Use C++17 structured bindings
Summary:
This patch updates the linker wrapper to use C++17 structured bindings
now that they are availible.
2022-08-08 15:07:03 -04:00
Fangrui Song cdeb50c321 [lldb] Remove include/lldb/lldb-private.h
The header from 62e0681afb does something with
LLVM_FALLTHROUGH. Now that llvm-project has switched to C++17 and
LLVM_FALLTHROUGH uses have been migrated to [[fallthrough]], the header is
unneeded.

Reviewed By: JDevlieghere

Differential Revision: https://reviews.llvm.org/D131422
2022-08-08 12:03:53 -07:00
Fangrui Song 3f18f7c007 [clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFC
With C++17 there is no Clang pedantic warning or MSVC C5051.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D131346
2022-08-08 09:12:46 -07:00
Aaron Ballman e640250454 Update the C status page from the latest working draft
WG14 N3047 is the last C working draft before the document goes out
for committee ballot, so this should be the last of the C2x compiler
features to be added.
2022-08-08 11:30:49 -04:00
Chris Bieneman fc470013d1 [Docs] Add HLSL ResourceType documentation
Along with the new documentation this also re-organizes the HLSL docs
to a subdirectory. The hope is to continue to expand this documentation
as the HLSL implementation advances.

Differential Revision: https://reviews.llvm.org/D130794
2022-08-08 09:06:38 -05:00
Benjamin Kramer 99a5a029e6 [ASTMatchers] Replace hand-coded copy of std::apply with the real C++17 function. NFCI 2022-08-08 14:08:04 +02:00
Nathan James 7042417ef1
[NFC][clang] Bring `and_present` and `if_present` casting functions to clang namespace
This should enable simpler migration when the `and_nonnull` and `or_null` functions are deprecated.
2022-08-08 08:38:50 +01:00
Ashay Rane d1bb3016dd
[mlir] fix `add_tablegen()` macro to allow installing mlir-pdll
Prior to this patch, the `add_tablegen()` macro in
llvm/cmake/modules/TableGen.cmake added the install rule only if
`project` matched `LLVM` or `MLIR`.  This patch adds an optional
`DESTINATION` argument, which, if non-empty, decides whether (and where)
to install the tablegen tool, thus eliminating the need for
project-specific overrides.  This patch also updates all other
invocations of the `add_tablegen()` macro.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D131282
2022-08-07 15:48:38 -07:00
Sergei Barannikov 87dc7d4b61
[clang][CodeGen] Factor out Swift ABI hooks (NFCI)
Swift calling conventions stands out in the way that they are lowered in
mostly target-independent manner, with very few customization points.
As such, swift-related methods of ABIInfo do not reference the rest of
ABIInfo and vice versa.
This change follows interface segregation principle; it removes
dependency of SwiftABIInfo on ABIInfo. Targets must now implement
SwiftABIInfo separately if they support Swift calling conventions.

Almost all targets implemented `shouldPassIndirectly` the same way. This
de-facto default implementation has been moved into the base class.

`isSwiftErrorInRegister` used to be virtual, now it is not. It didn't
accept any arguments which could have an effect on the returned value.
This is now a static property of the target ABI.

Reviewed By: rusyaev-roman, inclyc

Differential Revision: https://reviews.llvm.org/D130394
2022-08-08 00:23:23 +08:00
Kazu Hirata 7542e72188 Use llvm::is_contained (NFC) 2022-08-07 00:16:17 -07:00
YingChi Long 1f54006bca
[clang][docs] use `Fixes` instead of `This fixes` in ReleaseNotes [NFC] 2022-08-07 12:42:15 +08:00
Shilei Tian e21202dac1 [Clang][OpenMP] Fix the issue that `llvm.lifetime.end` is emitted too early for variables captured in linear clause
Currently if an OpenMP program uses `linear` clause, and is compiled with
optimization, `llvm.lifetime.end` for variables listed in `linear` clause are
emitted too early such that there could still be uses after that. Let's take the
following code as example:
```
// loop.c
int j;
int *u;

void loop(int n) {
  int i;
  for (i = 0; i < n; ++i) {
    ++j;
    u = &j;
  }
}
```
We compile using the command:
```
clang -cc1 -fopenmp-simd -O3 -x c -triple x86_64-apple-darwin10 -emit-llvm loop.c -o loop.ll
```
The following IR (simplified) will be generated:
```
@j = local_unnamed_addr global i32 0, align 4
@u = local_unnamed_addr global ptr null, align 8

define void @loop(i32 noundef %n) local_unnamed_addr {
entry:
  %j = alloca i32, align 4
  %cmp = icmp sgt i32 %n, 0
  br i1 %cmp, label %simd.if.then, label %simd.if.end

simd.if.then:                                     ; preds = %entry
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %j)
  store ptr %j, ptr @u, align 8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %j)
  %0 = load i32, ptr %j, align 4
  store i32 %0, ptr @j, align 4
  br label %simd.if.end

simd.if.end:                                      ; preds = %simd.if.then, %entry
  ret void
}
```
The most important part is:
```
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %j)
  %0 = load i32, ptr %j, align 4
  store i32 %0, ptr @j, align 4
```
`%j` is still loaded after `@llvm.lifetime.end.p0(i64 4, ptr nonnull %j)`. This
could cause the backend incorrectly optimizes the code and further generates
incorrect code. The root cause is, when we emit a construct that could have
`linear` clause, it usually has the following pattern:
```
EmitOMPLinearClauseInit(S)
{
  OMPPrivateScope LoopScope(*this);
  ...
  EmitOMPLinearClause(S, LoopScope);
  ...
  (void)LoopScope.Privatize();
  ...
}
EmitOMPLinearClauseFinal(S, [](CodeGenFunction &) { return nullptr; });
```
Variables that need to be privatized are added into `LoopScope`, which also
serves as a RAII object. When `LoopScope` is destructed and if optimization is
enabled, a `@llvm.lifetime.end` is also emitted for each privatized variable.
However, the writing back to original variables in `linear` clause happens after
the scope in `EmitOMPLinearClauseFinal`, causing the issue we see above.

A quick "fix" seems to be, moving `EmitOMPLinearClauseFinal` inside the scope.
However, it doesn't work. That's because the local variable map has been updated
by `LoopScope` such that a variable declaration is mapped to the privatized
variable, instead of the actual one. In that way, the following code will be
generated:
```
  %0 = load i32, ptr %j, align 4
  store i32 %0, ptr %j, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %j)
```
Well, now the life time is correct, but apparently the writing back is broken.

In this patch, a new function `OMPPrivateScope::restoreMap` is added and called
before calling `EmitOMPLinearClauseFinal`. This can make sure that
`EmitOMPLinearClauseFinal` can find the orignal varaibls to write back.

Fixes #56913.

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D131272
2022-08-06 16:50:37 -04:00
Tom Stellard d2b158e29e clang/cmake: Drop use of llvm-config for LLVM install discovery
This has been deprecated for a while, since D51714 in 2018.

Remove it in favor of using CMake's find_package() function.

Reviewed By: phosek, mgorny

Differential Revision: https://reviews.llvm.org/D128777
2022-08-06 16:22:59 -04:00
Aarush Bhat a6cb8419b1
clang: fix typo availbility
- Fixes [[ https://github.com/llvm/llvm-project/issues/56787 | #56787 ]].

I am fixing the spelling of availability.

I am unsure if this change will have any side effects. If someone can
help on how to check if it has any side effects, I can test those out as
well.

Reviewed By: inclyc

Differential Revision: https://reviews.llvm.org/D131277
2022-08-07 03:44:55 +08:00
Kazu Hirata c8e6ebd74e Use value instead of getValue (NFC) 2022-08-06 11:21:39 -07:00
Aaron Ballman 486a3c4662 Update the status of some more C DRs
Update some of the C99-era DRs starting in the 300s.
2022-08-06 11:53:40 -04:00
Tobias Hieta b1356504e6
[LLVM] Update C++ standard to 17
Also make the soft toolchain requirements hard. This allows
us to use C++17 features in LLVM now.

If we find patterns with C++17 that improve readability
it should be recommended in the coding standards.

Reviewed By: jhenderson, cor3ntin, MaskRay

Differential Revision: https://reviews.llvm.org/D130689
2022-08-06 09:42:10 +02:00
Jun Zhang 786b503f66
[Clang][Lex] Extend HeaderSearch::LookupFile to control OpenFile behavior.
In the case of static compilation the file system is pretty much read-only
and taking a snapshot of it usually is sufficient. In the interactive C++
case the compilation is longer and people can create and include files, etc.
In that case we often do not want to open files or cache failures unless is
absolutely necessary.

This patch extends the original API call by forwarding some optional flags,
so we can continue use it in the previous way with no breakage.
Signed-off-by: Jun Zhang <jun@junz.org>

Differential Revision: https://reviews.llvm.org/D131241
2022-08-06 11:36:02 +08:00
Argyrios Kyrtzidis 7b12e561ac [test/Modules/cxx20-export-import.cpp] Pre-clean the modules cache directory of the test, NFC 2022-08-05 17:27:43 -07:00
Nico Weber 3fbbf28173 unbreak Modules/cxx20-export-import.cpp with LLVM_APPEND_VC_REV=OFF after 6635f48e4a
See revision b8b7a9dcdc for prior art.
2022-08-05 19:50:23 -04:00
Xiang Li 549542b494 [HLSL] emit-obj when set output.
When not set output, set default output to stdout.
When set output with -Fo and no -fcgl, set -emit-obj to generate dx container.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D130858
2022-08-05 16:27:17 -07:00
Joseph Huber 3b52341116 [CUDA] Fix output name being replaced in device-only mode
When performing device only compilation, there was an issue where
`cubin` outputs were being renamed to `cubin` despite the user's name.
This is required in a normal compilation flow as the Nvidia tools only
understand specific filenames instead of checking magic bytes for some
unknown reason. We do not want to perform this transformation when the
user is performing device only compilation.

Reviewed By: tra

Differential Revision: https://reviews.llvm.org/D131278
2022-08-05 19:08:41 -04:00
Argyrios Kyrtzidis 6635f48e4a [Serialization] Remove `ORIGINAL_PCH_DIR` record
Use of `ORIGINAL_PCH_DIR` record has been superseeded by making PCH/PCM files with relocatable paths at write time.
Removing this record is useful for producing an output-path-independent PCH file and enable sharing of the same PCH file even
when it was intended for a different output path.

Differential Revision: https://reviews.llvm.org/D131124
2022-08-05 15:40:33 -07:00
Ben Langmuir fb89cc0ddb [clang][modules] Don't depend on sharing FileManager during module build
Sharing the FileManager between the importer and the module build should
only be an optimization. Add a cc1 option -fno-modules-share-filemanager
to allow us to test this. Fix the path to modulemap files, which
previously depended on the shared FileManager when using path mapped to
an external file in a VFS.

Differential Revision: https://reviews.llvm.org/D131076
2022-08-05 12:24:40 -07:00
Ben Langmuir d038bb196c [clang] Fix redirection behaviour for cached FileEntryRef
In 6a79e2ff19 we changed Filemanager::getEntryRef() to return the
redirecting FileEntryRef instead of looking through the redirection.
This commit fixes the case when looking up a cached file path to also
return the redirecting FileEntryRef. This mainly affects the behaviour
of calling getNameAsRequested() on the resulting entry ref.

Differential Revision: https://reviews.llvm.org/D131273
2022-08-05 12:23:38 -07:00
Jack Kirk 3e0e5568a6 [CUDA] Fixed sm version constrain for __bmma_m8n8k128_mma_and_popc_b1.
As stated in
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#warp-level-matrix-instructions-wmma-mma:
".and operation in single-bit wmma requires sm_80 or higher."

tra@: Fixed a bug in builtins-nvptx-mma.py test generator and regenerated the tests.

Differential Revision: https://reviews.llvm.org/D131265
2022-08-05 12:14:06 -07:00
Aaron Ballman 4bc9e60306 Removing redundant code; NFC
The same predicate is checked on line 12962 just above the removed code.
2022-08-05 09:17:20 -04:00
Chuanqi Xu 809b416641 [NFC] Requires x86-registered-target for test/pr56919.cpp 2022-08-05 16:46:38 +08:00
Balázs Kéri 501faaa0d6 [clang][analyzer] Add more wide-character functions to CStringChecker
Support for functions wmempcpy, wmemmove, wmemcmp is added to the checker.
The same tests are copied that exist for the non-wide versions, with
non-wide functions and character types changed to the wide version.

Reviewed By: martong

Differential Revision: https://reviews.llvm.org/D130470
2022-08-05 10:32:53 +02:00
Chuanqi Xu 230d6f93aa [Coroutines] Remove lifetime intrinsics for spliied allocas in coroutine frames
Closing https://github.com/llvm/llvm-project/issues/56919

It is meaningless to preserve the lifetime markers for the spilled
allocas in the coroutine frames and it would block some optimizations
too.
2022-08-05 14:50:43 +08:00
Xiang Li b2c9ff7273 [NFC][HLSL] Fix build error caused missing typo update.
setHLSLFnuctionAttributes to setHLSLFunctionAttributes.

Differential Revision: https://reviews.llvm.org/D131240
2022-08-04 23:20:25 -07:00
Xiang Li 6134629af0 [NFC][HLSL] Fix typo in CGHLSLRuntime.
Change setHLSLFnuctionAttributes to setHLSLFunctionAttributes.

Differential Revision: https://reviews.llvm.org/D131238
2022-08-04 23:08:40 -07:00
Timm Bäder d1942855c4 [clang] Consider array filler in MaybeElementDependentArrayfiller()
Any InitListExpr may have an array filler and since we may be evaluating
the array filler as well, we need to take into account that the array
filler expression might make the InitListExpr element dependent.

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

Differential Revision: https://reviews.llvm.org/D131155
2022-08-05 06:47:49 +02:00
Timm Bäder 8b74074731 [clang][sema] Fix collectConjunctionTerms()
Consider:

A == 5 && A != 5

IfA is 5, the old collectConjunctionTerms() would call itself again for
the LHS (which it ignores), then the RHS (which it also ignores) and
then just return without ever adding anything to the Terms array.

Differential Revision: https://reviews.llvm.org/D131070
2022-08-05 06:45:32 +02:00
Xiang Li 906e41f4e3 [HLSL] clang codeGen for HLSLShaderAttr.
Translate HLSLShaderAttr to IR level.
 1. Skip mangle for hlsl entry functions.
 2. Add function attribute for hlsl entry functions.

Reviewed By: Anastasia

Differential Revision: https://reviews.llvm.org/D124752
2022-08-04 21:23:57 -07:00
Ellis Hoag 6f4c3c0f64 [InstrProf][attempt 2] Add new format for -fprofile-list=
In D130807 we added the `skipprofile` attribute. This commit
changes the format so we can either `forbid` or `skip` profiling
functions by adding the `noprofile` or `skipprofile` attributes,
respectively. The behavior of the original format remains
unchanged.

Also, add the `skipprofile` attribute when using
`-fprofile-function-groups`.

This was originally landed as https://reviews.llvm.org/D130808 but was
reverted due to a Windows test failure.

Differential Revision: https://reviews.llvm.org/D131195
2022-08-04 17:12:56 -07:00
Richard Smith 73b62f8135 Fix parsing of comma fold-expressions as the operand of a C-style cast. 2022-08-04 17:08:08 -07:00
Xiang Li 8a27a2f89f [HLSL] Support -E option for HLSL.
-E option will set entry function for hlsl.
The format is -E entry_name.

To avoid conflict with existing option with name 'E', add an extra prefix '--'.

A new field HLSLEntry is added to TargetOption.
To share code with HLSLShaderAttr, entry function will be add HLSLShaderAttr attribute too.

Reviewed By: beanz

Differential Revision: https://reviews.llvm.org/D124751
2022-08-04 16:54:19 -07:00
Matt Arsenault c5b36ab1d6 AMDGPU/clang: Remove dead code
The order has to be a constant and should be enforced by the builtin
definition. The fallthrough behavior would have been broken anyway.

There's still an existing issue/assert if you try to use garbage for the
ordering. The IRGen should be broken, but we also hit another assert
before that.

Fixes issue 56832
2022-08-04 19:02:56 -04:00
Leonard Chan 33171df9cc Revert "[clang][Darwin] Always set the default C++ Standard Library to libc++"
This reverts commit c5ccb78ade.

We're seeing darwin-stdlib.cpp fail on our linux, mac, and windows
builders:
https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8806821020552676065/overview
2022-08-04 22:56:32 +00:00
Corentin Jabot a1a71b7dc9 [Clang] Fix capture of values initialized by bitfields
This fixes a regression introduced in 127bf44

Differential Revision: https://reviews.llvm.org/D131202
2022-08-04 23:58:47 +02:00
Zakk Chen 010f329803 [RISCV][Clang] Support policy function for all vector segment load.
We will switch all UndefValue to PoisonValue in follow up patches.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D126750
2022-08-04 17:47:24 +00:00
Sam Estep 8611a77ee7 [clang][dataflow] Analyze method bodies
This patch adds the ability to context-sensitively analyze method bodies, by moving `ThisPointeeLoc` from `DataflowAnalysisContext` to `Environment`, and adding code in `pushCall` to set it.

Reviewed By: ymandel, sgatev, xazax.hun

Differential Revision: https://reviews.llvm.org/D131170
2022-08-04 17:45:47 +00:00
Sam Estep 0eaecbbc23 [clang][dataflow] Handle return statements
This patch adds a `ReturnLoc` field to the `Environment`, serving a similar to the `ThisPointeeLoc` field in the `DataflowAnalysisContext`. It then uses that (along with a new `VisitReturnStmt` method in `TransferVisitor`) to handle non-`void`-returning functions in context-sensitive analysis.

Reviewed By: ymandel, sgatev

Differential Revision: https://reviews.llvm.org/D130600
2022-08-04 17:42:19 +00:00
David Green 8c30f4a5ab [AArch64] Always allow the __bf16 type
We would like to make the ACLE NEON and SVE intrinsics more useable by
gating them on the target, not by ifdef preprocessor macros. In order to
do this the types they use need to be available. This patches makes
__bf16 always available under AArch64 not just when the bf16
architecture feature is present. This bringing it in-line with GCC. In
subsequent patches the NEON bfloat16x8_t and SVE svbfloat16_t types
(along with bfloat16_t used in arm_sve.h) will be made unconditional
too.

The operations valid on the types are still very limited. They can be
used as a storage type, but the intrinsics used for convertions are
still behind an ifdef guard in arm_neon.h/arm_bf16.h.

Differential Revision: https://reviews.llvm.org/D130973
2022-08-04 18:35:27 +01:00
Fangrui Song 88501dc749 [Sema] -Wformat: support C23 format specifier %b %B
Close #56885: WG14 N2630 added %b to fprintf/fscanf and recommended %B for
fprintf. This patch teaches -Wformat %b for the printf/scanf family of functions
and %B for the printf family of functions.

glibc 2.35 and latest Android bionic added %b/%B printf support. From
https://www.openwall.com/lists/libc-coord/2022/07/ no scanf support is available
yet.

Like GCC, we don't test library support.

GCC 12 -Wformat -pedantic emits a warning:

> warning: ISO C17 does not support the ‘%b’ gnu_printf format [-Wformat=]

The behavior is not ported.

Note: `freebsd_kernel_printf` uses %b differently.

Reviewed By: aaron.ballman, dim, enh

Differential Revision: https://reviews.llvm.org/D131057
2022-08-04 10:26:31 -07:00
Eric Li 5659908f4c [clang][dataflow][NFC] Resize vector directly with ctor
Differential Revision: https://reviews.llvm.org/D131177
2022-08-04 13:12:37 -04:00
Eric Li 18034aee63 [clang][dataflow][NFC] Convert mutable vector references to ArrayRef
`transferBlock` and `computeBlockInputState` only read the
`BlockStates` vector for the predecessor block(s), and do not need to
mutate any of the contents. Only `runTypeErasedDataflowAnalysis`
writes into the `vector`, so simply down to an `ArrayRef`.
2022-08-04 13:12:37 -04:00
Nico Weber 0eb7d86f58 Revert "[InstrProf] Add new format for -fprofile-list="
This reverts commit b692312ca4.
Breaks tests on Windows, see https://reviews.llvm.org/D130808#3699952
2022-08-04 13:04:59 -04:00
Ellis Hoag b692312ca4 [InstrProf] Add new format for -fprofile-list=
In D130807 we added the `skipprofile` attribute. This commit
changes the format so we can either `forbid` or `skip` profiling
functions by adding the `noprofile` or `skipprofile` attributes,
respectively. The behavior of the original format remains
unchanged.

Also, add the `skipprofile` attribute when using
`-fprofile-function-groups`.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D130808
2022-08-04 08:49:43 -07:00
Chelsea Cassanova bcf6ffb87e Reland "[lldb/Fuzzer] Add fuzzer for expression evaluator"
This reverts commit d959324e1e.

The target_include_directories in the clang-fuzzer CMake files
are set to PRIVATE instead of PUBLIC to prevent the clang buildbots
from breaking when symlinking clang into llvm.

The expression evaluator fuzzer itself has been modified to prevent a
bug that occurs when running it without a target.
2022-08-04 11:47:06 -04:00
Ellis Hoag 12e78ff881 [InstrProf] Add the skipprofile attribute
As discussed in [0], this diff adds the `skipprofile` attribute to
prevent the function from being profiled while allowing profiled
functions to be inlined into it. The `noprofile` attribute remains
unchanged.

The `noprofile` attribute is used for functions where it is
dangerous to add instrumentation to while the `skipprofile` attribute is
used to reduce code size or performance overhead.

[0] https://discourse.llvm.org/t/why-does-the-noprofile-attribute-restrict-inlining/64108

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D130807
2022-08-04 08:45:27 -07:00
Eric Li 54d24eae98 [clang][dataflow][NFC] Fix outdated comment on getStableStorageLocation
Follow-up to D129097.

It is no longer a requirement that the `QualType` passed to to
`DataflowAnalysisContext::getStableStorageLocation()` is not null. A
null type pass as an argument is only applicable as the pointee type
of a `std::nullptr_t` pointer.

Differential Revision: https://reviews.llvm.org/D131109
2022-08-04 11:15:14 -04:00
YingChi Long 282d4755c3
[clang] change `auto` to `Expr` in last commit [NFC] 2022-08-04 21:15:45 +08:00
YingChi Long f417583f31
[clang] format string checking for conpile-time evaluated str literal
This patch enhances clang's ability to check compile-time determinable
string literals as format strings, and can give FixIt hints at literals
(unlike gcc). Issue https://github.com/llvm/llvm-project/issues/55805
mentiond two compile-time string cases. And this patch partially fixes
one.

```
constexpr const char* foo() {
  return "%s %d";
}
int main() {
   printf(foo(), "abc", "def");
   return 0;
}
```

This patch enables clang check format string for this:

```
<source>:4:24: warning: format specifies type 'int' but the argument has type 'const char *' [-Wformat]
  printf(foo(), "abc", "def");
         ~~~~~         ^~~~~
<source>:2:42: note: format string is defined here
constexpr const char *foo() { return "%s %d"; }
                                         ^~
                                         %s
1 warning generated.
```

Reviewed By: aaron.ballman

Signed-off-by: YingChi Long <me@inclyc.cn>

Differential Revision: https://reviews.llvm.org/D130906
2022-08-04 21:07:30 +08:00
Kadir Cetinkaya df48e3fbcc
Revert "[clang] Pass FoundDecl to DeclRefExpr creator for operator overloads"
This reverts commit 4e94f66531.
See https://reviews.llvm.org/D129973#3698969 for reasoning.
2022-08-04 12:14:43 +02:00
Matt Jacobson c8b2f3f51b [ObjC] type method metadata `_imp`, messenger routine at callsite with program address space
On targets with non-default program address space (e.g., Harvard
architectures), clang crashes when emitting Objective-C method metadata,
because the address of the method IMP cannot be bitcast to i8*. It similarly
crashes at messenger callsite with a failed bitcast.

Define the _imp field instead as i8 addrspace(1)* (or whatever the target's
program address space is). And in getMessageSendInfo(), create signatureType by
specifying the program address space.

Add a regression test using the AVR target. Test failed previously and passes
now. Checked codegen of the test for x86_64-apple-darwin19.6.0 and saw no
difference, as expected.

Reviewed By: rjmccall, dylanmckay

Differential Revision: https://reviews.llvm.org/D112113
2022-08-04 05:40:32 -04:00
Corentin Jabot 127bf44385 [Clang][C++20] Support capturing structured bindings in lambdas
This completes the implementation of P1091R3 and P1381R1.

This patch allow the capture of structured bindings
both for C++20+ and C++17, with extension/compat warning.

In addition, capturing an anonymous union member,
a bitfield, or a structured binding thereof now has a
better diagnostic.

We only support structured bindings - as opposed to other kinds
of structured statements/blocks. We still emit an error for those.

In addition, support for structured bindings capture is entirely disabled in
OpenMP mode as this needs more investigation - a specific diagnostic indicate the feature is not yet supported there.

Note that the rest of P1091R3 (static/thread_local structured bindings) was already implemented.

at the request of @shafik, i can confirm the correct behavior of lldb wit this change.

Fixes https://github.com/llvm/llvm-project/issues/54300
Fixes https://github.com/llvm/llvm-project/issues/54300
Fixes https://github.com/llvm/llvm-project/issues/52720

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D122768
2022-08-04 10:12:53 +02:00