Commit Graph

96591 Commits

Author SHA1 Message Date
mitchell c0779756a0 [clang-format] Fix alignment in #else preprocessor blocks
Summary:
clang-format makes multiple passes when #if/#else preprocessor blocks are found.  It will make
one pass for normal code and code in the #if block, and then it will make another pass for just
the code in #else blocks. This often results in invalid alignment inside the else blocks because
they do not have any scope or indentAndNestingLevel context from their surrounding tokens/lines.

This patch remedies that by caching any initial indentAndNestingLevel from a second pass and
not breaking/returning early when a scope change is detected.

Fixes #36070

Reviewers: HazardyKnusperkeks, MyDeveloperDay

Tags: clang, clang-format

Differential Revision: https://reviews.llvm.org/D134042
2022-09-27 15:41:09 -04:00
Jennifer Yu 30cc712eb6 [Clang][OpenMP] Fix run time crash when use_device_addr is used.
It is data mapping ordering problem.

According omp spec
If one or more map clauses are present, the list item conversions that
are performed for any use_device_ptr or use_device_addr clause occur
after all variables are mapped on entry to the region according to those
map clauses.

The change is to put mapping data for use_device_addr at end of data
mapping array.

Differential Revision: https://reviews.llvm.org/D134556
2022-09-27 11:53:57 -07:00
Qiongsi Wu 86cd353520 [LTO][clang] Using Single Dash Consistently when Passing LTO Options
The following three static functions in `clang/lib/Driver/ToolChains/CommonArgs.cpp`

```
static void renderRpassOptions(...)
static void renderRemarksOptions(...)
static void renderRemarksHotnessOptions(...)
```

use `--plugin-opt` for the plugin option prefix, while the function `tools::addLTOOptions`  uses `-plugin-opt`. This patch makes sure that we only use `-plugin-opt` (single dash) everywhere. It is not clear to me that why we decided to use `--plugin-opt` in https://reviews.llvm.org/D85810. If using `--plugin-opt` is intended, I'd love to hear the reason and I will close this patch.

We intend to followup this patch with a few other patches that teach `clang` to pass plugin options to the AIX linker, which uses a different prefix (`-bplugin_opt:`).

Reviewed By: w2yehia

Differential Revision: https://reviews.llvm.org/D134668
2022-09-27 14:50:41 -04:00
Chris Bieneman e432108bf2 [CMake] Add `CLANG_ENABLE_HLSL` CMake option
The HLSL support in clang is in progress and not fully functioning. As
such we don't want to install the related optional build components by
default (yet), but we do need an option to build and install them
locally for testing and for some key users.

This adds the `CLANG_ENABLE_HLSL` option which is off by default and can
be enabled to install the HLSL clang headers and the clang-dxc symlink.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D134693
2022-09-27 12:33:22 -05:00
Craig Topper cbbce9b537 [Driver] Silence a -Wparentheses error. NFC 2022-09-27 10:25:23 -07:00
Craig Topper d1ad006a8f [Driver] Prevent Mips specific code from claiming -mabi argument on other targets.
Fixes PR57976.

Reviewed By: erichkeane, arichardson, MaskRay

Differential Revision: https://reviews.llvm.org/D134671
2022-09-27 10:07:20 -07:00
Joseph Huber f50a7c7a26 [LinkerWrapper] Fix optimized debugging builds for NVPTX LTO
The ptxas assembler does not allow the `-g` flag along with
optimizations. Normally this is degraded to line info in the driver, but
when using LTO we did not have this step and the linker wrapper was not
correctly degrading the option. Note that this will not work if the user
does not pass `-g` again to the linker invocation. That will require
setting some flags in the binary to indicate that debugging was used
when building.

This fixes #57990

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D134660
2022-09-27 10:49:17 -05:00
Erich Keane 6b0b306e62 Fix regression from Deferred Concepts with lambda in var init
As reported in GH #57945, this would crash because the decl context for
the lambda was being loaded via 'getNonClosureContext', which only gets
CODE contexts, so a global lambda was getting 'nullptr' here instead.
This patch does some work to make sure we get a valid/valuable
declcontext here instead.
2022-09-27 06:32:39 -07:00
Daniel Kiss 712de9d171 [AArch64] Add all predecessor archs in target info
A given function is compatible with all previous arch versions.
To avoid compering values of the attribute this logic adds all predecessor
architecture values.

Reviewed By: dmgreen, DavidSpickett

