Commit Graph

64915 Commits

Author SHA1 Message Date
Jameson Nash 9d59cfc67e clang-analyzer plugins require LLVM_ENABLE_PLUGINS also
The clang-analyzer plugins are not linked to a particular tool, so they
can only be compiled if plugins are broadly supported. We could opt
instead to decide whether to link them to specifically against clang or
with undefined symbols, depending on the value of LLVM_ENABLE_PLUGINS,
but we do not currently expect there to be a use case for that rather
niche configuration.

Differential Revision: https://reviews.llvm.org/D119591
2022-02-16 11:59:09 -05:00
Joseph Huber 5781839f7a Revert "[OpenMP] Pass AMDGPU math libraries into the linker wrapper"
This hits an assertion in the linker wrapper. Revert for now, will fix
later.

This reverts commit 61fb260d9d.
2022-02-16 11:54:44 -05:00
Joseph Huber 61fb260d9d [OpenMP] Pass AMDGPU math libraries into the linker wrapper
This patch passes in the AMDPGU math libraries to the linker wrapper.
The wrapper already handles linking OpenMP bitcode libraries via the
`--target-library` option. This should be sufficient to link in math
libraries for the accompanying architecture.

Fixes #53526.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D119841
2022-02-16 11:39:11 -05:00
Adrian Prantl 0604d86c07 Darwin: introduce a global override for debug prefix map entries.
This patch adds a new Darwin clang driver environment variable in the
spirit of RC_DEBUG_OPTIONS, called RC_DEBUG_PREFIX_MAP, which allows a
meta build tool to add one additional -fdebug-prefix-map entry without
the knowledge of the build system.

rdar://85224675

Differential Revision: https://reviews.llvm.org/D119850
2022-02-16 08:36:26 -08:00
Sven van Haastregt 6690b7d3ac [OpenCL] Ensure atomic_init is guarded with extension
The named and generic address space overloads for atomic_init added
by 50f8abb9f4 ("[OpenCL] Add OpenCL 3.0 atomics to
-fdeclare-opencl-builtins", 2022-02-11) were not guarded by the
corresponding extensions.
2022-02-16 15:12:23 +00:00
Peter Kasting c5fb05f663 Reland: Make lld-link work in a non-MSVC shell, add /winsysroot:
This relands 73e585e44d (and 0574b5fc65), with a fix for
the failing test (by using Optional<StringRef>s instead of
making StringRef::empty() mean absence of value).

Differential Revision: https://reviews.llvm.org/D118070
2022-02-16 09:22:39 -05:00
Nikita Popov fe3407a91b [CGBuilder] Assert that CreateAddrSpaceCast does not change element type
Address space casts in general may change the element type, but
don't allow it in the method working on Address, so we can
preserve the element type.

CreatePointerBitCastOrAddrSpaceCast() still needs to be addressed.
2022-02-16 15:17:08 +01:00
Nathan Sidwell 082f328899 [clang] Itanium mangler constructors
The Itanium mangler constructors use both NSDMI and explicit member
construction for default values.  This is confusing.

*) Use NSDMIs wherever possible

*) Use forwarding ctor for the nesting case with an
 llvm::raw_null_ostream (and explicitly set NullOut flag in that ctor).

*) Copy the ModuleSubstitutions.  This is a bug with no effect in the
 current mangling, but not in the newer mangling.

Reviewed By: ChuanqiXu

Differential Revision: https://reviews.llvm.org/D119550
2022-02-16 04:30:47 -08:00
Sven van Haastregt 477bc8e8b9 [OpenCL] Guard atomic_double with cl_khr_int64_*
It is necessary to guard atomic_double type according to
https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_C.html#_footnotedef_54.
Platform that disable cl_khr_int64_base_atomics and
cl_khr_int64_extended_atomics will have compiling errors even if
atomic_double is not used.

Patch by Haonan Yang.

Differential Revision: https://reviews.llvm.org/D119398
2022-02-16 10:07:35 +00:00
Balazs Benics b3c0014e5a Revert "Revert "[analyzer] Prevent misuses of -analyze-function""
This reverts commit 620d99b7ed.

Let's see if removing the two offending RUN lines makes this patch pass.
Not ideal to drop tests but, it's just a debugging feature, probably not
that important.
2022-02-16 10:33:21 +01:00
Chuanqi Xu d30ca5e2e2 [C++20] [Coroutines] Implement return value optimization for get_return_object
This patch tries to implement RVO for coroutine's return object got from
get_return_object.
From [dcl.fct.def.coroutine]/p7 we could know that the return value of
get_return_object is either a reference or a prvalue. So it makes sense
to do copy elision for the return value. The return object should be
constructed directly into the storage where they would otherwise be
copied/moved to.

