Commit Graph

86781 Commits

Author SHA1 Message Date
Fangrui Song bc7df035ae Make -fintegrated-cc1 work with cc1as
Tested 0.018s faster on my machine.
2020-11-14 01:16:16 -08:00
Mehdi Amini 42e88bd6b1 Replace sequences of v.push_back(v[i]); v.erase(&v[i]); with std::rotate (NFC)
The code has a few sequence that looked like:

    Ops.push_back(Ops[0]);
    Ops.erase(Ops.begin());

And are equivalent to:

    std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end());

The latter has the advantage of never reallocating the vector, which
would be a bug in the original code as push_back would read from the
memory it deallocated.
2020-11-14 00:55:33 +00:00
Arthur Eubanks 52f05fb2c2 [MemProf][NewPM] Make memprof passes required
Just like other sanitizers.
Fixes check-memprof under NPM.

Reviewed By: leonardchan

Differential Revision: https://reviews.llvm.org/D91389
2020-11-13 15:15:27 -08:00
Duncan P. N. Exon Smith cfde3edeae Frontend: Remove unused parameter from ASTUnit::LoadFromCompilerInvocationAction, NFC
Drop `IncludeBriefCommentsInCodeCompletion` since it is always `false`.

Differential Revision: https://reviews.llvm.org/D91295
2020-11-13 17:47:17 -05:00
Vladimir Vereschaka b09154ebf9 [CMake] Explicity set up RPATH for the runtime libs on Win to ARM Linux cross builds.
Since RPATH initialization was disabled for the runtime libraries to
avoid overwriting RPATH unconditionally we need to explicity set up it
for the Win to Arm Linux cross builds.

See some details here: https://reviews.llvm.org/D91099
2020-11-13 14:32:35 -08:00
Arthur Eubanks 6e098189db [DFSan][NewPM] Handle dfsan under NPM
Make it required. Since it's a module pass, optnone won't test it, so
extend the clang test to also use opt-bisect now that it's supported.

14/16 check-dfsan tests failed with NPM enabled, now all pass.

Reviewed By: leonardchan

Differential Revision: https://reviews.llvm.org/D91385
2020-11-13 13:41:38 -08:00
Duncan P. N. Exon Smith a2f2c2f3a4 Serialization: Merge three diagnostics to simplify ASTReader::getInputFile, NFC
Clean up the logic for `err_fe_{pch,module,ast}_file_modified` to use a
`select` like other ASTReader diagnostics. There should be no
functionality change here, just a cleanup.

Differential Revision: https://reviews.llvm.org/D91367
2020-11-13 16:23:04 -05:00
Heejin Ahn 902ea588ea [WebAssembly] Rename atomic.notify and *.atomic.wait
- atomic.notify -> memory.atomic.notify
- i32.atomic.wait -> memory.atomic.wait32
- i64.atomic.wait -> memory.atomic.wait64

See https://github.com/WebAssembly/threads/pull/149.

Reviewed By: tlively

Differential Revision: https://reviews.llvm.org/D91447
2020-11-13 12:04:48 -08:00
Heejin Ahn 01d8715369 [WebAssembly] Remove a temporarily added RUN line
This RUN line was added as a temporary measure to undo the damage done
by D79655. Everyone's build system should be fine by now.

Reviewed By: tlively

Differential Revision: https://reviews.llvm.org/D91448
2020-11-13 11:57:09 -08:00
Duncan P. N. Exon Smith b764a62f02 Serialization: Rename three AST diagnostics, NFC
All three diagnostics have a select between "PCH", "module", and "AST"
in the text. The most generic of these is "AST", so rename them from
`err_module_...` to `err_ast_...`.

Differential Revision: https://reviews.llvm.org/D91436
2020-11-13 14:09:00 -05:00
Baptiste Saleil 3f78605a8c [PowerPC] Add paired vector load and store builtins and intrinsics
This patch adds the Clang builtins and LLVM intrinsics to load and store vector pairs.

Differential Revision: https://reviews.llvm.org/D90799
2020-11-13 12:35:10 -06:00
Aaron Ballman 66b876c014 Pass the source range when diagnosing an unknown attribute
This way, the whole attribute gets highlighted with diagnostics instead
of just the scope name in an attribute like [[clang::unknown]].
2020-11-13 10:29:44 -08:00
Duncan P. N. Exon Smith d87fd096ac Serialization: Hoist the check for in-flight diagnostics in ASTReader::getInputFile, NFC
This logic seems easier to follow without the `Error()` helper, and
checking `DiagnosticsEngine::isDiagnosticInFlight` just once up front.

Differential Revision: https://reviews.llvm.org/D91366
2020-11-13 13:26:37 -05:00
Nico Weber 46ca880fca clang: Don't assert on no_unique_address fields in @encode()
Just skip (non-bitfield) zero-sized fields, like we do with empty bases.

The class->struct conversion in the test is because -std=c++20 else deletes some default methods
due to non-accessible base dtors otherwise.

As a side-effect of writing the test, I discovered that D76801 did an ABI breaking change of sorts
for Objective-C's @encode. But it's been in for a while, so I'm not sure if we want to row back on
that or now.

Fixes PR48048.

Differential Revision: https://reviews.llvm.org/D90622
2020-11-13 11:39:10 -05:00
Haojian Wu 7ad6c8414c [clang] Fix an assertion crash in delayed access check.
`TD->getTemplatedDecl()` might not be a DeclContext variant, which can
trigger an assertion inside `isa<>`.

Differential Revision: https://reviews.llvm.org/D91380
2020-11-13 14:02:57 +01:00
Jan Svoboda d2d59d2be9 Reland [clang][cli] Port ObjCMTAction to new option parsing system
Merge existing marhsalling info kinds and add some primitives to
express flag options that contribute to a bitfield.

Depends on D82574

Original patch by Daniel Grumberg.

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D82860
2020-11-13 13:42:54 +01:00
Serge Pavlov 92d7a84e12 [Driver] Add option -fproc-stat-report
The new option `-fproc-stat-info=<file>` can be used to generate report
about used memory and execution tile of each stage of compilation.
Documentation for this option can be found in `UserManual.rst`. The
option can be used in parallel builds.