Differential Revision: https://reviews.llvm.org/D134353
2022-09-27 10:23:21 +02:00
David Sherwood fbb119412f [AArch64] Add Neoverse V2 CPU support
Adds support for the Neoverse V2 CPU to the AArch64 backend.

Differential Revision: https://reviews.llvm.org/D134352
2022-09-27 07:56:08 +00:00
Yaxun (Sam) Liu 1172bdecfa [HIP] Fix unbundling archive
HIP is able to unbundle archive of bundled bitcode.
However currently there are two bugs:

1. archives passed by -l: are not unbundled.
2. archives passed as input files are not unbundled

The actual file name of an archive passed by -l: should
not be prefixed with lib and appended with '.a',
but the file path is prefixed with paths in '-L' options.

The actual file name of an archive passed as an input file
stays the same, not affected by the '-L' options.
2022-09-26 22:16:17 -04:00
Yuanfang Chen f3e02989e6 [NFC][Clang] Remove dead code
And correct a few typos.
2022-09-26 18:32:52 -07:00
Fangrui Song b2d7a0dcf1 [AArch64] Check target feature support for __builtin_arm_crc*
This is the AArch64 counterpart of D134127.
Daniel Kiss will change more `BUILTIN` to `TARGET_BUILTIN`.

Fix #57802
2022-09-26 17:16:44 -07:00
Akira Hatanaka 0ca1051bfc Check whether the allocated type is an array type before calling
checkArrayElementAlignment in Sema::BuildCXXNew

This commit fixes a bug that was introduced by adaf62ced and reported
here: https://reviews.llvm.org/D133711#3814717
2022-09-26 14:21:21 -07:00
Jan Svoboda 8df1f3bc19 [clang][deps] Fix test on AIX
The "-fno-integrated-as" on AIX expands the driver invocation into multiple jobs. This patch makes new test accommodates for that.
2022-09-26 12:40:28 -07:00
Jan Svoboda 715bd12d2e [clang][modules] Over-align the `Module` class
This makes `llvm::PointerIntPair<Module *, 3>` from f35230ae work across platforms.

Reviewed By: srj

Differential Revision: https://reviews.llvm.org/D134653
2022-09-26 10:55:22 -07:00
Richard Howell 1f451a8bd6 [clang] initialize type qualifiers for FunctionNoProtoType
When initializing FunctionNoProtoType types, zero out the type
qualifiers. This will ensure the ODR hash remains stable as it
hashes the values for these qualifiers for all function types.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D133586
2022-09-26 09:48:54 -07:00
Nathan Sidwell 53c3664f67 [xmm] Remove duplicate #define
I noticed a duplicate macro definition in xmmintrin.h.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D134545
2022-09-26 08:59:55 -07:00
Erich Keane 684a78968b Reapply "[Concepts] Recover properly from a RecoveryExpr in a concept"
This reverts commit 192d69f7e6.

This fixes the condition to check whether this is a situation where we
are in a recovery-expr'ed concept a little better, so we don't access an
inactive member of a union, which should make the bots happy.

Differential Revision: https://reviews.llvm.org/D134542
2022-09-26 08:39:10 -07:00
Erich Keane 192d69f7e6 Revert "[Concepts] Recover properly from a RecoveryExpr in a concept"
This reverts commit e3d14bee23.

There are apparently a large number of crashes in libcxx and some JSON
Parser thing, so clearly this has some sort of serious issue.  Reverting
so I can take some time to figure out what is going on.
2022-09-26 06:55:25 -07:00
Erich Keane e3d14bee23 [Concepts] Recover properly from a RecoveryExpr in a concept
Discovered by reducing a different problem, we currently assert because
we failed to make the constraint expressions not dependent, since a
RecoveryExpr cannot be transformed.

This patch fixes that, and gets reasonably nice diagnostics by
introducing a concept (hah!) of "ContainsErrors" to the Satisfaction
types, which causes us to treat the candidate as non-viable.

However, just making THAT candidate non-viable would result in choosing
the 'next best' canddiate, which can result in awkward errors, where we
start evaluating a candidate that is not intended to be selected.
Because of this, and to make diagnostics more relevant, we now just
cause the entire lookup to result in a 'no-viable-candidates'.