Test Plan: folly, check-all

Reviewed By: junparser

Differential revision: https://reviews.llvm.org/D117087
2022-02-16 13:38:00 +08:00
Nico Weber 125abb61f7 Revert "Add support for floating-point option `ffp-eval-method` and for"
This reverts commit 4bafe65c2b.
Breaks at least Misc/warning-flags.c, see comments on
https://reviews.llvm.org/D109239
2022-02-15 22:02:25 -05:00
Richard Smith 13b6f31548 Fix crash when deserializing a lambda expression in a decltype. 2022-02-15 17:56:45 -08:00
Zahira Ammarguellat 4bafe65c2b Add support for floating-point option `ffp-eval-method` and for
`pragma clang fp eval_method`.
2022-02-15 13:59:27 -08:00
Björn Schäpers 8da319fe77 [clang-format][NFC] Give State.Stack.back() a meaningful name
Without that debugging was a hell for me.

Differential Revision: https://reviews.llvm.org/D119597
2022-02-15 21:37:38 +01:00
Björn Schäpers b786a4aefe [clang-format] Extend SpaceBeforeParens for requires
We can now configure the space between requires and the following paren,
seperate for clauses and expressions.

Differential Revision: https://reviews.llvm.org/D113369
2022-02-15 21:37:36 +01:00
Björn Schäpers bcd1e4612f [clang-format] Further improve support for requires expressions
Detect requires expressions in more unusable contexts. This is far from
perfect, but currently we have no good metric to decide between a
requires expression and a trailing requires clause.

Differential Revision: https://reviews.llvm.org/D119138
2022-02-15 21:37:35 +01:00
Yaxun (Sam) Liu 73b22935a7 [CUDA][HIP] Do not promote constexpr var with non-constant initializer
constexpr var may be initialized with address of non-const variable.
In this case the initializer is not constant in device compilation.
This has been handled for const vars but not for constexpr vars.

This patch makes handling of const var and constexpr var
consistent.

Reviewed by: Artem Belevich

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

Fixes: https://github.com/llvm/llvm-project/issues/53780
2022-02-15 15:15:55 -05:00
Joseph Huber 24ecafb413 [OpenMP] Add support for CPU offloading in new driver
This patch adds support for linking CPU offloading applications in the
linker wrapper. We generate the necessary linking job using the host
linker's path and library arguments. This may not be true for more
complex offloading schemes, but this is sufficient for now.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D119613
2022-02-15 15:05:30 -05:00
David Blaikie 9980a3f831 DebugInfo: Disable simplified template names for -gmlt and below
Since -gmlt doesn't carry any type information necessary to rebuild
template names.
2022-02-15 11:58:40 -08:00
David Blaikie 1ea326634b DebugInfo: Don't simplify template names using _BitInt(N)
_BitInt(N) only encodes the byte size in DWARF, not the bit size, so
can't be reconstituted.
2022-02-15 11:58:40 -08:00
Amy Kwan 5dc0a1657b [PowerPC] Fix __builtin_pdepd and __builtin_pextd to be 64-bit and P10 only.
The `__builtin_pdepd` and `__builtin_pextd` are P10 builtins that are meant to
be used under 64-bit only. For instance, when the builtins are compiled under
32-bit mode:
```
$ cat t.c
unsigned long long foo(unsigned long long a, unsigned long long b) {
  return __builtin_pextd(a,b);
}

$ clang -c t.c -mcpu=pwr10 -m32
ExpandIntegerResult #0: t31: i64 = llvm.ppc.pextd TargetConstant:i32<6928>, t28, t29

fatal error: error in backend: Do not know how to expand the result of this operator!
```
This patch adds sema checking for these builtins to compile under 64-bit
mode only and on P10. The builtins will emit a diagnostic when they are compiled on
non-P10 compilations and on 32-bit mode.

Differential Revision: https://reviews.llvm.org/D118753
2022-02-15 12:30:50 -06:00
Marek Kurdej e21db15be8 [clang-format] Honour PointerAlignment in statements with initializers.
Fixes https://github.com/llvm/llvm-project/issues/53843.

Reviewed By: HazardyKnusperkeks, owenpan