Differential Revision: https://reviews.llvm.org/D78903
2020-11-13 14:15:42 +07:00
Richard Smith 7602ef768b Suppress trailing template arguments equivalent to default arguments
when printing the name of a member of a class template specialization.
2020-11-12 21:10:34 -08:00
Michael Liao 8920ef06a1 [hip] Remove the coercion on aggregate kernel arguments.
- If an aggregate argument is indirectly accessed within kernels, direct
  passing results in unpromotable `alloca`, which degrade performance
  significantly. InferAddrSpace pass is enhanced in
  [D91121](https://reviews.llvm.org/D91121) to take the assumption that
  generic pointers loaded from the constant memory could be regarded
  global ones. The need for the coercion on aggregate arguments is
  mitigated.

Differential Revision: https://reviews.llvm.org/D89980
2020-11-12 21:19:30 -05:00
Amy Huang 0c80b542d3 Some updates/fixes to the creduce script.
This was motivated by changes to llvm's `not --crash` disabling symbolization
but I ended up removing `not` from the script entirely because it
returns differently depending on  whether clang "crashes" or exits for some
other reason. The script had to choose between calling `not` and `not --crash`
and sometimes it was wrong.

The script also now disables symbolization when we don't read the stack
trace because symbolizing is kind of slow.

Differential Revision: https://reviews.llvm.org/D91372
2020-11-12 13:40:26 -08:00
Alexey Bataev 07b568a9c8 [OPENMP]Fix PR47790: segfault in frontend while parsing Objective-C with OpenMP.
Need to check if the sema is actually finishing a function decl.

Differential Revision: https://reviews.llvm.org/D91376
2020-11-12 13:26:11 -08:00
Kazushi (Jam) Marukawa 9c504ec06d [VE] Disable -fsigaddr option for VE
VE needs to support integrated assembler and "nas".  This "nas"
doesn't recognize ".sigaddr" pseudo mnemonics, so need to disable
it.  This patch disable it on VE by default.  Also add a regression
test for that.

Reviewed By: simoll

Differential Revision: https://reviews.llvm.org/D91350
2020-11-13 06:22:12 +09:00
Arthur Eubanks 3a7b57b7ca [NFC][NewPM] Reuse PassBuilder callbacks with -O0
This removes lots of duplicated code which was necessary before
https://reviews.llvm.org/D89158.
Now we can use PassBuilder::runRegisteredEPCallbacks().
This is mostly sanitizers.

There is likely more that can be done to simplify, but let's start with this.

Reviewed By: ychen

Differential Revision: https://reviews.llvm.org/D90870
2020-11-12 12:42:59 -08:00
Alexey Bataev 3c6b457bee [OPENMP]Fix PR48076: Check map types array before accessing its front.
Need to check if there are map types for the components before trying to
access them when trying to modify type mappings for combined partial
mappings.

Differential Revision: https://reviews.llvm.org/D91370
2020-11-12 12:00:29 -08:00
Anatoliy Tomilov e7c7a19826 [Frontend] Treat .cuh files as CUDA source files
to synchronize with tools/clang-format/git-clang-format

tra: Keeping them in sync does have a minor benefit of not raising a question why the two maps are different.

Differential Revision: https://reviews.llvm.org/D91034
2020-11-12 11:42:53 -08:00
Aaron Ballman b336826c1d Non-implicit attribute creation requires a source range; NFC
There are two factory functions used to create a semantic attribute,
Create() and CreateImplicit(). CreateImplicit() does not need to
specify the source range of the attribute since it's an implicitly-
generated attribute. The same logic does not apply to Create(), so
this removes the default argument from those declarations to avoid
accidentally creating a semantic attribute without source location
information.
2020-11-12 10:06:30 -08:00
Kevin P. Neal ac523d2de5 [FPEnv][Clang][Driver] Use MarshallingInfoFlag for -fexperimental-strict-floating-point
As of D80952 we are disabling strict floating point on all hosts except
those that are explicitly listed as supported. Use of strict floating point
on other hosts requires use of the -fexperimental-strict-floating-point
flag. This is to avoid bugs like "https://bugs.llvm.org/show_bug.cgi?id=45329"
(which has an incorrect link in the previous review).

In the review for D80952 I was asked to mark the -fexperimental option as
a MarshallingInfoFlag. This patch does exactly that.

Differential Revision: https://reviews.llvm.org/D88987
2020-11-12 12:51:35 -05:00
Baptiste Saleil 170e45ae18 [PowerPC] Prevent the use of MMA with P9 and earlier
We want to allow using MMA on P10 CPU only. This patch prevents the use of MMA
with the -mmma option on P9 CPUs and earlier.

Differential Revision: https://reviews.llvm.org/D91200
2020-11-12 10:36:50 -06:00
Jean-Michel Gorius 62ed69b01d [clang][docs] Remove wrongly spaced \brief in Doxygen comment (NFC) 2020-11-12 15:44:43 +01:00
Sylvain Audi 79105e4644 [clang-scan-deps] Fix for input file given as relative path in compilation database "command" entry.
Differential Revision: https://reviews.llvm.org/D91204
2020-11-12 08:48:17 -05:00
Hans Wennborg a088766508 [dllexport] Instantiate default ctor default args for explicit specializations (PR45811)
For dllexported default constructors with default arguments, we export
default constructor closures which pass in the default args. (See D8331
for a good explanation.)

For templates, that means those default args must be instantiated even
if the function isn't called. That is done by the
InstantiateDefaultCtorDefaultArgs() function, but it wasn't done for
explicit specializations, causing asserts (see bug).

Differential revision: https://reviews.llvm.org/D91089
2020-11-12 13:29:34 +01:00
Hans Wennborg b9d36540a8 [dllexport] Avoid assert for explicitly defaulted methods in explicit instantiation definitions (PR47683)
Clang was asserting due to attempting to codegen such methods twice.

Differential revision: https://reviews.llvm.org/D90849
2020-11-12 13:19:29 +01:00
Chuanqi Xu cd89c4dbdd [NFC][coroutines] remove unused argument in SemaCoroutine
Test plan: check-llvm, check-clang

Reviewers: lxfind, junparser

Differential Revision: https://reviews.llvm.org/D91243
2020-11-12 13:22:20 +08:00
Richard Smith 2d4035e493 Fix structural comparison of template template arguments to compare the
right union member.

Should fix the armv8 buildbot.
2020-11-11 19:15:21 -08:00
Qiu Chaofan 2abc33683b [PowerPC] [Clang] Define macros to identify quad-fp semantics
We have option -mabi=ieeelongdouble to set current long double to
IEEEquad semantics. Like what GCC does, we need to define
__LONG_DOUBLE_IEEE128__ macro in this case, and __LONG_DOUBLE_IBM128__
if using PPCDoubleDouble.

Reviewed By: steven.zhang

Differential Revision: https://reviews.llvm.org/D90208
2020-11-12 10:26:13 +08:00
Sam McCall 1630e50874 [Syntax] Tablegen literal expressions.
Non-mechanical changes:
 - Added FIXME to StringLiteral to cover multi-token string literals.
 - LiteralExpression::getLiteralToken() is gone. (It was never called)
   This is because we don't codegen methods in Alternatives
   It's conceptually suspect if we consider multi-token string literals, though.

Differential Revision: https://reviews.llvm.org/D91277
2020-11-12 01:26:02 +01:00
Arthur Eubanks b6ccff3d5f [NewPM] Provide method to run all pipeline callbacks, used for -O0
Some targets may add required passes via
TargetMachine::registerPassBuilderCallbacks(). We need to run those even
under -O0. As an example, BPFTargetMachine adds
BPFAbstractMemberAccessPass, a required pass.

This also allows us to clean up BackendUtil.cpp (and out-of-tree Rust
usage of the NPM) by allowing us to share added passes like coroutines
and sanitizers between -O0 and other optimization levels.

Since callbacks may end up not adding passes, we need to check if the
pass managers are empty before adding them, so PassManager now has an
isEmpty() function. For example, polly adds callbacks but doesn't always
add passes in those callbacks, so this is necessary to keep
-debug-pass-manager tests' output from changing depending on if polly is
enabled or not.

Tests are a continuation of those added in
https://reviews.llvm.org/D89083.

Reviewed By: asbirlea, Meinersbur

Differential Revision: https://reviews.llvm.org/D89158
2020-11-11 15:10:27 -08:00
Richard Smith 5f12f4ff90 Suppress printing of inline namespace names in diagnostics by default,
except where they are necessary to disambiguate the target.

This substantially improves diagnostics from the standard library,
which are otherwise full of `::__1::` noise.
2020-11-11 15:05:51 -08:00
Richard Smith e7f3e2103c Suppress printing template arguments that match default template
arguments of types by default.

This somewhat improves the worst-case printing of types like
std::string, std::vector, etc., where many irrelevant default arguments
can be included in the type as printed if we've lost the type sugar.
2020-11-11 15:05:51 -08:00
Duncan P. N. Exon Smith 4c55c3b66d Frontend: Change ComputePreambleBounds to take MemoryBufferRef, NFC
Avoid requiring an actual MemoryBuffer in ComputePreambleBounds, when
a MemoryBufferRef will do just fine.

Differential Revision: https://reviews.llvm.org/D90890
2020-11-11 17:19:51 -05:00
Florian Hahn 1d5daed199
[Matrix] Update mangling to use paramterized vendor ext type syntax.
The Itanium CXX ABI grammer has been extended to support parameterized
vendor extended types [1].

This patch updates Clang's mangling for matrix types to use the new
extension.

[1] b359d28971

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D91253
2020-11-11 21:39:22 +00:00
Kazushi (Jam) Marukawa 6e0ae20f3b [VE] Support vector register in inline asm
Support a vector register constraint in inline asm of clang.
Add a regression test also.

Reviewed By: simoll

Differential Revision: https://reviews.llvm.org/D91251
2020-11-12 06:18:35 +09:00
Duncan P. N. Exon Smith 4e9af3d478 Frontend: Skip namespace around createVFSFromCompilerInvocation definition, NFC
Qualify definitions with `clang::` rather than opening/closing a namespace.

Differential Revision: https://reviews.llvm.org/D90957
2020-11-11 16:15:06 -05:00
Mehdi Amini f917356f9c Revert "[clang][cli] Port ObjCMTAction to new option parsing system"
This reverts commit 09248a5d25.

Some builds are broken. I suspect a `static constexpr` in a class missing a
definition out of class (required pre-c++17).
2020-11-11 20:01:03 +00:00
Simon Pilgrim deb543ae70 [Driver] hip-toolchain-device-only.hip - remove unused check prefix
Just use default CHECK
2020-11-11 18:00:03 +00:00
Alex Lorenz 3df3b62018 [clang] ns_error_domain attribute also supports CFString typed variables
Differential Revision: https://reviews.llvm.org/D90891
2020-11-11 08:50:30 -08:00
Simon Pilgrim e3b64eb31c [CodeGenCXX] Remove unused check prefixes 2020-11-11 16:19:53 +00:00
Simon Pilgrim c1e3d38301 [CodeGenOpenCL] Fix check prefix typo on convergent.cl test
Noticed while fixing unused prefix warnings - there isn't actually any diff in the loop unrolled ir between old/new pass managers any more, so the broken checks were superfluous
2020-11-11 15:44:59 +00:00
Simon Pilgrim 10fc39b291 [CodeGenObjC] Remove unused check prefixes 2020-11-11 15:44:58 +00:00
Simon Pilgrim fc80931b87 [CodeGenCUDA] Fix check prefix typo on device-stub.cu tests
Noticed while fixing unused prefix warnings
2020-11-11 15:44:57 +00:00
Sam McCall ea4d24c899 [Syntax] Tablegen Sequence classes. NFC
Similar to the previous patch, this doesn't convert *all* the classes that
could be converted. It also doesn't enforce any new invariants etc.

It *does* include some data we don't use yet: specific token types that are
allowed and optional/required status of sequence items. (Similar to Dmitri's
prototype). I think these are easier to add as we go than later, and serve
a useful documentation purpose.

Differential Revision: https://reviews.llvm.org/D90659
2020-11-11 16:29:19 +01:00
Sam McCall 138189ee33 [Syntax] Tablegen operator<<(NodeKind). NFC
Differential Revision: https://reviews.llvm.org/D90662
2020-11-11 16:02:01 +01:00
Simon Pilgrim 3e5533bafd [CodeGen] Remove unused check prefixes 2020-11-11 14:57:38 +00:00
Simon Pilgrim 8cb97fb9c9 [CodeGen] Fix check prefix mismatch on neon-immediate-ubsan.c tests
Noticed while fixing unused prefix warnings,
2020-11-11 14:57:37 +00:00
Nico Weber 3109ce51d4 clang-cl: Expose -f[no-]delete-null-pointer-checks as clang-cl flag 2020-11-11 09:19:02 -05:00
Elvina Yakubova 624bced7ee [OpenCL] Make Clang recognize -cl-std=1.0 as a value argument
This patch makes Clang recognize -cl-std=1.0 as a value argument,
before only -std=cl1.0 has to be used instead.

Fixes https://bugs.llvm.org/show_bug.cgi?id=47981

Reviewed By: Anastasia

Differential Revision: https://reviews.llvm.org/D91237
2020-11-11 17:01:57 +03:00
Andrzej Warzynski fdbc7e505c [flang][driver] Make sure that `-###` is marked as supported (NFC)
`-###` has always been supported in the new flang driver. This patch
merely makes sure that it's included when printing the help screen (i.e.
`flang-new -help`).
2020-11-11 13:12:51 +00:00
Jan Svoboda 09248a5d25 [clang][cli] Port ObjCMTAction to new option parsing system
Merge existing marhsalling info kinds and add some primitives to
express flag options that contribute to a bitfield.

Depends on D82574

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D82860
2020-11-11 13:03:02 +01:00
Sam McCall 98aa067109 [Syntax] Start to move trivial Node class definitions to TableGen. NFC
This defines two node archetypes with trivial class definitions:
 - Alternatives: the generated abstract classes are trivial as all
   functionality is via LLVM RTTI
 - Unconstrained: this is a placeholder, I think all of these are going to be
   Lists but today they have no special accessors etc, so we just say
   "could contain anything", and migrate them one-by-one to Sequence later.

Compared to Dmitri's prototype, Nodes.td looks more like a class hierarchy and
less like a grammar. (E.g. variants list the Alternatives parent rather than
vice versa).
The main reasons for this:
 - the hierarchy is an important part of the API we want direct control over.
   - e.g. we may introduce abstract bases like "loop" that the grammar doesn't
     care about in order to model is-a concepts that might make refactorings
     more expressive. This is less natural in a grammar-like idiom.
   - e.g. we're likely to have to model some alternatives as variants and others
     as class hierarchies, the choice will probably be based on natural is-a
     relationships.
 - it reduces the cognitive load of switching from editing *.td to working with
   code that uses the generated classes

Differential Revision: https://reviews.llvm.org/D90543
2020-11-11 12:39:43 +01:00
Krasimir Georgiev 77b4841169 [clang-format] do not break before @tags in JS comments
In JavaScript breaking before a `@tag` in a comment puts it on a new line, and
machinery that parses these comments will fail to understand such comments.

This adapts clang-format to not break before `@`. Similar functionality exists
for not breaking before `{`.

Reviewed By: mprobst

Differential Revision: https://reviews.llvm.org/D91078
2020-11-11 12:27:15 +01:00
Sam McCall 454579e46a Reland [Syntax] Add minimal TableGen for syntax nodes. NFC
This reverts commit 09c6259d6d.
(Fixed side-effecting code being buried in an assert)
2020-11-11 11:24:47 +01:00
Faisal Vali e4d27932a5 [NFC, Refactor] Rename the (scoped) enum DeclaratorContext's enumerators to remove duplication
Since these are scoped enumerators, they have to be prefixed by DeclaratorContext, so lets remove Context from the name, and return some characters to the multiverse.

Patch was reviewed here: https://reviews.llvm.org/D91011