This means we will only emit the list of candidates, rather than any
cascading failures.
2022-09-26 06:33:48 -07:00
Aaron Ballman 91babd3516 Update the status of a few more C99 DRs 2022-09-26 08:20:56 -04:00
Tomasz Kamiński 4ff836a138 [analyzer] Pass correct bldrCtx to computeObjectUnderConstruction
In case when the prvalue is returned from the function (kind is one
of `SimpleReturnedValueKind`, `CXX17ElidedCopyReturnedValueKind`),
then it construction happens in context of the caller.
We pass `BldrCtx` explicitly, as `currBldrCtx` will always refer to callee
context.

In the following example:
```
struct Result {int value; };
Result create() { return Result{10}; }
int accessValue(Result r) { return r.value; }

void test() {
   for (int i = 0; i < 2; ++i)
      accessValue(create());
}
```

In case when the returned object was constructed directly into the
argument to a function call `accessValue(create())`, this led to
inappropriate value of `blockCount` being used to locate parameter region,
and as a consequence resulting object (from `create()`) was constructed
into a different region, that was later read by inlined invocation of
outer function (`accessValue`).
This manifests itself only in case when calling block is visited more
than once (loop in above example), as otherwise there is no difference
in `blockCount` value between callee and caller context.
This happens only in case when copy elision is disabled (before C++17).

Reviewed By: NoQ

Differential Revision: https://reviews.llvm.org/D132030
2022-09-26 11:39:10 +02:00
Simon Pilgrim 75e90ea766 Fix MSVC "not all control paths return a value" warning. NFCI. 2022-09-26 10:27:38 +01:00
Danil Sidoruk 258d7b86ee [clang-format] Handle constructor invocations after new operator in C# correct
Fixes #56549.

Differential Revision: https://reviews.llvm.org/D129926
2022-09-25 21:10:26 -07:00
Sam McCall 30b676ac5f Don't crash when code completing `using enum ^Foo`.
Fixes https://github.com/clangd/clangd/issues/1281

Differential Revision: https://reviews.llvm.org/D134243
2022-09-26 04:52:19 +02:00
Weining Lu 394f30919a [Clang][LoongArch] Add inline asm support for constraints f/l/I/K
This patch adds support for constraints `f`, `l`, `I`, `K` according
to [1]. The remain constraints (`k`, `m`, `ZB`, `ZC`) will be added
later as they are a little more complex than the others.
f: A floating-point register (if available).
l: A signed 16-bit constant.
I: A signed 12-bit constant (for arithmetic instructions).
K: An unsigned 12-bit constant (for logic instructions).

For now, no need to support register alias (e.g. `$a0`) in llvm as
clang will correctly decode the usage of register name aliases into
their official names. And AFAIK, the not yet upstreamed `rustc` for
LoongArch will always use official register names (e.g. `$r4`).

[1] https://gcc.gnu.org/onlinedocs/gccint/Machine-Constraints.html

Differential Revision: https://reviews.llvm.org/D134157
2022-09-26 08:49:58 +08:00
Nico Weber ea8371247f [clang-cl] Implement /ZH: flag
Based on a patch by Arlo Siemsen (D98438)!

Differential Revision: https://reviews.llvm.org/D134544
2022-09-25 14:43:14 -04:00
Emilia Dreamer 39e6077d97
[clang-format] Look ahead before consuming `bool` in requires clause.
The comment handling the bool case says:
"bool is only allowed if it is directly followed by a paren for a cast"

This change more closely follows this directive by looking ahead for
the paren before consuming the bool keyword itself. Without a following
paren, the bool would be part of something else, such as a return type
for a function declaration

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

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D134325
2022-09-25 20:30:21 +03:00
Emilia Dreamer 7847225576
[clang-format] Correctly annotate static and consteval lambdas
`P1169` "static operator()" (https://wg21.link/P1169) is accepted to
C++23 and while clang itself doesn't exactly support it yet,
clang-format could quite easily.

This simply allows the keyword `static` to be a part of lambdas as
specified by the addition to [expr.prim.lambda.general]

While adding this, I noticed `consteval` lambdas also aren't handled,
so that keyword is now allowed to be a part of lambdas as well

Reviewed By: HazardyKnusperkeks, owenpan, MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D134587
2022-09-25 20:29:55 +03:00
Petar Avramovic dcc756d03e [AMDGPU] Pattern for flat atomic fadd f64 intrinsic with local addr
Fix regression from clang opencl test in builtins-fp-atomics-gfx90a.cl
test_flat_add_local_f64 caused by D130579
Revert a3becb333d.

Differential Revision: https://reviews.llvm.org/D134568
2022-09-25 13:25:41 +02:00
wangliushuai 910ad36e1a [Clang] Improve diagnostics about the invalid target feature.
Clang with debug builds will crash when run with empty target feature input.
And the warning message is a little bit confusing. This patch adds an empty
check and a new diagnostic to illustrate where goes wrong.

Reviewed By: MaskRay, aaron.ballman

Differential Revision: https://reviews.llvm.org/D133563
2022-09-25 10:27:08 +08:00
Jun Zhang e07ead85a3
[Clang] Warn when trying to dereference void pointers in C
Previously we only have an extension that warn void pointer deferencing
in C++, but for C we did nothing.

C2x 6.5.3.2p4 says The unary * operator denotes indirection. If it points
to an object, the result is an lvalue designating the object. However, there
is no way to form an lvalue designating an object of an incomplete type as
6.3.2.1p1 says "an lvalue is an expression (with an object type other than
void)", so the behavior is undefined.

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