Differential Revision: https://reviews.llvm.org/D119814
2022-02-15 18:06:32 +01:00
Eric Li d1e3235f60 [libTooling] Change Tranformer's consumer to take multiple changes
Previously, Transformer would invoke the consumer once per file modified per
match, in addition to any errors encountered. The consumer is not aware of which
AtomicChanges come from any particular match. It is unclear which sets of edits
may be related or whether an error invalidates any previously emitted changes.

Modify the signature of the consumer to accept a set of changes. This keeps
related changes (i.e. all edits from a single match) together, and clarifies
that errors don't produce partial changes.

Reviewed By: ymandel

Differential Revision: https://reviews.llvm.org/D119745
2022-02-15 16:34:36 +00:00
Alexander Potapenko 05ee1f4af8 Revert "[asan] Add support for disable_sanitizer_instrumentation attribute"
This reverts commit dd145f953d.

https://reviews.llvm.org/D119726, like https://reviews.llvm.org/D114421,
still causes TSan to fail, see https://lab.llvm.org/buildbot/#/builders/70/builds/18020

Differential Revision: https://reviews.llvm.org/D119838
2022-02-15 15:04:53 +01:00
Alexander Potapenko dd145f953d [asan] Add support for disable_sanitizer_instrumentation attribute
For ASan this will effectively serve as a synonym for
__attribute__((no_sanitize("address")))

This is a reland of https://reviews.llvm.org/D114421

Reviewed By: melver, eugenis

Differential Revision: https://reviews.llvm.org/D119726
2022-02-15 14:06:12 +01:00
Nathan Sidwell 02093906fa [clang][NFC] Remove IgnoreLinkageSpecDecls
The Itanium mangler uses IgnoreLinkageSpecDecls to strip linkage spec
contexts.  It doesn't do this consistently, but there is no need for
it to do it at all.  getEffectiveDeclContext never returns a linkage
spec, as it either recurses, uses getRedeclContext (which itself
removes the specs), or gets the decl context of non-namespace entities.

This patch removes the function and all calls to it.  For safety I add
a couple of asserts to make sure we never get them.

Reviewed By: ChuanqiXu