Thank you to aaron, bruno, wyatt and barry for indulging me.
2020-11-10 23:40:12 -06:00
Roland McGrath cf36142d34 [clang] Add missing header guard in <cpuid.h>
This header has long lacked a standard multiple inclusion guard
like other headers have, for no apparent reason.  The GCC header
of the same name likewise lacks one up through release 10.1, but
trunk GCC (release 11, and perhaps future 10.x) has fixed it
(see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96238).

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D91226
2020-11-10 19:34:25 -08:00
Akira Hatanaka d9258a21f0 Fix the data layout mangling specification for 'arm64-pc-win32-macho'
rdar://problem/70410504
2020-11-10 18:52:12 -08:00
Richard Smith c6d86b6b45 Properly collect template arguments from a class-scope function template
specialization.

Fixes a crash-on-valid if further template parameters are introduced
within the specialization (by a generic lambda).
2020-11-10 15:55:19 -08:00
Stephen Kelly 872633b285 Add utility for testing if we're matching nodes AsIs
Differential Revision: https://reviews.llvm.org/D91144
2020-11-10 23:32:30 +00:00
Richard Smith c43f8c7728 Add PrintingPolicy overload to APValue::printPretty. NFC. 2020-11-10 14:48:56 -08:00
Stephen Kelly ed2baaac56 Revert "Add utility for testing if we're matching nodes AsIs"
This reverts commit e73296d3b9.

This may have caused build bot failure.
2020-11-10 22:29:58 +00:00
Akira Hatanaka 874b0a0b9d [CodeGen] Mark calls to objc_autorelease as tail
This enables a method sending an autorelease message to an object and
returning the object in MRR to avoid adding the object to an autorelease
pool if a call to objc_retainAutoreleasedReturnValue in the caller
function accepts the hand off of the retain count.

rdar://problem/50678052

Differential Revision: https://reviews.llvm.org/D91111
2020-11-10 13:48:25 -08:00
Xun Li 19f0770923 [Coroutine][Sema] Cleanup temporaries as early as possible
The original bug was discovered in T75057860. Clang front-end emits an AST that looks like this for an co_await expression:
|- ExprWithCleanups
  |- -CoawaitExpr
    |- -MaterializeTemporaryExpr ... Awaiter
      ...
    |- -CXXMemberCallExpr ... .await_ready
      ...
    |- -CallExpr ... __builtin_coro_resume
      ...
    |- -CXXMemberCallExpr ... .await_resume
      ...

ExprWithCleanups is responsible for cleaning up (including calling dtors) for the temporaries generated in the wrapping expression).
In the above structure, the __builtin_coro_resume part (which corresponds to the code for the suspend case in the co_await with symmetric transfer), the pseudocode looks like this:
  __builtin_coro_resume(
   awaiter.await_suspend(
     from_address(
       __builtin_coro_frame())).address());

One of the temporaries that's generated as part of this code is the coroutine handle returned from awaiter.await_suspend() call. The call returns a handle  which is a prvalue (since it's a returned value on the fly). In order to call the address() method on it, it needs to be converted into an xvalue. Hence a materialized temp is created to hold it. This temp will need to be cleaned up eventually. Now, since all cleanups happen at the end of the entire co_await expression, which is after the <coro.suspend> suspension point, the compiler will think that such a temp needs to live across suspensions, and need to be put on the coroutine frame, even though it's only used temporarily just to call address() method.
Such a phenomena not only unnecessarily increases the frame size, but can lead to ASAN failures, if the coroutine was already destroyed as part of the await_suspend() call. This is because if the coroutine was already destroyed, the frame no longer exists, and one can not store anything into it. But if the temporary object is considered to need to live on the frame, it will be stored into the frame after await_suspend() returns.