Signed-off-by: Jun Zhang <jun@junz.org>

Differential Revision: https://reviews.llvm.org/D134461
2022-09-24 22:18:04 +08:00
Joseph Huber e2213159fa [Clang] Make Clang driver suggest '-Xclang' for CC1 options passed to the driver
This patch adds an additional check for if an options passed to the
Clang driver could've been intended for the clang compiler. This is
primarily done for the times when a user attempts to pass an option like
`-ast-dump` to the driver instead.

Reviewed By: MaskRay, aaron.ballman

Differential Revision: https://reviews.llvm.org/D134550
2022-09-24 07:58:40 -05:00
eopXD 75279aeecd [RISCV][Clang] Replace all undef value with poison
Address remaining work that dates back to discussion in D126745

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D134513
2022-09-24 04:42:04 -07:00
Petar Avramovic a3becb333d [clang][AMDGPU] Temporarily disable clang atomic fadd test for gfx90a
Test is broken by D130579. Temporarily disable to silence builbot failures.
2022-09-23 21:49:16 +02:00
Erich Keane 0d18815baf Fix GH57943: Friend constraint checker didn't handle null decls.
Apparently TransformDecl in TreeTransform can be called with a nullptr
for a Decl, so my casts were illegal.  The fix here is to add an early
exit to my TransformDecl.
2022-09-23 12:21:56 -07:00
Teresa Johnson b1926f308f Restore "[MemProf] Memprof profile matching and annotation"
This reverts commit 794b7ea960, and
thus restores commit a212d8da94, and
follow on fixes 0cd6763fa9,
e9ff53d42f, and
37c6a25e9a.

Use a hash function (BLAKE3) instead of hash_combine/hash_code which are
not guaranteed to be stable across executions.

Additionally, it adds a "REQUIRES: x86_64-linux" to the tests that have
raw profile inputs to avoid failures on big endian bots.

Reviewers: snehasish, davidxl

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D128142
2022-09-23 11:38:47 -07:00
Chris Bieneman d20f9f8d21 [Docs] [HLSL] Add IR reference for HLSL
HLSL uses a variety of named IR metadata and attributes to convey
additional information from the frontend to the backend. This document
tries to capture and document the named annotations to provide a
reference for future contributors.

Reviewed By: python3kgae

Differential Revision: https://reviews.llvm.org/D134304
2022-09-23 10:29:54 -05:00
Anders Langlands e8c78d8528 Allow getting template args for ClassTemplateSpecializations
Modifies clang_Cursor_getNumTemplateArguments() and friends to work on
Struct, Class and ClassTemplatePartialSpecialization decls as well as
functions.

Differential Revision: https://reviews.llvm.org/D134416
2022-09-23 11:06:14 -04:00
Nico Weber 31142c4290 [clang] Make --ld-path= work with -fuse-ld=lld
This allows using --ld-path= to set a custom linker path, while
still informing clang that the binary at that path is an lld built
at the same revision as clang, so that clang can make assumptions
about the flags it supports, its output format, etc.

This currently only has an observable effect on Darwin.

Differential Revision: https://reviews.llvm.org/D134063
2022-09-23 09:04:19 -04:00
Haojian Wu 4f8d92f1d6 [clang] Fix the bogus diagnostic introduced by the newly-added UsingTemplate Kind.
Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D123808
2022-09-23 10:36:55 +02:00
Daniel Kiss 7e1a873872 [Arm][AArch64] Make getArchFeatures to use TargetParser.def
Prefixing the the SubArch with plus sign makes the ArchFeature name.

Reviewed By: DavidSpickett