Differential Revision: https://reviews.llvm.org/D119748
2022-02-15 04:28:45 -08:00
Sven van Haastregt 074451bd33 [OpenCL] opencl-c.h: fix atomic_fetch_max with addrspace
Commit 3c7d2f1b67 ("[OpenCL] opencl-c.h: add CL 3.0 non-generic
address space atomics", 2021-07-30) added some atomic_fetch_add/sub
overloads with uintptr_t arguments twice.  Instead, they should have
been atomic_fetch_max overloads with non-generic address spaces.
2022-02-15 12:12:03 +00:00
iains 2370977bdd [clang] Remove a duplicate action kind table entry.
We have two entries for OPT_emit_codegen_only in the frontend action kind
table, delete one.

Differential Revision: https://reviews.llvm.org/D119826
2022-02-15 11:19:09 +00:00
Jan Svoboda e7dcf09fc3 [clang][lex] Use `SearchDirIterator` types in for loops
This patch replaces a lot of index-based loops with iterators and ranges.

Depends on D117566.

Reviewed By: ahoppen

Differential Revision: https://reviews.llvm.org/D119722
2022-02-15 11:02:26 +01:00
Jan Svoboda 17c9fcd6f6 [clang][lex] Use `ConstSearchDirIterator` in lookup cache
This patch starts using the new iterator type in `LookupFileCacheInfo`.

Depends on D117566.

Reviewed By: ahoppen

Differential Revision: https://reviews.llvm.org/D119721
2022-02-15 10:39:05 +01:00
Jan Svoboda 7631c366c8 [clang][lex] Introduce `ConstSearchDirIterator`
The `const DirectoryLookup *` out-parameter of `{HeaderSearch,Preprocessor}::LookupFile()` is assigned the most recently used search directory, which callers use to implement `#include_next`.

From the function signature it's not obvious the `const DirectoryLookup *` is being used as an iterator. This patch introduces `ConstSearchDirIterator` to make that affordance obvious. This would've prevented a bug that occurred after initially landing D116750.

Reviewed By: ahoppen

Differential Revision: https://reviews.llvm.org/D117566
2022-02-15 10:36:54 +01:00
Jan Svoboda a081a0654f [clang][lex] NFC: De-duplicate some #include_next logic
This patch addresses a FIXME and de-duplicates some `#include_next` logic

Depends on D119714.

Reviewed By: ahoppen

Differential Revision: https://reviews.llvm.org/D119716
2022-02-15 09:52:39 +01:00
Jan Svoboda c6f8704053 [clang][deps] Disable global module index
While scanning dependencies of a TU that depends on a PCH, the scanner basically performs mixed implicit/explicit modular compilation. (Explicit modules come from the PCH.) This seems to trip up the global module index.

This patch disables global module index in the dependency scanner.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D118890
2022-02-15 09:51:23 +01:00
Jan Svoboda d8298f04a9 [clang][lex][minimizer] Avoid treating path separators as comments
The minimizer strips out single-line comments (introduced by `//`). This sequence of characters can also appear in `#include` or `#import` directives where they play the role of path separators. We already avoid stripping this character sequence for `#include` but not for `#import` (which has the same semantics). This patch makes it so `#import <A//A.h>` is not affected by minimization. Previously, we would incorrectly reduce it into `#import <A`.

Reviewed By: arphaman

Differential Revision: https://reviews.llvm.org/D119226
2022-02-15 09:49:19 +01:00
Jan Svoboda fd2dff17c5 [clang][lex][minimizer] Ensure whitespace between squashed lines
The minimizer tries to squash multi-line macro definitions into single line. For that to work, contents of each line need to be separated by a space. Since we always strip leading whitespace on lines of a macro definition, the code currently tries to preserve exactly one space that appeared before the backslash.

This means the following code:

```
#define FOO(BAR) \
  #BAR           \
  baz
```

gets minimized into:

```
#define FOO(BAR) #BAR baz
```

However, if there are no spaces before the backslash on line 2:

```
#define FOO(BAR) \
  #BAR\
  baz
```

no space can be preserved, leading to (most likely) malformed macro definition:

```
#define FOO(BAR) #BARbaz
```

This patch makes sure we always put exactly one space at the end of line ending with a backslash.

Reviewed By: arphaman

Differential Revision: https://reviews.llvm.org/D119231
2022-02-15 09:49:03 +01:00
Jan Svoboda edd09bb5a4 [clang][lex] Remove `Preprocessor::GetCurDirLookup()`
`Preprocessor` exposes the search directory iterator via `GetCurDirLookup()` getter, which is only used in two static functions.

To simplify reasoning about search directory iterators/references and to simplify the `Preprocessor` API, this patch makes the two static functions private member functions and removes the getter entirely.

Depends D119708.

Reviewed By: ahoppen, dexonsmith

Differential Revision: https://reviews.llvm.org/D119714
2022-02-15 09:48:25 +01:00
Jan Svoboda 7a124f4859 [clang][lex] Remove `PPCallbacks::FileNotFound()`
The purpose of the `FileNotFound` preprocessor callback was to add the ability to recover from failed header lookups. This was to support downstream project.

However, injecting additional search path while performing header search can invalidate currently used iterators/references to `DirectoryLookup` in `Preprocessor` and `HeaderSearch`.

The downstream project ended up maintaining a separate patch to further tweak the functionality. Since we don't have any upstream users nor open source downstream users, I'd like to remove this callback for good to prevent future misuse. I doubt there are any actual downstream users, since the functionality is definitely broken at the moment.

Reviewed By: ahoppen

Differential Revision: https://reviews.llvm.org/D119708
2022-02-15 09:48:25 +01:00
Brad Smith d241ce0f97 [Driver][NetBSD] -r: imply -nostdlib like GCC
Similar to D116843 for Gnu.cpp

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D119655
2022-02-14 23:29:13 -05:00
Brad Smith cbd9d136ef [Driver][DragonFly] -r: imply -nostdlib like GCC
Similar to D116843 for Gnu.cpp

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D119656
2022-02-14 23:24:26 -05:00
Mike Rice 83a407d176 [OpenMP]Fix parsing of OpenMP directive nested in a metadirective
Differential Revision: https://reviews.llvm.org/D119761
2022-02-14 16:15:20 -08:00
Volodymyr Sapsai fa4a0f1d31 [modules] Add a flag for TagDecl if it was a definition demoted to a declaration.
For redeclaration chains we maintain an invariant of having only a
single definition in the chain. In a single translation unit we make
sure not to create duplicates. But modules are separate translation
units and they can contain definitions for the same symbol
independently. When we load such modules together, we need to demote
duplicate definitions to keep the AST invariants.

Some AST clients are interested in distinguishing
declaration-that-was-demoted-from-definition and
declaration-that-was-never-a-definition. For that purpose introducing
`IsThisDeclarationADemotedDefinition`. No functional change intended.

rdar://84677782

Differential Revision: https://reviews.llvm.org/D118855
2022-02-14 16:04:40 -08:00
Alex Lorenz d238acd113 [clang][driver] add clang driver support for emitting macho files with two build version load commands
This patch extends clang driver to pass the right flags to the clang frontend, and ld64,
so that they can emit macho files with two build version load commands. It adds a new
0darwin-target-variant option which complements -target and also can be used to specify different
target variants when multi-arch compilations are invoked with multiple -arch commands.

Differential Revision: https://reviews.llvm.org/D118862
2022-02-14 12:27:14 -08:00
Aaron Ballman a766545402 Update the diagnostic behavior of [[noreturn]] in C2x
Post-commit review feedback suggested dropping the deprecated
diagnostic for the 'noreturn' macro (the diagnostic from the header
file suffices and the macro diagnostic could be confusing) and to only
issue the deprecated diagnostic for [[_Noreturn]] when the attribute
identifier is either directly written or not from a system macro.

Amends the commit made in 5029dce492.
2022-02-14 14:04:32 -05:00
Balazs Benics b8ae323cca Revert "[analyzer] Add failing test case demonstrating buggy taint propagation"
This reverts commit 744745ae19.

I'm reverting this since this patch caused a build breakage.

https://lab.llvm.org/buildbot/#/builders/91/builds/3818
2022-02-14 18:45:46 +01:00
Balazs Benics d16c5f4192 Revert "[analyzer] Fix taint propagation by remembering to the location context"
This reverts commit b099e1e562.

I'm reverting this since the head of the patch stack caused a build
breakage.

https://lab.llvm.org/buildbot/#/builders/91/builds/3818
2022-02-14 18:45:46 +01:00
Balazs Benics 2acead35c1 Revert "[analyzer] Fix taint rule of fgets and setproctitle_init"
This reverts commit bf5963bf19.

I'm reverting this since the head of the patch stack caused a build
breakage.

https://lab.llvm.org/buildbot/#/builders/91/builds/3818
2022-02-14 18:45:46 +01:00
Alex Lorenz 00cd6c0420 [Preprocessor] Reduce the memory overhead of `#define` directives (Recommit)
Recently we observed high memory pressure caused by clang during some parallel builds.
We discovered that we have several projects that have a large number of #define directives
in their TUs (on the order of millions), which caused huge memory consumption in clang due
to a lot of allocations for MacroInfo. We would like to reduce the memory overhead of
clang for a single #define to reduce the memory overhead for these files, to allow us to
reduce the memory pressure on the system during highly parallel builds. This change achieves
that by removing the SmallVector in MacroInfo and instead storing the tokens in an array
allocated using the bump pointer allocator, after all tokens are lexed.

The added unit test with 1000000 #define directives illustrates the problem. Prior to this
change, on arm64 macOS, clang's PP bump pointer allocator allocated 272007616 bytes, and
used roughly 272 bytes per #define. After this change, clang's PP bump pointer allocator
allocates 120002016 bytes, and uses only roughly 120 bytes per #define.

For an example test file that we have internally with 7.8 million #define directives, this
change produces the following improvement on arm64 macOS: Persistent allocation footprint for
this test case file as it's being compiled to LLVM IR went down 22% from 5.28 GB to 4.07 GB
and the total allocations went down 14% from 8.26 GB to 7.05 GB. Furthermore, this change
reduced the total number of allocations made by the system for this clang invocation from
1454853 to 133663, an order of magnitude improvement.

The recommit fixes the LLDB build failure.

Differential Revision: https://reviews.llvm.org/D117348
2022-02-14 09:27:44 -08:00
Arthur O'Dwyer 3c8d2aa87c [clang] Don't emit redundant warnings for 'return;'
when the function declaration's return type is already invalid for
some reason. This is relevant to https://github.com/llvm/llvm-project/issues/49188
because another way that the declaration's return type could become
invalid is that it might be `C auto` where `C<void>` is false.

Differential Revision: https://reviews.llvm.org/D119094
2022-02-14 11:28:32 -05:00
Balazs Benics bf5963bf19 [analyzer] Fix taint rule of fgets and setproctitle_init
There was a typo in the rule.
`{{0}, ReturnValueIndex}` meant that the discrete index is `0` and the
variadic index is `-1`.
What we wanted instead is that both `0` and `-1` are in the discrete index
list.

Instead of this, we wanted to express that both `0` and the
`ReturnValueIndex` is in the discrete arg list.

The manual inspection revealed that `setproctitle_init` also suffered a
probably incomplete propagation rule.

Reviewed By: Szelethus, gamesh411

Differential Revision: https://reviews.llvm.org/D119129
2022-02-14 16:55:55 +01:00