A fix attempt was done in https://reviews.llvm.org/D87470. Unfortunately it is incorrect. The reason is that cleanups in Clang works more like linearly than nested. There is one current state indicating whether it needs cleanup, and an ExprWithCleanups resets that state. This means that an ExprWithCleanups must be capable of cleaning up all temporaries created  in the wrapping expression, otherwise there will be dangling temporaries cleaned up at the wrong place.
I eventually found a walk-around (https://reviews.llvm.org/D89066) that doesn't break any existing tests while fixing the issue. But it targets the final co_await only. If we ever have a co_await that's not on the final awaiter and the frame gets destroyed after suspend, we are in trouble. Hence we need a proper fix.

This patch is the proper fix. It does the folllowing things to fully resolve the issue:
1. The AST has to be generated in the order according to their nesting relationship. We should not generate AST out of order because then the code generator would incorrectly track the state of temporaries and when a cleanup is needed. So the code in buildCoawaitCalls is reorganized so that we will be generating the AST for each coawait member call in order along with their child AST.
2. await_ready() call is wrapped with an ExprWithCleanups so that temporaries in it gets cleaned up as early as possible to avoid living across suspension.
3. await_suspend() call is wrapped with an ExprWithCleanups if it's not a symmetric transfer. In the case of a symmetric transfer, in order to maintain the musttail call contract, the ExprWithCleanups is wraaped before the resume call.
4. In the end, we mark again that it needs a cleanup, so that the entire CoawaitExpr will be wrapped with a ExprWithCleanups which will clean up the Awaiter object associated with the await expression.

Differential Revision: https://reviews.llvm.org/D90990
2020-11-10 13:27:42 -08:00
Richard Smith 438a27f2e5 Move code to determine the type of an LValueBase out of ExprConstant and
into a member function on LValueBase. NFC.
2020-11-10 13:03:57 -08:00
Yang Fan 703038b35a [Sema] Fix volatile check when testing if a return object can be implicitly moved
In C++11 standard, to become implicitly movable, the expression in return
statement should be a non-volatile automatic object. CWG1579 changed the rule
to require that the expression only needs to be an automatic object. C++14
standard and C++17 standard kept this rule unchanged. C++20 standard changed
the rule back to require the expression be a non-volatile automatic object.
This should be a typo in standards, and VD should be non-volatile.

Differential Revision: https://reviews.llvm.org/D88295
2020-11-10 15:11:07 -05:00
Stephen Kelly e73296d3b9 Add utility for testing if we're matching nodes AsIs
Differential Revision: https://reviews.llvm.org/D91144
2020-11-10 19:28:11 +00:00
Haojian Wu 7d85f732b1 Fix the DeclContextLookupResult::iterator non-copyable.
The value_type is a const pointer, which makes the iteator non-copyable.
Before the patch, the normal usage like below was illegal:

```
auto It = lookupresult.begin();
...
It = lookupresult.end(); // the copy is not allowed.
```

Differential Revision: https://reviews.llvm.org/D91158
2020-11-10 20:22:45 +01:00
Alexandre Rames 58c586e701 Allow searching for prebuilt implicit modules.
This reverts commit c67656b994, and addresses the
build issue.
2020-11-10 10:14:13 -08:00
Simon Pilgrim defc59734a Add a llvm_unreachable to fix MSVC unhandled enum warning. NFCI. 2020-11-10 10:43:45 +00:00
Martin Probst 16212b8b3e clang-format: [JS] support new assignment operators.
Before:

    a && = b;

After:

    a &&= b;

These operators are new additions in ES2021.

Differential Revision: https://reviews.llvm.org/D91132
2020-11-10 09:26:46 +01:00
David Blaikie 724877e219 Roll otherwise-unused variable into assert 2020-11-09 23:27:47 -08:00
Richard Smith b637148ecb [c++20] For P0732R2 / P1907R1: Basic code generation and name
mangling support for non-type template parameters of class type and
template parameter objects.

The Itanium side of this follows the approach I proposed in
https://github.com/itanium-cxx-abi/cxx-abi/issues/47 on 2020-09-06.

The MSVC side of this was determined empirically by observing MSVC's
output.

Differential Revision: https://reviews.llvm.org/D89998
2020-11-09 22:10:27 -08:00
Haowei Wu d93287cac8 [scan-build] Supprot relative 'file' in cdb.
Excluded folders in scan build is turned to absolute path before
comapre to 'file' in cdb. 'file' in cdb might be a path relative
to 'directory', so we need to turn it to absolute path before
comparison.

Patch by Yu Shan

Differential Revision: https://reviews.llvm.org/D90362
2020-11-09 20:06:20 -08:00
Qiu Chaofan 979a4d268a [PowerPC] [Clang] Port SSE4.1-compatible insert intrinsics
This patch adds three intrinsics compatible to x86's SSE 4.1 on PowerPC
target, with tests:

- _mm_insert_epi8
- _mm_insert_epi32
- _mm_insert_epi64

The intrinsics implementation is contributed by Paul Clarke.

Reviewed By: jsji

Differential Revision: https://reviews.llvm.org/D89242
2020-11-10 10:52:13 +08:00
Michael Kruse e5dba2d7e5 [OMPIRBuilder] Start 'Create' methods with lower case. NFC.
For consistency with the IRBuilder, OpenMPIRBuilder has method names starting with 'Create'. However, the LLVM coding style has methods names starting with lower case letters, as all other OpenMPIRBuilder already methods do. The clang-tidy configuration used by Phabricator also warns about the naming violation, adding noise to the reviews.

This patch renames all `OpenMPIRBuilder::CreateXYZ` methods to `OpenMPIRBuilder::createXYZ`, and updates all in-tree callers.

I tested check-llvm, check-clang, check-mlir and check-flang to ensure that I did not miss a caller.

Reviewed By: mehdi_amini, fghanim

Differential Revision: https://reviews.llvm.org/D91109
2020-11-09 19:35:11 -06:00
Jan Svoboda dbfa69c502 Port some floating point options to new option marshalling infrastructure
This ports a number of OpenCL and fast-math flags for floating point
over to the new marshalling infrastructure.

As part of this, `Opt{In,Out}FFlag` were enhanced to allow other flags to
imply them, via `DefaultAnyOf<>`. For example:
```
defm signed_zeros : OptOutFFlag<"signed-zeros", ...,
  "LangOpts->NoSignedZero",
  DefaultAnyOf<[cl_no_signed_zeros, menable_unsafe_fp_math]>>;
```
defines `-fsigned-zeros` (`false`) and `-fno-signed-zeros` (`true`)
linked to the keypath `LangOpts->NoSignedZero`, defaulting to `false`,
but set to `true` implicitly if one of `-cl-no-signed-zeros` or
`-menable-unsafe-fp-math` is on.

Note that the initial patch was written Daniel Grumberg.

Differential Revision: https://reviews.llvm.org/D82756
2020-11-09 18:00:10 -05:00
Sam McCall 09c6259d6d Revert "[Syntax] Add minimal TableGen for syntax nodes. NFC"
This reverts commit 55120f74ca.

Segfaults during build:
http://lab.llvm.org:8011/#/builders/36/builds/1310
2020-11-09 23:59:11 +01:00
Sam McCall 55120f74ca [Syntax] Add minimal TableGen for syntax nodes. NFC
So far, only used to generate Kind and implement classof().

My plan is to have this general-purpose Nodes.inc in the style of AST
DeclNodes.inc etc, and additionally a special-purpose backend generating
the actual class definitions. But baby steps...

Differential Revision: https://reviews.llvm.org/D90540
2020-11-09 23:45:50 +01:00
Kirill Bobyrev 142c6f82fd
[clang] Simplify buildSyntaxTree API
Follow-up on https://reviews.llvm.org/D88553#inline-837013

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90672
2020-11-09 22:49:54 +01:00
Duncan P. N. Exon Smith c56ec7bede Tooling: Remove dead code for ToolingInvocation::mapVirtualFile
Follows through on c4cb3b10dc8c50e46c9fb1b7ae95e3c3c94975d3's FIXME
dating back to 2015. Anyone using this should migrate to
InMemoryFileSystem and/or ClangTool::mapVirtualFile.

Differential Revision: https://reviews.llvm.org/D90885
2020-11-09 15:45:35 -05:00
Stephen Kelly 23f17ab5ff Fix use of directly-nested traverse() matchers 2020-11-09 19:23:17 +00:00
Stephen Kelly 121d51dc83 Fix trailing whitespace
My editor keeps on changing this and I keep having to revert it.
2020-11-09 19:12:38 +00:00
Stephen Kelly 8f354711ae Change algorithms to return iterators
Make it possible to inspect the matched node, possibly to ignore it.

Differential Revision: https://reviews.llvm.org/D90983
2020-11-09 19:12:38 +00:00
Fangrui Song e625f9c5d1 -fbasic-block-sections=list=: Suppress output if failed to open the file
Reviewed By: tmsriram

Differential Revision: https://reviews.llvm.org/D90815
2020-11-09 09:26:37 -08:00
Atmn Patel fd3cad7a60 [clang] Fix ForStmt mustprogress handling
D86841 had an error where for statements with no conditional were
required to make progress. This is not true, this patch removes that
line, and adds regression tests.

Differential Revision: https://reviews.llvm.org/D91075
2020-11-09 11:38:06 -05:00
Tyker d093401a26 [NFC] Remove string parameter of annotation attribute from AST childs.
this simplifies using annotation attributes when using clang as library
2020-11-09 16:39:59 +01:00
Krasimir Georgiev 7b7170fa57 [clang-format] avoid introducing multiline comments
In C++ with -Werror=comment, multiline comments are not allowed.
clang-format could accidentally introduce multiline comments when reflowing.
This adapts clang-format to not introduce multiline comments by not allowing a
break after `\`. Note that this does not apply to comment lines that already are
multiline comments, such as comments in macros.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D90949
2020-11-09 15:29:09 +01:00
Lucas Prates c2c2cc1360 [ARM][AArch64] Adding Neoverse V1 CPU support
Add support for the Neoverse V1 CPU to the ARM and AArch64 backends.

This is based on patches from Mark Murray and Victor Campos.

Reviewed By: dmgreen

Differential Revision: https://reviews.llvm.org/D90765
2020-11-09 13:15:40 +00:00
Hubert Tong 09fc7796e5 [NFC][tests] Replace use of GNUisms in usage of diff
... the POSIX options suffice.

This maintains compatibility with the system `diff` on platforms
like AIX.
2020-11-08 12:07:51 -05:00
Simon Pilgrim 8930032f53 Don't dereference a dyn_cast<> result - use cast<> instead. NFCI.
We were relying on the dyn_cast<> succeeding - better use cast<> and have it assert that its the correct type than dereference a null result.
2020-11-08 13:06:07 +00:00
Arthur Eubanks 226e179f74 Revert "[NewPM] Provide method to run all pipeline callbacks, used for -O0"
This reverts commit ae38540042.
As well as some follow-up test fixes.

The original change causes new-pass-manager.ll to fail when polly is enabled.
2020-11-08 00:32:35 -08:00
Stephen Kelly 4eb880439a Fix dumping of explicit template specializations
This was missing from commit 7efe07a1 (Traverse-ignore explicit template
instantiations, 2020-11-06).
2020-11-07 22:34:16 +00:00
Melanie Blower c511963d5a [clang] Fix length threshold for MicrosoftMangle md5 hash
Reviewers: rnk, dblaikie

Differential Revision: https://reviews.llvm.org/D90714
2020-11-07 07:40:24 -08:00
Melanie Blower b0de3f6787 [clang] Improve Microsoft mangling lit test with dblaikie's suggestions 2020-11-07 07:32:34 -08:00
Fangrui Song d2da05de7c [test] Fix Other/new-pass-manager.ll & clang/test/Misc/loop-opt-setup.c 2020-11-06 21:55:11 -08:00
Atmn Patel d3e75d31e3 Revert "[CodeGen] Fixes sanitizer test"
This reverts commit b1878b4641. This does
fix the test but it means that ac73b73c16 is not implemented
correctly. Reverting for now, and will be reverting the commit that
causes this to fail.
2020-11-07 00:32:12 -05:00
Atmn Patel b1878b4641 [CodeGen] Fixes sanitizer test
By turning the loop into an infinite one, the loop can't be deleted
anymore so the test will continue to pass.
2020-11-06 23:53:38 -05:00
Fangrui Song f2e479db92 [OpenMP] Fix -Wmisleading-indentation after D84192 2020-11-06 20:09:43 -08:00
Atmn Patel 569abb530e [LoopDeletion] Fixes failing test
The commit 0b17c6e447 occasionally causes this test to
fail, this fixes it.
2020-11-06 22:45:28 -05:00
Atmn Patel 0b17c6e447 [LoopDeletion] Allows deletion of possibly infinite side-effect free loops
From C11 and C++11 onwards, a forward-progress requirement has been
introduced for both languages. In the case of C, loops with non-constant
conditionals that do not have any observable side-effects (as defined by
6.8.5p6) can be assumed by the implementation to terminate, and in the
case of C++, this assumption extends to all functions. The clang
frontend will emit the `mustprogress` function attribute for C++
functions (D86233, D85393, D86841) and emit the loop metadata
`llvm.loop.mustprogress` for every loop in C11 or later that has a
non-constant conditional.

This patch modifies LoopDeletion so that only loops with
the `llvm.loop.mustprogress` metadata or loops contained in functions
that are required to make progress (`mustprogress` or `willreturn`) are
checked for observable side-effects. If these loops do not have an
observable side-effect, then we delete them.

Loops without observable side-effects that do not satisfy the above
conditions will not be deleted.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D86844
2020-11-06 22:06:58 -05:00
cchen 0cab91140f [OpenMP5.0] map item can be non-contiguous for target update
In order not to modify the `tgt_target_data_update` information but still be
able to pass the extra information for non-contiguous map item (offset,
count, and stride for each dimension), this patch overload `arg` when
the maptype is set as `OMP_MAP_DESCRIPTOR`. The origin `arg` is for
passing the pointer information, however, the overloaded `arg` is an
array of descriptor_dim:

struct descriptor_dim {
  int64_t offset;
  int64_t count;
  int64_t stride
};

and the array size is the same as dimension size. In addition, since we
have count and stride information in descriptor_dim, we can replace/overload the
`arg_size` parameter by using dimension size.

For supporting `stride` in array section, we use a dummy dimension in
descriptor to store the unit size. The formula for counting the stride
in dimension D_n: `unit size * (D_0 * D_1 ... * D_n-1) * D_n.stride`.

Demonstrate how it works:
```
double arr[3][4][5];

D0: { offset = 0, count = 1, stride = 8 }                                // offset, count, dimension size always be 0, 1, 1 for this extra dimension, stride is the unit size
D1: { offset = 0, count = 2, stride = 8 * 1 * 2 = 16 }                   // stride = unit size * (product of dimension size of D0) * D1.stride = 4 * 1 * 2 = 8
D2: { offset = 2, count = 2, stride = 8 * (1 * 5) * 1 = 40  }            // stride = unit size * (product of dimension size of D0, D1) * D2.stride = 4 * 5 * 1 = 20
D3: { offset = 0, count = 2, stride = 8 * (1 * 5 * 4) * 2 = 320 }        // stride = unit size * (product of dimension size of D0, D1, D2) * D3.stride = 4 * 25 * 2 = 200

// X here means we need to offload this data, therefore, runtime will transfer
// data from offset 80, 96, 120, 136, 400, 416, 440, 456
// Runtime patch: https://reviews.llvm.org/D82245
// OOOOO OOOOO OOOOO
// OOOOO OOOOO OOOOO
// XOXOO OOOOO XOXOO
// XOXOO OOOOO XOXOO
```

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D84192
2020-11-06 21:04:37 -06:00
Elvina Yakubova c9ca3a3c66 [AArch64] Add driver tests for HiSilicon's TSV110 2020-11-07 01:51:37 +03:00
Stephen Kelly 0d6e1251d7 Add new matchers for dependent names in templates
Differential Revision: https://reviews.llvm.org/D90767
2020-11-06 21:03:20 +00:00
Kevin P. Neal 2069403cdf [FPEnv] Use strictfp metadata in casting nodes
The strictfp metadata was added to the casting AST nodes in D85960, but
we aren't using that metadata yet. This patch adds that support.

In order to avoid lots of ad-hoc passing around of the strictfp bits I
updated the IRBuilder when moving from a function that has the Expr* to a
function that lacks it. I believe we should switch to this pattern to keep
the strictfp support from being overly invasive.

For the purpose of testing that we're picking up the right metadata, I
also made my tests use a pragma to make the AST's strictfp metadata not
match the global strictfp metadata. This exposes issues that we need to
deal with in subsequent patches, and I believe this is the right method
for most all of our clang strictfp tests.

Differential Revision: https://reviews.llvm.org/D88913
2020-11-06 11:56:12 -05:00
Balazs Benics aa0dc1c3b8 [analyzer][NFCi] Mark CallEvent::getOriginExpr virtual, some cleanup
Previously we just shadowed the original implementation with a virtual
declaration - which is really bugprone in a long run.

This patch marks `CallEvent::getOriginExpr` virtual to let subclasses
override it's behavior.
At the same time, I checked all virtual functions of this class hierarchy
to make sure we don't suffer from this elsewhere.
Removes redundant declarations of `virtual` if `override` is already present.

In theory, this patch is a functional change, but no tests were broken.
I suspect that there were no meaningful changes in behavior in the
subclasses compared to the shadowed `CallEvent::getOriginExpr`.

That being said, I had a hard time coming up with unit-tests covering this.
Motivation: https://reviews.llvm.org/D74735#2370909

Reviewed By: NoQ

Differential Revision: https://reviews.llvm.org/D90754
2020-11-06 16:51:34 +01:00
Stephen Kelly 7efe07a12b Traverse-ignore explicit template instantiations
Continue to dump and match on explicit template specializations, but
omit explicit instantiation declarations and definitions.

Differential Revision: https://reviews.llvm.org/D90763
2020-11-06 15:25:59 +00:00
David Spickett aecd52b97b [Clang][AArch64] Remove unused prefix in constrained rounding test
This test was added in 7f38812d5b
and all the other tests make use of the COMMONIR check. So I think
this was left in by mistake for this particular test.

Reviewed By: kpn

Differential Revision: https://reviews.llvm.org/D90921
2020-11-06 14:13:46 +00:00
Krasimir Georgiev 2dbcbd357d [clang-format] do not break before { in JS comments
In JavaScript some @tags can be followed by `{`, and machinery that parses
these comments will fail to understand the comment if followed by a line break.

clang-format already handles this case by not breaking before `{` in comments.
However this was not working in cases when the column limit falls within `@tag`
or between `@tag` and `{`. This adapts clang-format for this case.

Reviewed By: mprobst

Differential Revision: https://reviews.llvm.org/D90908
2020-11-06 10:34:10 +01:00
Freddy Ye 5e312e0041 [X86] use macros to split GFNI intrinsics into different kinds
Tremont microarchitecture only has GFNI(SSE) version, not AVX and
AVX512 version. This patch is to avoid compiling fail on Windows when
using -march=tremont to invoke one of GFNI(SSE) intrinsic.

Differential Revision: https://reviews.llvm.org/D90822
2020-11-06 16:03:38 +08:00
Fangrui Song 247c5b5d69 [test] Properly test -Werror-implicit-function-declaration and -Wvec-elem-size
Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D90874
2020-11-05 20:08:23 -08:00
Stella Stamenova c67656b994 Revert "Allow searching for prebuilt implicit modules."
This reverts commit 71e108cd86.

This change caused a build failure on Windows:
http://lab.llvm.org:8011/#/builders/83/builds/570
2020-11-05 17:16:14 -08:00
Stanislav Mekhanoshin 4fcdfc4398 [AMDGPU] Simplify amdgpu-macros.cl test. NFC.
Differential Revision: https://reviews.llvm.org/D90886
2020-11-05 16:29:16 -08:00
Michael Liao 23c6d1501d [amdgpu] Add `llvm.amdgcn.endpgm` support.
- `llvm.amdgcn.endpgm` is added to enable "abort" support.

Differential Revision: https://reviews.llvm.org/D90809
2020-11-05 19:06:50 -05:00
Saleem Abdulrasool e55157874c APINotes: repair the Windows builders
Disable the test on Windows, which should've been obvious as being
needed.  The differences in diff implementations and line-endings make
this test difficult to execute on Windows.
2020-11-05 21:25:52 +00:00
Alexandre Rames 71e108cd86 Allow searching for prebuilt implicit modules.
The behavior is controlled by the `-fprebuilt-implicit-modules` option, and
allows searching for implicit modules in the prebuilt module cache paths.

The current command-line options for prebuilt modules do not allow to easily
maintain and use multiple versions of modules. Both the producer and users of
prebuilt modules are required to know the relationships between compilation
options and module file paths. Using a particular version of a prebuilt module
requires passing a particular option on the command line (e.g.
`-fmodule-file=[<name>=]<file>` or `-fprebuilt-module-path=<directory>`).

However the compiler already knows how to distinguish and automatically locate
implicit modules. Hence this proposal to introduce the
`-fprebuilt-implicit-modules` option. When set, it enables searching for
implicit modules in the prebuilt module paths (specified via
`-fprebuilt-module-path`). To not modify existing behavior, this search takes
place after the standard search for prebuilt modules. If not

Here is a workflow illustrating how both the producer and consumer of prebuilt
modules would need to know what versions of prebuilt modules are available and
where they are located.

  clang -cc1 -x c modulemap -fmodules -emit-module -fmodule-name=foo -fmodules-cache-path=prebuilt_modules_v1 <config 1 options>
  clang -cc1 -x c modulemap -fmodules -emit-module -fmodule-name=foo -fmodules-cache-path=prebuilt_modules_v2 <config 2 options>
  clang -cc1 -x c modulemap -fmodules -emit-module -fmodule-name=foo -fmodules-cache-path=prebuilt_modules_v3 <config 3 options>

  clang -cc1 -x c use.c -fmodules fmodule-map-file=modulemap -fprebuilt-module-path=prebuilt_modules_v1 <config 1 options>
  clang -cc1 -x c use.c -fmodules fmodule-map-file=modulemap <non-prebuilt config options>

With prebuilt implicit modules, the producer can generate prebuilt modules as
usual, all in the same output directory. The same mechanisms as for implicit
modules take care of incorporating hashes in the path to distinguish between
module versions.

Note that we do not specify the output module filename, so `-o` implicit modules are generated in the cache path `prebuilt_modules`.

  clang -cc1 -x c modulemap -fmodules -emit-module -fmodule-name=foo -fmodules-cache-path=prebuilt_modules <config 1 options>
  clang -cc1 -x c modulemap -fmodules -emit-module -fmodule-name=foo -fmodules-cache-path=prebuilt_modules <config 2 options>
  clang -cc1 -x c modulemap -fmodules -emit-module -fmodule-name=foo -fmodules-cache-path=prebuilt_modules <config 3 options>

The user can now simply enable prebuilt implicit modules and point to the
prebuilt modules cache. No need to "parse" command-line options to decide
what prebuilt modules (paths) to use.

  clang -cc1 -x c use.c -fmodules fmodule-map-file=modulemap -fprebuilt-module-path=prebuilt_modules -fprebuilt-implicit-modules <config 1 options>
  clang -cc1 -x c use.c -fmodules fmodule-map-file=modulemap -fprebuilt-module-path=prebuilt_modules -fprebuilt-implicit-modules <non-prebuilt config options>

This is for example particularly useful in a use-case where compilation is
expensive, and the configurations expected to be used are predictable, but not
controlled by the producer of prebuilt modules. Modules for the set of
predictable configurations can be prebuilt, and using them does not require
"parsing" the configuration (command-line options).

Reviewed By: Bigcheese

Differential Revision: https://reviews.llvm.org/D68997
2020-11-05 13:10:53 -08:00
Jan Ole Hüser d2e7dca5ca [CodeGen] Fix Bug 47499: __unaligned extension inconsistent behaviour with C and C++
For the language C++ the keyword __unaligned (a Microsoft extension) had no effect on pointers.

The reason, why there was a difference between C and C++ for the keyword __unaligned:
For C, the Method getAsCXXREcordDecl() returns nullptr. That guarantees that hasUnaligned() is called.
If the language is C++, it is not guaranteed, that hasUnaligend() is called and evaluated.

Here are some links:

The Bug: https://bugs.llvm.org/show_bug.cgi?id=47499
Thread on the cfe-dev mailing list: http://lists.llvm.org/pipermail/cfe-dev/2020-September/066783.html
Diff, that introduced the check hasUnaligned() in getNaturalTypeAlignment(): https://reviews.llvm.org/D30166

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D90630
2020-11-05 12:57:17 -08:00
Albion Fung 1af037f643 [PowerPC] Correct cpsgn's behaviour on PowerPC to match that of the ABI
This patch fixes the reversed behaviour exhibited by cpsgn on PPC. It now matches the ABI.

Differential Revision: https://reviews.llvm.org/D84962
2020-11-05 15:35:14 -05:00
Nico Weber b69af88481 [gn build] (manually) port 82f86ae01 2020-11-05 14:11:26 -05:00
Saleem Abdulrasool 82f86ae01a APINotes: add APINotesYAMLCompiler
This adds the skeleton of the YAML Compiler for APINotes.  This change
only adds the YAML IO model for the API Notes along with a new testing
tool `apinotes-test` which can be used to verify that can round trip the
YAML content properly.  It provides the basis for the future work which
will add a binary serialization and deserialization format to the data
model.

This is based on the code contributed by Apple at
https://github.com/llvm/llvm-project-staging/tree/staging/swift/apinotes.

Differential Revision: https://reviews.llvm.org/D88859
Reviewed By: Gabor Marton
2020-11-05 18:55:13 +00:00
Fangrui Song c6a384df1f [Sema] Special case -Werror-implicit-function-declaration and reject other -Werror-
This is the only -Werror- form warning option GCC supports (gcc/c-family/c.opt).
Fortunately no other form is used anywhere.
2020-11-05 10:25:30 -08:00
Erich Keane 6b104ea4b4 Implement Lambda Conversion Operators for All CCs for MSVC.
As described here:
https://devblogs.microsoft.com/oldnewthing/20150220-00/?p=44623

In order to allow Lambdas to be used with traditional Win32 APIs, they
emit a conversion function for (what Raymond Chen claims is all) a
number of the calling conventions.  Through experimentation, we
discovered that the list isn't quite 'all'.

This patch implements this by taking the list of conversions that MSVC
emits (across 'all' architectures, I don't see any CCs on ARM), then
emits them if they are supported by the current target.

However, we also add 3 other options (which may be duplicates):
free-function, member-function, and operator() calling conventions.  We
do this because we have an extension where we generate both free and
member for these cases so th at people specifying a calling convention
on the lambda will have the expected behavior when specifying one of
those two.

MSVC doesn't seem to permit specifying calling-convention on lambdas,
but we do, so we need to make sure those are emitted as well. We do this
so that clang-only conventions are supported if the user specifies them.

Differential Revision: https://reviews.llvm.org/D90634
2020-11-05 07:25:44 -08:00
Raphael Isemann 659f4bd87e [clang] Add an option for hiding line numbers in diagnostics
Clang offers a `-f[no]-show-column` flag for hiding the column numbers when
printing diagnostics but there is no option for doing the same with line
numbers.

In LLDB having this option would be useful, as LLDB sometimes only knows the
file name for a SourceLocation and just assigns it the dummy line/column `1:1`.
These fake line/column numbers are confusing to the user and LLDB should be able
to tell clang to hide *both* the column and the line number when rendering text
diagnostics.

This patch adds a flag for also hiding the line numbers. It's not exposed via
the command line flags as it's most likely not very useful for any user and can
lead to ambiguous output when the user decides to only hide either the line or
the column number (where `file:1: ...` could now refer to both line 1 or column
1 depending on the compiler flags). LLDB can just access the DiagnosticOptions
directly when constructing its internal Clang instance.

The effect doesn't apply to Vi/MSVC style diagnostics because it's not defined
how these diagnostic styles would show an omitted line number (MSVC doesn't have
such an option and Vi's line mode is theory only supporting line numbers if I
understand it correctly).

Reviewed By: thakis, MaskRay

Differential Revision: https://reviews.llvm.org/D83038
2020-11-05 16:10:18 +01:00
Sven van Haastregt 8ac9bcc746 [OpenCL] Support vec_step in C++ for OpenCL mode
Enable the vec_step builtin in C++ for OpenCL mode for compatibility
with OpenCL C.

Differential Revision: https://reviews.llvm.org/D90766
2020-11-05 12:02:59 +00:00
Eduardo Caldas 23657d9cc3 [SyntaxTree] Add reverse links to syntax Nodes.
Rationale:
Children of a syntax tree had forward links only, because there was no
need for reverse links.

This need appeared when we started mutating the syntax tree.
On a forward list, to remove a target node in O(1) we need a pointer to the node before the target. If we don't have this "before" pointer, we have to find it, and that requires O(n).
So in order to remove a syntax node from a tree, we would similarly need to find the node before to then remove. This is both not ergonomic nor does it have a good complexity.

Differential Revision: https://reviews.llvm.org/D90240
2020-11-05 09:33:53 +00:00
Arthur Eubanks 5fd3193c88 [test] Add 'REQUIRES: bpf-registered-target' to bpf-O0.c 2020-11-04 23:19:14 -08:00
Arthur Eubanks ae38540042 [NewPM] Provide method to run all pipeline callbacks, used for -O0
Some targets may add required passes via
    TargetMachine::registerPassBuilderCallbacks(). We need to run those even
    under -O0. As an example, BPFTargetMachine adds
    BPFAbstractMemberAccessPass, a required pass.

    This also allows us to clean up BackendUtil.cpp (and out-of-tree Rust
    usage of the NPM) by allowing us to share added passes like coroutines
    and sanitizers between -O0 and other optimization levels.

    Tests are a continuation of those added in
    https://reviews.llvm.org/D89083.

    In order to prevent TargetMachines from adding unnecessary optimization
    passes at -O0, TargetMachine::registerPassBuilderCallbacks() will be
    changed to take an OptimizationLevel, but that will be done separately.

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D89158
2020-11-04 22:27:16 -08:00
Serge Pavlov 20b4f4f760 [Driver] Add callback to Command execution
Summary:
Object of type `Compilation` now can keep a callback that is called
after each execution of `Command`. This must simplify adaptation of
clang in custom distributions and allow facilities like collection of
execution statistics.

Reviewers: rsmith, rjmccall, Eugene.Zelenko

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D78899
2020-11-05 12:21:40 +07:00
Atmn Patel ac73b73c16 [clang] Add mustprogress and llvm.loop.mustprogress attribute deduction
Since C++11, the C++ standard has a forward progress guarantee
[intro.progress], so all such functions must have the `mustprogress`
requirement. In addition, from C11 and onwards, loops without a non-zero
constant conditional or no conditional are also required to make
progress (C11 6.8.5p6). This patch implements these attribute deductions
so they can be used by the optimization passes.

Differential Revision: https://reviews.llvm.org/D86841
2020-11-04 22:03:14 -05:00
Baptiste Saleil f976ba6139 [PowerPC] Add Sema checks for MMA types
The use of the new types introduced for PowerPC MMA instructions needs to be restricted.
We add a PowerPC function checking that the given type is valid in a context in which we don't allow MMA types.
This function is called from various places in Sema where we want to prevent the use of these types.

Differential Revision: https://reviews.llvm.org/D82035
2020-11-04 17:01:47 -06:00
Duncan P. N. Exon Smith 6e73cfa836 Basic: Change Module::Umbrella to a PointerUnion, NFC
Change `Module::Umbrella` from a `const void *` to a `PointerUnion` of
`FileEntry` and `DirectoryEntry`. We can drop the `HasUmbrellaDir` bit
(since `PointerUnion` includes that).

This change makes it safer to update to `FileEntryRef` and
`DirectoryEntryRef` in a future patch.

Differential Revision: https://reviews.llvm.org/D90481
2020-11-04 16:19:39 -05:00
Arthur Eubanks ab0ddbc38a Reland [NewPM] Add OptimizationLevel param to registerPipelineStartEPCallback
This allows targets to skip optional optimization passes at -O0.

Reviewed By: ychen

Differential Revision: https://reviews.llvm.org/D90777
2020-11-04 13:11:40 -08:00
Duncan P. N. Exon Smith 77a9e0a4af Basic: Split out DirectoryEntry.h, NFC
Move `DirectoryEntry` and `DirectoryEntryRef` into their own header,
similar to the creation of FileEntry.h. No functionality change here,
just preparing to include it in more places to allow wider adoption of
`DirectoryEntryRef` without requiring all of `FileManager.h`.

Differential Revision: https://reviews.llvm.org/D90478
2020-11-04 14:11:57 -05:00
cchen d0d43b58b1 [OpenMP] target nested `use_device_ptr() if()` and is_device_ptr trigger asserts
Clang now asserts for the below case:
```
void clang::CodeGen::CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata(): Assertion `std::get<0>(E) && "All ordered entries must exist!"' failed.
```

The reason why Clang hit the assert is because in
`emitTargetDataCalls`, both `BeginThenGen` and `BeginElseGen` call
`registerTargetRegionEntryInfo` and try to register the Entry in
OffloadEntriesTargetRegion with same key. If changing the expression in
if clause to any constant expression, then the assert disappear. (https://godbolt.org/z/TW7haj)

The assert itself is to avoid
user from accessing elements out of bound inside `OrderedEntries` in
`createOffloadEntriesAndInfoMetadata`.

In this patch, I add a check in `registerTargetRegionEntryInfo` to avoid
register the target region more than once.

A test case that triggers assert: https://godbolt.org/z/4cnGW8

Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D90704
2020-11-04 12:36:57 -06:00
etiotto 7e2edf973b [compiler-rt][AIX]: Link compiler-rt profile library when -fprofile-generate is specified
This patch enhances the clang driver to link the runtime profile
library on AIX when the -fprofile-generate option is used.

Reviewed By: phosek

Differentail Revision: https://reviews.llvm.org/D90641
2020-11-04 09:54:54 -05:00
Qiu Chaofan 7faf62a80b [Clang] Add more fp128 math library function builtins
Since glibc has supported math library functions conforming IEEE 128-bit
floating point types on some platform (like ppc64le), we can fix clang's
math builtins missing this type.

Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D90593
2020-11-04 17:58:42 +08:00
Richard Smith 09b54e2799 When re-checking an already-substituted template argument, don't lose
the reference-ness of the parameter's type.
2020-11-03 14:09:54 -08:00
Matt Morehouse a6d15d4070 Undo Revert "Ignore template instantiations if not in AsIs mode"
MaskRay already fixed the ASan bug.
2020-11-03 13:59:01 -08:00
Matt Morehouse 72531ae6e6 Revert "Ignore template instantiations if not in AsIs mode"
This reverts commit 53df3beb62 due to
check-asan failure on the buildbot.
2020-11-03 13:57:31 -08:00
Baptiste Saleil daa127d77e [PowerPC] Add MMA builtin decoding and definitions
Add MMA builtin decoding. These builtins use the new PowerPC-specific types __vector_pair and __vector_quad.
So to avoid pervasive changes, we use custom type descriptors and custom decoding for these builtins.
We also use custom code generation to expand builtin calls with pointers to simpler intrinsic calls with non-pointer types.

Differential Revision: https://reviews.llvm.org/D81748
2020-11-03 15:08:46 -06:00
Fangrui Song 96ed6793b3 [unittest][TrasnformerTest] Fix asan stack-use-after-return 2020-11-03 12:34:45 -08:00
Ben Dunbobbin 7ad6010f58 Fix - [Clang] Add the ability to map DLL storage class to visibility
415f7ee883 had a silly typo introduced when I inlined some
code into a loop from its own function.

Original commit message:

For PlayStation we offer source code compatibility with
Microsoft's dllimport/export annotations; however, our file
format is based on ELF.

To support this we translate from DLL storage class to ELF
visibility at the end of codegen in Clang.

Other toolchains have used similar strategies (e.g. see the
documentation for this ARM toolchain:

https://developer.arm.com/documentation/dui0530/i/migrating-from-rvct-v3-1-to-rvct-v4-0/changes-to-symbol-visibility-between-rvct-v3-1-and-rvct-v4-0)

This patch adds the ability to perform this translation. Options
are provided to support customizing the mapping behaviour.

Differential Revision: https://reviews.llvm.org/D89970
2020-11-03 19:13:54 +00:00
Aaron En Ye Shi ca5b31502c [HIP] Math Headers to use type promotion
Similar to libcxx implementation of cmath function
overloads, use type promotion templates to determine
return types of multi-argument math functions.

Fixes: SWDEV-256825

Reviewed By: tra, yaxunl

Differential Revision: https://reviews.llvm.org/D90409
2020-11-03 18:40:26 +00:00
Artem Belevich cdbf6bfdc7 [HIP] Use argv[0] as the default choice for the Executable name.
The path produced by getMainExecutable() may not be the right one when the files are installed in
a symlinked tree and when the real location of llvm-objdump is in a different directory.

Given that clang-offload-bundler is invoked by clang, the driver already does the job figuring out
the right path (e.g. it pays attention to -no-canonical-prefixes).
Offload bundler should use it, instead of trying to figure out the path on its
own.

Differential Revision: https://reviews.llvm.org/D90436
2020-11-03 10:31:39 -08:00
Artem Belevich be86b6773b [CUDA] Allow local static variables with target attributes.
While CUDA documentation claims that such variables are not allowed[1], NVCC has
been accepting them since CUDA-10.0[2] and some headers in CUDA-11 rely on this
working.

1. https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#static-variables-function
2. https://godbolt.org/z/zsodzc

Differential Revision: https://reviews.llvm.org/D88345
2020-11-03 10:30:38 -08:00
Tim Renouf 89d41f3a2b [AMDGPU] Add gfx1033 target
Differential Revision: https://reviews.llvm.org/D90447

Change-Id: If2650fc7f31bbdd49c76e74a9ca8e3734d769761
2020-11-03 16:27:48 +00:00
Tim Renouf ee3e642627 [AMDGPU] Add gfx90c target
This differentiates the Ryzen 4000/4300/4500/4700 series APUs that were
previously included in gfx909.

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

Change-Id: Ia901a7157eb2f73ccd9f25dbacec38427312377d
2020-11-03 16:27:43 +00:00
Nathan James b091af790f
[ASTMatchers] Made isExpandedFromMacro Polymorphic
Made the isExpandedFromMacro matcher work on Stmt's, TypeLocs and Decls in line with the other macro expansion matchers.
Also tweaked it to take a `std::string` instead of a `StringRef`.
This prevents potential use-after-free bugs if the matcher is created with a string thats destroyed before the matcher finishes matching.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D90303
2020-11-03 14:36:51 +00:00
Yaxun (Sam) Liu abd8cd9199 [CUDA][HIP] Fix linkage for -fgpu-rdc
Currently for explicit template function instantiation in CUDA/HIP device
compilation clang emits instantiated kernel with external linkage
and instantiated device function with internal linkage.

This is fine for -fno-gpu-rdc since there is only one TU.

However this causes duplicate symbols for kernels for -fgpu-rdc if
the same instantiation happen in multiple TU. Or missing symbols
if a device function calls an explicitly instantiated template function
in a different TU.

To make explicit template function instantiation work for
-fgpu-rdc we need to follow the C++ linkage paradigm, i.e.
use weak_odr linkage.

Differential Revision: https://reviews.llvm.org/D90311
2020-11-03 08:07:19 -05:00
Stephen Kelly ff02ae2139 Add test missing from previous commit 2020-11-03 11:06:52 +00:00
Martin Storsjö d3bd06f5c7 [clang] Fix the fsanitize.c testcase after eaae6fdf67. NFC.
After that commit, the vptr sanitizer is enabled for mingw targets.
2020-11-03 10:21:29 +02:00
Martin Storsjö eaae6fdf67 [clang] [MinGW] Allow using the vptr sanitizer
Differential Revision: https://reviews.llvm.org/D90572
2020-11-03 09:59:09 +02:00
Stephan Bergmann 7a5184ed95 [scan-build] Fix clang++ pathname again
e00629f777 "[scan-build] Fix clang++ pathname" had
removed the -MAJOR.MINOR suffix, but since presumably LLVM 7 the suffix is only
-MAJOR, so ClangCXX (i.e., the CLANG_CXX environment variable passed to
clang/tools/scan-build/libexec/ccc-analyzer) now contained a non-existing
/path/to/clang-12++ (which apparently went largely unnoticed as
clang/tools/scan-build/libexec/ccc-analyzer falls back to just 'clang++' if the
executable denoted by CLANG_CXX does not exist).

For the new clang/test/Analysis/scan-build/cxx-name.test to be effective,
%scan-build must now take care to pass the clang executable's resolved pathname
(i.e., ending in .../clang-MAJOR rather than just .../clang) to --use-analyzer.

Differential Revision: https://reviews.llvm.org/D89481
2020-11-03 08:17:17 +01:00
Serge Pavlov ee63acc37e Put back the test pragma-fp-exc.cpp
This test was removed in 5963e028e7 because it failed on cores where
support of constrained intrinsics was limited. Now this test is enabled
only on x86.
2020-11-03 13:18:40 +07:00
Fangrui Song 0d4e1729e3 [docs] Fix clang/docs/UsersManual.rst after D87528 & D88446 2020-11-02 21:07:15 -08:00
Sam McCall dd6f7ee05e [Syntax] DeclaratorList is a List
I think this was just an oversight.

Differential Revision: https://reviews.llvm.org/D90541
2020-11-03 03:29:06 +01:00
Fangrui Song 8a626f1cc4 Add textual header PPCTypes.def to module Clang_Basic after D81508 2020-11-02 18:23:26 -08:00
Alex Lorenz 701456b523 [darwin] add support for __isPlatformVersionAtLeast check for if (@available)
The __isPlatformVersionAtLeast routine is an implementation of `if (@available)` check
that uses the _availability_version_check API on Darwin that's supported on
macOS 10.15, iOS 13, tvOS 13 and watchOS 6.

Differential Revision: https://reviews.llvm.org/D90367
2020-11-02 16:28:09 -08:00
Fangrui Song bc847b3143 [cc1as] Close MCAsmParser before MCStreamer
This is a pre-existing problem exposed by D90511 (asan failurs with
clang/test/Driver/relax.s and a few other tests).
2020-11-02 15:56:57 -08:00
Ben Dunbobbin ae9231ca2a Reland - [Clang] Add the ability to map DLL storage class to visibility
415f7ee883 had LIT test failures on any build where the clang executable
was not called "clang". I have adjusted the LIT CHECKs to remove the
binary name to fix this.

Original commit message:

For PlayStation we offer source code compatibility with
Microsoft's dllimport/export annotations; however, our file
format is based on ELF.

To support this we translate from DLL storage class to ELF
visibility at the end of codegen in Clang.

Other toolchains have used similar strategies (e.g. see the
documentation for this ARM toolchain:

https://developer.arm.com/documentation/dui0530/i/migrating-from-rvct-v3-1-to-rvct-v4-0/changes-to-symbol-visibility-between-rvct-v3-1-and-rvct-v4-0)

This patch adds the ability to perform this translation. Options
are provided to support customizing the mapping behaviour.

Differential Revision: https://reviews.llvm.org/D89970
2020-11-02 23:24:49 +00:00
Artem Belevich 0a3ebb4d8d Revert "[CUDA] Allow local static variables with target attributes."
This reverts commit f38a9e5117
Which triggered assertions.
2020-11-02 15:09:07 -08:00
Artem Belevich f38a9e5117 [CUDA] Allow local static variables with target attributes.
While CUDA documentation claims that such variables are not allowed[1], NVCC has
been accepting them since CUDA-10.0[2] and some headers in CUDA-11 rely on this
working.

1. https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#static-variables-function
2. https://godbolt.org/z/zsodzc

Differential Revision: https://reviews.llvm.org/D88345
2020-11-02 14:37:13 -08:00
Duncan P. N. Exon Smith 5cb8d93205 Fix build error on bots after 9f151df178
Attempt to fix build error on bots not seen locally.
2020-11-02 15:55:13 -05:00
Stephen Kelly 53df3beb62 Ignore template instantiations if not in AsIs mode
Summary:
IgnoreUnlessSpelledInSource mode should ignore these because they are
not written in the source.  This matters for example when trying to
replace types or values which are templated.  The new test in
TransformerTest.cpp in this commit demonstrates the problem.

In existing matcher code, users can write
`unless(isInTemplateInstantiation())` or `unless(isInstantiated())` (the
user must know which to use).  The point of the
TK_IgnoreUnlessSpelledInSource mode is to allow the novice to avoid such
details.  This patch changes the IgnoreUnlessSpelledInSource mode to
skip over implicit template instantiations.

This patch does not change the TK_AsIs mode.

Note: An obvious attempt at an alternative implementation would simply
change the shouldVisitTemplateInstantiations() in ASTMatchFinder.cpp to
return something conditional on the operational TraversalKind.  That
does not work because shouldVisitTemplateInstantiations() is called
before a possible top-level traverse() matcher changes the operational
TraversalKind.

Reviewers: sammccall, aaron.ballman, gribozavr2, ymandel, klimek

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D80961
2020-11-02 20:21:48 +00:00
Stephen Kelly 537cc6dd2b Rename CXXUnresolvedConstructExpr::arg_size for consistency
Make it possible to use argumentCountIs and hasArgument with
CXXUnresolvedConstructExpr.

Differential Revision: https://reviews.llvm.org/D90553
2020-11-02 20:21:48 +00:00
Duncan P. N. Exon Smith 9f151df178 Change Module::ASTFile and ModuleFile::File => Optional<FileEntryRef>, NFC
Change `Module::ASTFile` and `ModuleFile::File` to use
`Optional<FileEntryRef>` instead of `const FileEntry *`. One of many
steps toward removing `FileEntry::getName`.

Differential Revision: https://reviews.llvm.org/D89836
2020-11-02 15:11:51 -05:00
Christopher Di Bella ba18bc4925 [Sema] adds -Wfree-nonheap-object member var checks
Checks to make sure that stdlib's (std::)free is being appropriately
used for member variables.

Differential Revision: https://reviews.llvm.org/D90269
2020-11-02 11:03:28 -08:00
Alex Richardson 906b9dbc9d [clang-format] Improve BAS_DontAlign+AllowAllArgumentsOnNextLine=false
TokenAnnotator::splitPenalty() was always returning 0 for opening parens if
AlignAfterOpenBracket was set to BAS_DontAlign, so the preferred point for
line breaking was always after the open paren (and was ignoring
PenaltyBreakBeforeFirstCallParameter). This change restricts the zero
penalty to the AllowAllArgumentsOnNextLine case. This results in improved
formatting for FreeBSD where we set AllowAllArgumentsOnNextLine: false
and a high value for PenaltyBreakBeforeFirstCallParameter to avoid breaking
after the open paren.

Before:
```
functionCall(
    paramA, paramB, paramC);
void functionDecl(
    int A, int B, int C)
```
After:
```
functionCall(paramA, paramB,
    paramC);
void functionDecl(int A, int B,
    int C)
```

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D90246
2020-11-02 17:52:37 +00:00
Aaron Ballman 2e2be3d964 Correct the nomerge attribute documentation
The nomerge attribute is a statement attribute not a function attribute.
2020-11-02 12:49:40 -05:00
Ben Dunbobbin 5024d3aa18 Revert "[Clang] Add the ability to map DLL storage class to visibility"
This reverts commit 415f7ee883.

The added tests were failing on the build bots!
2020-11-02 17:33:54 +00:00
Ben Dunbobbin 415f7ee883 [Clang] Add the ability to map DLL storage class to visibility
For PlayStation we offer source code compatibility with
Microsoft's dllimport/export annotations; however, our file
format is based on ELF.

To support this we translate from DLL storage class to ELF
visibility at the end of codegen in Clang.

Other toolchains have used similar strategies (e.g. see the
documentation for this ARM toolchain:

https://developer.arm.com/documentation/dui0530/i/migrating-from-rvct-v3-1-to-rvct-v4-0/changes-to-symbol-visibility-between-rvct-v3-1-and-rvct-v4-0)

This patch adds the ability to perform this translation. Options
are provided to support customizing the mapping behaviour.

Differential Revision: https://reviews.llvm.org/D89970
2020-11-02 17:08:23 +00:00
Shoaib Meenai 4e4ab8e015 [clang] Limit scope of CLANG_VENDOR definition
It's only used by Version.cpp, so limit the definition to just that one
file instead of making all of Clang recompile if you change CLANG_VENDOR.

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D90516
2020-11-02 09:04:43 -08:00
Kirstóf Umann 22e7182002 [analyzer][ReturnPtrRangeChecker] Fix a false positive on end() iterator
ReturnPtrRange checker emits a report if a function returns a pointer which
points out of the buffer. However, end() iterator of containers is always such
a pointer, so this always results a false positive report. This false positive
case is now eliminated.

This patch resolves these tickets:
https://bugs.llvm.org/show_bug.cgi?id=20929
https://bugs.llvm.org/show_bug.cgi?id=25226
https://bugs.llvm.org/show_bug.cgi?id=27701

Patch by Tibor Brunner!

Differential Revision: https://reviews.llvm.org/D83678
2020-11-02 16:41:17 +01:00
Ben Dunbobbin ff2e24a741 [PS4] Support dllimport/export attributes
For PS4 development we support dllimport/export annotations in
source code. This patch enables the dllimport/export attributes
on PS4 by adding a new function to query the triple for whether
dllimport/export are used and using that function to decide
whether these attributes are supported. This replaces the current
method of checking if the target is Windows.

This means we can drop the use of "TargetArch" in the .td file
(which is an improvement as dllimport/export support isn't really
a function of the architecture).

I have included a simple codgen test to show that the attributes
are accepted and have an effect on codegen for PS4. I have also
enabled the DLLExportStaticLocal and DLLImportStaticLocal
attributes, which we support downstream. However, I am unable to
write a test for these attributes until other patches for PS4
dllimport/export handling land upstream. Whilst writing this
patch I noticed that, as these attributes are internal, they do
not need to be target specific (when these attributes are added
internally in Clang the target specific checks have already been
run); however, I think leaving them target specific is fine
because it isn't harmful and they "really are" target specific
even if that has no functional impact.

Differential Revision: https://reviews.llvm.org/D90442
2020-11-02 14:25:34 +00:00
Caroline Concatto d28de0d7f2 [Flang][Driver] Add PrintPreprocessedInput FrontendAction (`flang-new -E`)
This patch implements the first frontend action for the Flang parser (i.e.
Fortran::parser). This action runs the preprocessor and is invoked with the
`-E` flag. (i.e. `flang-new -E <input-file>). The generated output is printed
to either stdout or the output file (specified with `-` or `-o <output-file>`).

Note that currently there is no mechanism to map options for the
frontend driver (i.e. Fortran::frontend::FrontendOptions) to options for
the parser (i.e. Fortran::parser::Options). Instead,
Frotran::parser::options are hard-coded to:

```
std::vector<std::string> searchDirectories{"."s};
searchDirectories = searchDirectories;
isFixedForm = false;
_encoding(Fortran::parser::Encoding::UTF_8);
```

These default settings are compatible with the current Flang driver. Further
work is required in order for CompilerInvocation to read and map
clang::driver::options to Fortran::parser::options.

Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>

Differential Revision: https://reviews.llvm.org/D88381
2020-11-02 14:03:35 +00:00
Teresa Johnson 95824be18f [MemProf] Fix test failure on windows
Fix failure in new test from 0949f96dc6521be80ebb8ebc1e1c506165c22aac:
Don't match exact file path separator.

Should fix:
http://lab.llvm.org:8011/#/builders/119/builds/437/steps/9/logs/FAIL__Clang__memory-profile-filename_c
2020-11-01 19:06:50 -08:00
Teresa Johnson 0949f96dc6 [MemProf] Pass down memory profile name with optional path from clang
Similar to -fprofile-generate=, add -fmemory-profile= which takes a
directory path. This is passed down to LLVM via a new module flag
metadata. LLVM in turn provides this name to the runtime via the new
__memprof_profile_filename variable.

Additionally, always pass a default filename (in $cwd if a directory
name is not specified vi the = form of the option). This is also
consistent with the behavior of the PGO instrumentation. Since the
memory profiles will generally be fairly large, it doesn't make sense to
dump them to stderr. Also, importantly, the memory profiles will
eventually be dumped in a compact binary format, which is another reason
why it does not make sense to send these to stderr by default.

Change the existing memprof tests to specify log_path=stderr when that
was being relied on.

Depends on D89086.

Differential Revision: https://reviews.llvm.org/D89087
2020-11-01 17:38:23 -08:00
Fangrui Song 96289ce633 [test] Fix unused check prefixes in test/AST 2020-10-31 21:46:45 -07:00
Fangrui Song 1a51bde1b6 [test] Clean up test/Frontend/gnu-mcount.c and fix unused check prefixes 2020-10-31 21:33:46 -07:00
Mark de Wever b231396122 [Sema] Diagnose annotating `if constexpr` with a likelihood attribute
Adds a diagnostic when the user annotates an `if constexpr` with a
likelihood attribute. The `if constexpr` statement is evaluated at compile
time so the attribute has no effect. Annotating the accompanied `else`
with a likelihood attribute has the same effect as annotating a generic
statement. Since the attribute there is most likely not intended, a
diagnostic will be issued. Since the attributes can't conflict, the
"conflict" won't be diagnosed for an `if constexpr`.

Differential Revision: https://reviews.llvm.org/D90336
2020-10-31 17:51:36 +01:00
Mark de Wever b46fddf75f [CodeGen] Implement [[likely]] and [[unlikely]] for while and for loop.
The attribute has no effect on a do statement since the path of execution
will always include its substatement.

It adds a diagnostic when the attribute is used on an infinite while loop
since the codegen omits the branch here. Since the likelihood attributes
have no effect on a do statement no diagnostic will be issued for
do [[unlikely]] {...} while(0);

Differential Revision: https://reviews.llvm.org/D89899
2020-10-31 17:51:29 +01:00
Serge Pavlov 5963e028e7 Temporarily remove test CodeGen/pragma-fp-exc
This test fails on buildbots where CPU architecture does not fully
support constrained intrinsics.
2020-10-31 19:48:44 +07:00
Serge Pavlov 6021cbea4d Add option 'exceptions' to pragma clang fp
Pragma 'clang fp' is extended to support a new option, 'exceptions'. It
allows to specify floating point exception behavior more flexibly.

Differential Revision: https://reviews.llvm.org/D89849
2020-10-31 17:36:12 +07:00
Arthur Eubanks 5c31b8b94f Revert "Use uint64_t for branch weights instead of uint32_t"
This reverts commit 10f2a0d662.

More uint64_t overflows.
2020-10-31 00:25:32 -07:00
Fangrui Song e2a1639c73 [test] Fix unused check prefixes in test/Driver
Note, the deprecated AArch64 -msign-return-address= does not accept b-key. So
delete the incorrect tests.
2020-10-31 00:14:59 -07:00
Liu, Chen3 756f597841 [X86] Support Intel avxvnni
This patch mainly made the following changes:

1. Support AVX-VNNI instructions;
2. Introduce ExplicitVEXPrefix flag so that vpdpbusd/vpdpbusds/vpdpbusds/vpdpbusds instructions only use vex-encoding when user explicity add {vex} prefix.

Differential Revision: https://reviews.llvm.org/D89105
2020-10-31 12:39:51 +08:00
Richard Smith dd8297b066 PR42513: Fix handling of function definitions lazily instantiated from
friends.

When determining whether a function has a template instantiation
pattern, look for other declarations of that function that were
instantiated from a friend function definition, rather than assuming
that checking for member specialization information on whichever
declaration name lookup found will be sufficient.
2020-10-30 18:35:12 -07:00
Thomas Lively a787e09779 [WebAssembly] Prototype i64x2.bitmask
As proposed in https://github.com/WebAssembly/simd/pull/368.

Differential Revision: https://reviews.llvm.org/D90514
2020-10-30 17:23:30 -07:00
Thomas Lively 0a512a555a [WebAssembly] Prototype i64x2.eq
As proposed in https://github.com/WebAssembly/simd/pull/381. Since it is still
in the prototyping phase, it is only accessible via a target builtin function
and a target intrinsic.

Depends on D90504.

Differential Revision: https://reviews.llvm.org/D90508
2020-10-30 16:38:15 -07:00
Thomas Lively 1cb0b56607 [WebAssembly] Prototype i64x2.widen_{low,high}_i32x4_{s,u}
As proposed in https://github.com/WebAssembly/simd/pull/290. As usual, these
instructions are available only via builtin functions and intrinsics while they
are in the prototyping stage.

Differential Revision: https://reviews.llvm.org/D90504
2020-10-30 15:44:04 -07:00
Keith Smiley bbf02e18f5 [clang][NFC] Remove unused FileCheck prefix
This is to enable --allow-unused-duplicates=false. This prefix appears
to be outdated and intentionally unused.

Differential Revision: https://reviews.llvm.org/D90430
2020-10-30 13:32:14 -07:00
Duncan P. N. Exon Smith 814141f9bd Remove `noexcept` from ac49500cd0 to fix bots
I'm having trouble with bots today. Remove more cargo-cult from the
generic version of `OptionalStorage` that is failing on some (fewer)
bots (but not locally).

I expect this will fix:

```
FAILED: tools/clang/unittests/Basic/CMakeFiles/BasicTests.dir/FileEntryTest.cpp.o
/usr/bin/c++  -DGTEST_HAS_RTTI=0 -DGTEST_HAS_TR1_TUPLE=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/clang/unittests/Basic -I/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/unittests/Basic -I/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/include -Itools/clang/include -Iinclude -I/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/include -I/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/utils/unittest/googletest/include -I/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/llvm/utils/unittest/googlemock/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3     -Wno-variadic-macros -fno-exceptions -fno-rtti -UNDEBUG -Wno-suggest-override -std=c++14 -MD -MT tools/clang/unittests/Basic/CMakeFiles/BasicTests.dir/FileEntryTest.cpp.o -MF tools/clang/unittests/Basic/CMakeFiles/BasicTests.dir/FileEntryTest.cpp.o.d -o tools/clang/unittests/Basic/CMakeFiles/BasicTests.dir/FileEntryTest.cpp.o -c /home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/unittests/Basic/FileEntryTest.cpp
/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/unittests/Basic/FileEntryTest.cpp: In member function ‘virtual void {anonymous}::FileEntryTest_OptionalFileEntryRefDegradesToFileEntryPtr_Test::TestBody()’:
/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/unittests/Basic/FileEntryTest.cpp:48:46: error: use of deleted function ‘constexpr clang::OptionalFileEntryRefDegradesToFileEntryPtr::OptionalFileEntryRefDegradesToFileEntryPtr()’
   OptionalFileEntryRefDegradesToFileEntryPtr M0;
                                              ^~
In file included from /home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/unittests/Basic/FileEntryTest.cpp:9:
/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/include/clang/Basic/FileEntry.h:250:3: note: ‘constexpr clang::OptionalFileEntryRefDegradesToFileEntryPtr::OptionalFileEntryRefDegradesToFileEntryPtr() noexcept’ is implicitly deleted because its exception-specification does not match the implicit exception-specification ‘’
   OptionalFileEntryRefDegradesToFileEntryPtr() noexcept = default;
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/unittests/Basic/FileEntryTest.cpp: In member function ‘virtual void {anonymous}::FileEntryTest_equals_Test::TestBody()’:
/home/buildbots/ppc64le-lld-multistage-test/ppc64le-lld-multistage-test/llvm-project/clang/unittests/Basic/FileEntryTest.cpp:82:46: error: use of deleted function ‘constexpr clang::OptionalFileEntryRefDegradesToFileEntryPtr::OptionalFileEntryRefDegradesToFileEntryPtr()’
   OptionalFileEntryRefDegradesToFileEntryPtr M0;
                                              ^~
```
2020-10-30 16:29:16 -04:00
Peter Collingbourne c9b1a2b41d AArch64: Use SBFX instead of UBFX to extract address granule in outlined HWASan checks.
In a kernel (or in general in environments where bit 55 of the address
is set) the shadow base needs to point to the end of the shadow region,
not the beginning. Bit 55 needs to be sign extended into bits 52-63
of the shadow base offset, otherwise we end up loading from an invalid
address. We can do this by using SBFX instead of UBFX.

Using SBFX should have no effect in the userspace case where bit 55
of the address is clear so we do so unconditionally. I don't think
we need a ABI version bump for this (but one will come anyway when
we switch to x20 for the shadow base register).

Differential Revision: https://reviews.llvm.org/D90424
2020-10-30 12:53:15 -07:00
Peter Collingbourne 3859fc653f AArch64: Switch to x20 as the shadow base register for outlined HWASan checks.
From a code size perspective it turns out to be better to use a
callee-saved register to pass the shadow base. For non-leaf functions
it avoids the need to reload the shadow base into x9 after each
function call, at the cost of an additional stack slot to save the
caller's x20. But with x9 there is also a stack size cost, either
as a result of copying x9 to a callee-saved register across calls or
by spilling it to stack, so for the non-leaf functions the change to
stack usage is largely neutral.

It is also code size (and stack size) neutral for many leaf functions.
Although they now need to save/restore x20 this can typically be
combined via LDP/STP into the x30 save/restore. In the case where
the function needs callee-saved registers or stack spills we end up
needing, on average, 8 more bytes of stack and 1 more instruction
but given the improvements to other functions this seems like the
right tradeoff.

Unfortunately we cannot change the register for the v1 (non short
granules) check because the runtime assumes that the shadow base
register is stored in x9, so the v1 check still uses x9.

Aside from that there is no change to the ABI because the choice
of shadow base register is a contract between the caller and the
outlined check function, both of which are compiler generated. We do
need to rename the v2 check functions though because the functions
are deduplicated based on their names, not on their contents, and we
need to make sure that when object files from old and new compilers
are linked together we don't end up with a function that uses x9
calling an outlined check that uses x20 or vice versa.

With this change code size of /system/lib64/*.so in an Android build
with HWASan goes from 200066976 bytes to 194085912 bytes, or a 3%
decrease.

Differential Revision: https://reviews.llvm.org/D90422
2020-10-30 12:51:30 -07:00