Differential Revision: https://reviews.llvm.org/D134349
2022-09-23 10:25:37 +02:00
Amir Ayupov 3dab7fede2 [CMake] Add clang-bolt target
This patch adds `CLANG_BOLT_INSTRUMENT` option that applies BOLT instrumentation
to Clang, performs a bootstrap build with the resulting Clang, merges resulting
fdata files into a single profile file, and uses it to perform BOLT optimization
on the original Clang binary.

The projects and targets used for bootstrap/profile collection are configurable via
`CLANG_BOLT_INSTRUMENT_PROJECTS` and `CLANG_BOLT_INSTRUMENT_TARGETS`.
The defaults are "llvm" and "count" respectively, which results in a profile with
~5.3B dynamically executed instructions.

The intended use of the functionality is through BOLT CMake cache file, similar
to PGO 2-stage build:
```
cmake <llvm-project>/llvm -C <llvm-project>/clang/cmake/caches/BOLT.cmake
ninja clang++-bolt # pulls clang-bolt
```

Stats with a recent checkout (clang-16), pre-built BOLT and Clang, 72vCPU/224G
| CMake configure with host Clang + BOLT.cmake | 1m6.592s
| Instrumenting Clang with BOLT | 2m50.508s
| CMake configure `llvm` with instrumented Clang | 5m46.364s (~5x slowdown)
| CMake build `not` with instrumented Clang |0m6.456s
| Merging fdata files | 0m9.439s
| Optimizing Clang with BOLT | 0m39.201s

Building Clang:
```cmake ../llvm-project/llvm -DCMAKE_C_COMPILER=... -DCMAKE_CXX_COMPILER=...
  -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS=clang
  -DLLVM_TARGETS_TO_BUILD=Native -GNinja```

| | Release | BOLT-optimized
| cmake | 0m24.016s | 0m22.333s
| ninja clang | 5m55.692s | 4m35.122s

I know it's not rigorous, but shows a ballpark figure.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D132975
2022-09-23 10:10:31 +02:00
Chuanqi Xu 1aaba40dcb [C++] [Modules] Add a test case for mocking implementation for std modules
I found this with the patch: https://reviews.llvm.org/D131858. It breaks
my local implementation but not the in-tree test cases. So I reduce the
failure and submit the test case. The more testing should be always
good.
2022-09-23 15:20:46 +08:00
Joseph Huber 5d12e9a571 [Clang][NFC] Make unused flag `-fopenmp-new-driver` help hidden
Summary:
This flag was deprecated awhile back but still shows up when using
`clang --help`. This patch just gets rid of it but keeps its interface
for backward compatibility.
2022-09-22 21:34:33 -05:00
eopXD 10409bf86e [FPEnv] Remove inaccurate comments regarding signaling NaN for isless
By draft of C23 (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2912.pdf),
the description for isless macro under 7.12.17.3 says,

The isless macro determines whether its first argument is less than its second
argument. The value of isless(x,y) is always equal to (x)< (y); however, unlike
(x) < (y), isless(x,y) does not raise the invalid floating-point exception when
x and y are unordered and neither is a signaling NaN.

isless should trap when encountering signaling NaN.

Reviewed By: jcranmer-intel, efriedma

Differential Revision: https://reviews.llvm.org/D134407
2022-09-22 18:13:16 -07:00
Amy Huang 3283f71069 Add clang flag equivalent to clang-cl /Zl flag
The /Zl flag omits default C runtime library name from obj files.
This patch just adds an equivalent clang driver flag.

Differential Revision: https://reviews.llvm.org/D133959
2022-09-22 23:08:52 +00:00
Teresa Johnson 794b7ea960 Revert "[MemProf] Memprof profile matching and annotation"
This reverts commit a212d8da94, and follow
on fixes 0cd6763fa9,
e9ff53d42f, and
37c6a25e9a.

After re-reading the documentation for hash_combine, I don't think this
is the appropriate hash function to use for computing the hash to use as
a stack id in the metadata, since it is not guaranteed to produce stable
values across executions. I have not hit this problem, but plan to
switch to using an MD5 hash. I am hitting an issue with one of the bots
(https://lab.llvm.org/buildbot/#/builders/171/builds/20732)
where the values produced are only the lower 32 bits of the expected
hash values, however, which I assume is related to the implementation of
hash_combine and hash_code.

I believe I fixed all of the other bot failures with the follow on fixes,
which I'll merge into the new version before reapplying.
2022-09-22 16:08:03 -07:00
Pavel Samolysov 1c530500ab [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-09-22 15:33:46 -07:00