Commit Graph

85871 Commits

Author SHA1 Message Date
Richard Smith 7337f29619 PR47555: Inheriting constructors are implicitly definable.
Don't forget to define them if they're constexpr and used inside a
template; we might try to evaluate a call to them before the template is
instantiated.
2020-09-16 18:11:18 -07:00
Richard Smith 905b9ca26c Canonicalize declaration pointers when forming APValues.
References to different declarations of the same entity aren't different
values, so shouldn't have different representations.

Recommit of e6393ee813 with fixed
handling for weak declarations. We now look for attributes on the most
recent declaration when determining whether a declaration is weak.
2020-09-16 18:11:18 -07:00
Daniel Kiss f70baaf71f [AArch64] Add -mmark-bti-property flag.
Writing the .note.gnu.property manually is error prone and hard to
maintain in the assembly files.
The -mmark-bti-property is for the assembler to emit the section with the
GNU_PROPERTY_AARCH64_FEATURE_1_BTI. To be used when C/C++ is compiled
with -mbranch-protection=bti.

This patch refactors the .note.gnu.property handling.

Reviewed By: chill, nickdesaulniers

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

Reland with test dependency on aarch64 target.
2020-09-17 01:18:36 +02:00
Daniel Kiss 60e244f82c Revert "[AArch64] Add -mmark-bti-property flag."
This reverts commit 95e43f84b7.
2020-09-17 01:17:23 +02:00
Daniel Kiss 95e43f84b7 [AArch64] Add -mmark-bti-property flag.
Writing the .note.gnu.property manually is error prone and hard to
maintain in the assembly files.
The -mmark-bti-property is for the assembler to emit the section with the
GNU_PROPERTY_AARCH64_FEATURE_1_BTI. To be used when C/C++ is compiled
with -mbranch-protection=bti.

This patch refactors the .note.gnu.property handling.

Reviewed By: chill, nickdesaulniers

Differential Revision: https://reviews.llvm.org/D81930
2020-09-17 00:24:14 +02:00
Yaxun (Sam) Liu ee5519d323 [NFC] Refactor DiagnosticBuilder and PartialDiagnostic
PartialDiagnostic misses some functions compared to DiagnosticBuilder.

This patch refactors DiagnosticBuilder and PartialDiagnostic, extracts
the common functionality so that the streaming << operators are
shared.

Differential Revision: https://reviews.llvm.org/D84362
2020-09-16 17:35:28 -04:00
Amy Huang bebfc3b92d Revert "Do not apply calling conventions to MSVC entry points"
This reverts commit 4cff1b40da.

Caused "undefined symbol: _WinMain@16" link errors.
2020-09-16 13:52:29 -07:00
Fanbo Meng 2240ca0bd1 [SystemZ][z/OS] Set aligned allocation unavailable by default for z/OS
Aligned allocation is not supported on z/OS. This patch sets -faligned-alloc-unavailable as default in z/OS toolchain.

Reviewed By: abhina.sreeskantharajan, hubert.reinterpretcast

Differential Revision: https://reviews.llvm.org/D87611
2020-09-16 14:49:03 -04:00
Johannes Doerfert 56069b5c71 [OpenMP] Support `std::complex` math functions in target regions
The last (big) missing piece to get "math" working in OpenMP target
regions (that I know of) was complex math functions, e.g.,
`std::sin(std::complex<double>)`. With this patch we overload the system
template functions for these operations with versions that have been
distilled from `libcxx/include/complex`. We use the same
  `omp begin/end declare variant`
mechanism we use for other math functions before, except that we this
time overload templates (via D85735).

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D85777
2020-09-16 13:37:10 -05:00
Johannes Doerfert 5c1084e884 [OpenMP] Context selector extensions for template functions
With this extension the effects of `omp begin declare variant` will be
applied to template function declarations. The behavior is opt-in and
controlled by the `extension(allow_templates)` trait. While generally
useful, this will enable us to implement complex math function calls by
overloading the templates of the standard library with the ones in
libc++.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D85735
2020-09-16 13:37:10 -05:00
Johannes Doerfert 97652202d1 [OpenMP] Overload `std::isnan` and friends multiple times for the GPU
`std::isnan` and friends can be found in two variants in the wild, one
returns `bool`, as the standard defines it, one returns `int`, as the C
macros do. So far we kinda hoped the system versions of these functions
will work for people, e.g. they are definitions that can be compiled for
the target. We know that is not the case always so we leverage the
`disable_implicit_base` OpenMP context extension to specialize both
versions of these functions without causing an invalid redeclaration.

Reviewed By: JonChesterfield, tra

Differential Revision: https://reviews.llvm.org/D85879
2020-09-16 13:37:09 -05:00
Johannes Doerfert c4b7a1da9d [OpenMP] Context selector extensions for return value overloading
This extension allows to declare variants in between `omp begin/end
declare variant` that do not match the type of the existing function
with that name. Without this extension we would not find a base function
(with a compatible type), therefore create a new one, which would
cause conflicting declarations. With this extension we will not create
"missing" base functions, which basically renders these specializations
harmless. They will be generated but never called.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D85878
2020-09-16 13:37:09 -05:00
Johannes Doerfert 5c63ae156e [OpenMP] Support nested OpenMP context selectors (declare variant)
Due to `omp begin/end declare variant`, OpenMP context selectors can be
nested. This patch adds initial support for this so we can use it for
target math variants. We should improve the detection of "equivalent"
scores and user conditions, we should also revisit the data structures
of the OMPTraitInfo object, however, both are not pressing issues right
now.

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D85877
2020-09-16 13:37:09 -05:00
Johannes Doerfert 05fd04eda4 [OpenMP][FIX] Do not drop a '$' while demangling declare variant names
Reviewed By: ABataev

Differential Revision: https://reviews.llvm.org/D85876
2020-09-16 13:37:09 -05:00
Johannes Doerfert 6a02932bec [OpenMP][FIX] Do not crash trying to print a missing (demangled) user condition
Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D85875
2020-09-16 13:37:08 -05:00
Michael Liao 4d4f092283 [clang][codegen] Skip adding default function attributes on intrinsics.
- After loading builtin bitcode for linking, skip adding default
  function attributes on LLVM intrinsics as their attributes are
  well-defined and retrieved directly from internal definitions. Adding
  extra attributes on intrinsics results in inconsistent result when
  `-save-temps` is present. Also, that makes few optimizations
  conservative.

Differential Revision: https://reviews.llvm.org/D87761
2020-09-16 14:10:05 -04:00
Zequan Wu 4d437348d2 fix test no-rtti.cpp 2020-09-16 11:03:15 -07:00
Saleem Abdulrasool 77a01d9498 Sema: add support for `__attribute__((__swift_bridge__))`
This extends semantic analysis of attributes for Swift interoperability
by introducing the `swift_bridge` attribute.  This attribute enables
bridging Objective-C types to Swift specific types.

This is based on the work of the original changes in
8afaf3aad2

Differential Revision: https://reviews.llvm.org/D87532
Reviewed By: Aaron Ballman
2020-09-16 17:54:57 +00:00
Zequan Wu ebf267b87d [Sema][MSVC] warn at dynamic_cast/typeid when /GR- is given
Differential Revision: https://reviews.llvm.org/D86369
2020-09-16 10:38:52 -07:00
Elizabeth Andrews 4cff1b40da Do not apply calling conventions to MSVC entry points
Fix link error for MSVC entry points when calling conventions
are specified. MSVC entry points should have default calling
convention.

Differential Revision: https://reviews.llvm.org/D87701
2020-09-16 09:39:37 -07:00
Benjamin Kramer f0546173fa [ASTMatchers] Add missing definition for decompositionDecl
Otherwise we'd get a linker error whenever decompositionDecl is ODR
used.
2020-09-16 17:32:29 +02:00
Alexey Bataev 4341c6618d [OPENMP]Do not allow threadprivates as base for array-like reduction.
The base must be shared between the threads, threadprivates are not
allowed to be bases for array-like reductions.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D85762
2020-09-16 09:30:32 -04:00
mydeveloperday 4dd9c709ef [clang-format] [NFC] Fix spelling mistake in the documentation
Ensure ClangFormatStyleOptions.rst can be regenerated from Format.h

Patch By: YangZhihui

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D87352
2020-09-16 13:46:34 +01:00
Simon Pilgrim 0a0abc0ede [Sema] isOpenMPCapturedDecl - assert we locate CapturedRegionScopeInfo. NFCI.
Fixes clang static analayzer null dereference warning.
2020-09-16 12:42:35 +01:00
Sam McCall f5c7102dbc Update dead links to Itanium and ARM ABIs. NFC 2020-09-16 13:42:01 +02:00
Simon Pilgrim 439f5749d9 [AST] ASTReader::ReadModuleMapFileBlock - assert non-null Module. NFCI.
At this stage the Module* shouldn't be null - add an assert to fix a clang static analyzer warning.
2020-09-16 12:30:24 +01:00
Simon Pilgrim aa1e15dda9 TokenAnnotator.cpp - remove useless pointer null test. NFCI.
We dereference the Left pointer throughout the parseParens() function apart from this single case - just add an non-null assertion and drop the check.

Fixes clang static analayzer null dereference warning.
2020-09-16 12:30:24 +01:00
Simon Pilgrim 4abb5cd839 CGBlocks.cpp - assert non-null CGF pointer. NFCI.
Fixes static analyzer warning.
2020-09-16 12:30:24 +01:00
Adam Balogh dbd45b2db8 [ASTMatchers] Fix `hasBody` for the descendants of `FunctionDecl`
//AST Matcher// `hasBody` is a polymorphic matcher that behaves
differently for loop statements and function declarations. The main
difference is the for functions declarations it does not only call
`FunctionDecl::getBody()` but first checks whether the declaration in
question is that specific declaration which has the body by calling
`FunctionDecl::doesThisDeclarationHaveABody()`. This is achieved by
specialization of the template `GetBodyMatcher`. Unfortunately template
specializations do not catch the descendants of the class for which the
template is specialized. Therefore it does not work correcly for the
descendants of `FunctionDecl`, such as `CXXMethodDecl`,
`CXXConstructorDecl`, `CXXDestructorDecl` etc. This patch fixes this
issue by using a template metaprogram.

The patch also introduces a new matcher `hasAnyBody` which matches
declarations which have a body present in the AST but not necessarily
belonging to that particular declaration.

Differential Revision: https://reviews.llvm.org/D87527
2020-09-16 13:16:51 +02:00
Mircea Trofin 8ea7ef8eda [ThinLTO] Relax thinlto_embed_bitcode.ll check
Fixes fuscia test [1] - the thinlto annotations may not always be there.

[1] http://lab.llvm.org:8011/builders/fuchsia-x86_64-linux/builds/11312
2020-09-15 22:42:22 -07:00
Mircea Trofin 61fc10d6a5 [ThinLTO] add post-thinlto-merge option to -lto-embed-bitcode
This will embed bitcode after (Thin)LTO merge, but before optimizations.
In the case the thinlto backend is called from clang, the .llvmcmd
section is also produced. Doing so in the case where the caller is the
linker doesn't yet have a motivation, and would require plumbing through
command line args.

Differential Revision: https://reviews.llvm.org/D87636
2020-09-15 15:56:11 -07:00
Jan Korous ae726fecae [SourceManager] Explicitly check for potential iterator underflow
Differential Revision: https://reviews.llvm.org/D86231
2020-09-15 15:54:16 -07:00
Alexey Bataev 9e3842d603 [OPENMP]Fix codegen for is_device_ptr component, captured by reference.
Need to map the component as TO instead of the literal, because need to
pass a reference to a component if the pointer is overaligned.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D84887
2020-09-15 17:21:38 -04:00
Saleem Abdulrasool 7d26d6a1b0 Sema: add support for `__attribute__((__swift_bridged_typedef__))`
Extend the semantic attributes that clang processes for Swift to include
`swift_bridged_typedef`.  This attribute enables typedefs to be bridged
into Swift with a bridged name.

This is based on the work of the original changes in
8afaf3aad2

Differential Revision: https://reviews.llvm.org/D87396
Reviewed By: Aaron Ballman
2020-09-15 20:15:34 +00:00
Snehasish Kumar f1a3ab9044 [clang] Add a command line flag for the Machine Function Splitter.
This patch adds a command line flag for the machine function splitter
(added in rG94faadaca4e1).

-fsplit-machine-functions
Split machine functions using profile information (x86 ELF). On
other targets an error is emitted. If profile information is not
provided a warning is emitted notifying the user that profile
information is required.

Differential Revision: https://reviews.llvm.org/D87047
2020-09-15 12:41:58 -07:00
Albion Fung 05aa997d51 [PowerPC] Implement __int128 vector divide operations
This patch implements __int128 vector divide operations for ISA3.1.

Differential Revision: https://reviews.llvm.org/D85453
2020-09-15 15:19:35 -04:00
Zequan Wu f975ae4867 [CodeGen][typeid] Emit typeinfo directly if type is known at compile-time
Differential Revision: https://reviews.llvm.org/D87425
2020-09-15 12:15:47 -07:00
Jonas Toth 69f98311ca [ASTMatchers] extract public matchers from const-analysis into own patch
The analysis for const-ness of local variables required a view generally useful
matchers that are extracted into its own patch.

They are decompositionDecl and forEachArgumentWithParamType, that works
for calls through function pointers as well.

This is a reupload of https://reviews.llvm.org/D72505, that already landed,
but had to be reverted due to a GCC crash on powerpc
(https://reviews.llvm.org/rG4c48ea68e491cb42f1b5d43ffba89f6a7f0dadc4)

Because this took a long time to adress, i decided to redo this patch and
have a clean workflow.
I try to coordinate with someone that has a PPC to apply this patch and
test for the crash. If everything is fine, I intend to just commit.
If the crash is still happening, i hope to at least find the cause.

Differential Revision: https://reviews.llvm.org/D87588
2020-09-15 21:07:30 +02:00
Alexey Bataev 738bab743b [OPENMP]Add support for allocate vars in untied tasks.
Local vars, marked with pragma allocate, mustbe allocate by the call of
the runtime function and cannot be allocated as other local variables.
Instead, we allocate a space for the pointer in private record and store
the address, returned by kmpc_alloc call in this pointer.
So, for untied tasks

```
 #pragma omp task untied
 {
   S s;
    #pragma omp allocate(s) allocator(allocator)
   s = x;
 }
```
compiler generates something like this:
```
struct task_with_privates {
  S *ptr;
};

void entry(task_with_privates *p) {
  S *s = p->s;
  switch(partid) {
  case 1:
    p->s = (S*)kmpc_alloc();
    kmpc_omp_task();
    br exit;
  case 2:
    *s = x;
    kmpc_omp_task();
    br exit;
  case 2:
    ~S(s);
    kmpc_free((void*)s);
    br exit;
  }
exit:
}
```

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D86558
2020-09-15 13:39:14 -04:00
Nemanja Ivanovic 3bc3983f22 Fix bot failure after ccb4124a41
The test case has a check line for the option on a line that includes
the string lld surrounded by any characters. This causes failures
when said string is in the build path. What the test case presumably
means to test is the actual invocation of the LLD linker (i.e. a
linker that has that string as a suffix). This patch simply removes
the erroneous wildcard after the string.
2020-09-15 12:36:47 -05:00
Florian Hahn 3a59628f3c Revert "[DSE] Switch to MemorySSA-backed DSE by default."
This reverts commit fb109c42d9.

Temporarily revert due to a mis-compile pointed out at D87163.
2020-09-15 18:07:56 +01:00
Kristóf Umann dd1d5488e4 [analyzer][Liveness][NFC] Get rid of statement liveness, because such a thing doesn't exist
The summary and very short discussion in D82122 summarizes whats happening here.

In short, liveness talks about variables, or expressions, anything that
has a value. Well, statements just simply don't have a one.

Differential Revision: https://reviews.llvm.org/D82598
2020-09-15 17:43:02 +02:00
Kristóf Umann 7c6f5b7fbf [analyzer] Add documentation for alpha.fuchsia.Lock and alpha.core.C11Lock
Differential Revision: https://reviews.llvm.org/D86532
2020-09-15 16:55:44 +02:00
Gabor Marton a012bc4c42 [analyzer][StdLibraryFunctionsChecker] Elaborate the summary of fread and fwrite
Add the BufferSize argument constraint to fread and fwrite. This change
itself makes it possible to discover a security critical case, described
in SEI-CERT ARR38-C.

We also add the not-null constraint on the 3rd arguments.

In this patch, I also remove those lambdas that don't take any
parameters (Fwrite, Fread, Getc), thus making the code better
structured.

Differential Revision: https://reviews.llvm.org/D87081
2020-09-15 16:35:39 +02:00
Simon Pilgrim 9eab73fa17 [X86] Update SSE/AVX integer MINMAX intrinsics to emit llvm.smax.* etc. (PR46851)
We're now getting close to having the necessary analysis/combines etc. for the new generic llvm smax/smin/umax/umin intrinsics.

This patch updates the SSE/AVX integer MINMAX intrinsics to emit the generic equivalents instead of the icmp+select code pattern.

Differential Revision: https://reviews.llvm.org/D87603
2020-09-15 11:19:08 +01:00
Chris Hamilton c8ddf27ddb Revert "[Sema] Address-space sensitive index check for unbounded arrays"
This reverts commit da55e9ba12.

Build bots uncovered coverage gap in testing.  Change not ready.
2020-09-15 01:57:29 -05:00
Chris Hamilton da55e9ba12 [Sema] Address-space sensitive index check for unbounded arrays
Check applied to unbounded (incomplete) arrays and pointers
to spot cases where the computed address is beyond the
largest possible addressable extent of the array, based
on the address space in which the array is delcared, or
which the pointer refers to.

Check helps to avoid cases of nonsense pointer math and
array indexing which could lead to linker failures or
runtime exceptions.  Of particular interest when building
for embedded systems with small address spaces.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D86796
2020-09-14 18:13:19 -05:00
Teresa Johnson 226d80ebe2 [MemProf] Rename HeapProfiler to MemProfiler for consistency
This is consistent with the clang option added in
7ed8124d46, and the comments on the
runtime patch in D87120.

Differential Revision: https://reviews.llvm.org/D87622
2020-09-14 13:14:57 -07:00
Rahman Lavaee 7841e21c98 Let -basic-block-sections=labels emit basicblock metadata in a new .bb_addr_map section, instead of emitting special unary-encoded symbols.
This patch introduces the new .bb_addr_map section feature which allows us to emit the bits needed for mapping binary profiles to basic blocks into a separate section.
The format of the emitted data is represented as follows. It includes a header for every function:

|  Address of the function                      |  -> 8 bytes (pointer size)
|  Number of basic blocks in this function (>0) |  -> ULEB128

The header is followed by a BB record for every basic block. These records are ordered in the same order as MachineBasicBlocks are placed in the function. Each BB Info is structured as follows:

|  Offset of the basic block relative to function begin |  -> ULEB128
|  Binary size of the basic block                       |  -> ULEB128
|  BB metadata                                          |  -> ULEB128  [ MBB.isReturn() OR MBB.hasTailCall() << 1  OR  MBB.isEHPad() << 2 ]

The new feature will replace the existing "BB labels" functionality with -basic-block-sections=labels.
The .bb_addr_map section scrubs the specially-encoded BB symbols from the binary and makes it friendly to profilers and debuggers.
Furthermore, the new feature reduces the binary size overhead from 70% bloat to only 12%.

For more information and results please refer to the RFC: https://lists.llvm.org/pipermail/llvm-dev/2020-July/143512.html

Reviewed By: MaskRay, snehasish

Differential Revision: https://reviews.llvm.org/D85408
2020-09-14 10:16:44 -07:00
Saleem Abdulrasool 916b434035 Sema: add support for `__attribute__((__swift_objc_members__))`
This adds the `__swift_objc_members__` attribute to the semantic
analysis.  It allows for annotating ObjC interfaces to provide Swift
semantics indicating that the types derived from this interface will be
back-bridged to Objective-C to allow interoperability with Objective-C
and Swift.

This is based on the work of the original changes in
8afaf3aad2

Differential Revision: https://reviews.llvm.org/D87395
Reviewed By: Aaron Ballman, Dmitri Gribenko
2020-09-14 15:24:41 +00:00
Simon Pilgrim 3b7708e2de Assert we've found the size of each (non-overlapping) structure. NFCI.
Fixes clang static analyzer warning.
2020-09-14 16:10:52 +01:00
Eduardo Caldas ceb0128509 [SyntaxTree][List] `assertInvariants` for `List`s
Differential Revision: https://reviews.llvm.org/D87600
2020-09-14 10:36:11 +00:00
Eduardo Caldas 0f4cc64fd7 [SyntaxTree] Provide `List::classof`
Differential Revision: https://reviews.llvm.org/D87599
2020-09-14 10:35:41 +00:00
Eduardo Caldas 12232dc181 [SyntaxTree][List] Fix: `ParameterDeclarationList` is the `List` inside `ParametersAndQualifiers`
Differential Revision: https://reviews.llvm.org/D87598
2020-09-14 10:35:41 +00:00
Simon Pilgrim 4232bccfb4 [CodeGen][X86] Regenerate minmax reduction sequence tests to match arithmetic tests.
avx512-reduceIntrin.c wasn't bothering with the exhaustive alloca/store/load/bitcast checks and avx512-reduceMinMaxIntrin.c shouldn't need to either.

This makes it a lot easier to maintain as the update script still doesn't work properly on x86 targets
2020-09-14 10:27:51 +01:00
Balazs Benics cdacffe4ac [analyzer][z3] Use more elaborate Z3 variable names
Previously, it was a tedious task to comprehend Z3 dumps.
We will use the same name prefix just as we use in the corresponding dump method

For all `SymbolData` values:
    `$###` -> `conj_$###`
    `$###` -> `derived_$###`
    `$###` -> `extent_$###`
    `$###` -> `meta_$###`
    `$###` -> `reg_$###`

Reviewed By: xazax.hun,mikhail.ramalho

Differential Revision: https://reviews.llvm.org/D86223
2020-09-14 08:43:56 +02:00
Balazs Benics 163863604f [analyzer] Evaluate PredefinedExpressions
We did not evaluate such expressions, just returned `Unknown` for such cases.
After this patch, we will be able to access a unique value identifying a template instantiation via the value of the `PRETTY_FUNCTION` predefined expression.

Reviewed By: vsavchenko

Differential Revision: https://reviews.llvm.org/D87004
2020-09-14 08:43:56 +02:00
Serge Pavlov f1cd6593da [AST][FPEnv] Keep FP options in trailing storage of CastExpr
This is recommit of 6c8041aa0f, reverted in de044f7562 because of some
fails. Original commit message is below.

This change allow a CastExpr to have optional FPOptionsOverride object,
stored in trailing storage. Of all cast nodes only ImplicitCastExpr,
CStyleCastExpr, CXXFunctionalCastExpr and CXXStaticCastExpr are allowed
to have FPOptions.

Differential Revision: https://reviews.llvm.org/D85960
2020-09-14 12:15:21 +07:00
Raphael Isemann c0bcd11068 [ASTImporter] Add basic support for comparing Stmts and compare function bodies
Right now the ASTImporter assumes for most Expr nodes that they are always equal
which leads to non-compatible declarations ending up being merged. This patch
adds the basic framework for comparing Stmts (and with that also Exprs) and
implements the custom checks for a few Stmt subclasses. I'll implement the
remaining subclasses in follow up patches (mostly because there are a lot of
subclasses and some of them require further changes like having GNU language in
the testing framework)

The motivation for this is that in LLDB we try to import libc++ source code and
some of the types we are importing there contain expressions (e.g. because they
use `enable_if<expr>`), so those declarations are currently merged even if they
are completely different (e.g. `enable_if<value> ...` and `enable_if<!value>
...` are currently considered equal which is clearly not true).

Reviewed By: martong, balazske

Differential Revision: https://reviews.llvm.org/D87444
2020-09-13 18:25:04 +02:00
Fangrui Song 63182c2ac0 [gcov] Add spanning tree optimization
gcov is an "Edge Profiling with Edge Counters" application according to
Optimally Profiling and Tracing Programs (1994).

The minimum number of counters necessary is |E|-(|V|-1). The unmeasured edges
form a spanning tree. Both GCC --coverage and clang -fprofile-generate leverage
this optimization. This patch implements the optimization for clang --coverage.
The produced .gcda files are much smaller now.
2020-09-13 00:07:31 -07:00
Fangrui Song f086e85eea [gcov] Assign names to some types and loaded values used in @__llvm_internal*
This makes the generated IR much more readable.
2020-09-12 22:42:37 -07:00
Travis Finkenauer 0fb2203cd6 [Docs] Fix --print-supported-cpus option rendering
Adds link/code sample to avoid rendering two dashes as non-ASCII "en dash".
Also make wording a complete sentence.

Reviewed By: nickdesaulniers, tmfink

Differential Revision: https://reviews.llvm.org/D85596
2020-09-13 05:26:18 +00:00
Sam Clegg 04febd30a8 [lld][WebAssembly] Error on import/export of mutable global without `mutable-globals` feature
Also add the +mutable-globals features in clang when
building with `-fPIC` since the linker will generate mutable
globals imports and exports in that case.

Differential Revision: https://reviews.llvm.org/D87537
2020-09-12 14:28:14 -07:00
Fangrui Song d6fadc49e3 [gcov] Process .gcda immediately after the accompanying .gcno instead of doing all .gcda after all .gcno
i.e. change the work flow from

* .gcno for function A
* .gcno for function B
* .gcno for function C
* .gcda for function A
* .gcda for function B
* .gcda for function C

to

* .gcno for function A
* .gcda for function A
* .gcno for function B
* .gcda for function B
* .gcno for function C
* .gcda for function C

Currently there is duplicate logic in .gcno & .gcda processing: how functions
are filtered, which edges are instrumented, etc. This refactor enables simplification.

Since we always process .gcno, in -fprofile-arcs -fno-test-coverage mode,
__llvm_internal_gcov_emit_function_args.0 will have non-zero checksums.
2020-09-12 13:53:03 -07:00
Mateusz Mikuła 7da9419399 [MinGW][libclang] Allow simultaneous shared and static lib
It builds fine for MinGW on Windows.

Differential Revision: https://reviews.llvm.org/D87539
2020-09-12 22:03:43 +03:00
Mateusz Mikuła bb613044b6 [MinGW][clang-shlib] Build by default on MinGW
It builds without errors and makes possible to use
CLANG_LINK_CLANG_DYLIB=1.

Differential Revision: https://reviews.llvm.org/D87547
2020-09-12 22:02:31 +03:00
Mateusz Mikuła cc76965b19 [MinGW] Use lib prefix for libraries
In MinGW world, UNIX like lib prefix is preferred for the libraries.
This patch adjusts CMake files to do that.

Differential Revision: https://reviews.llvm.org/D87517
2020-09-12 22:01:29 +03:00
Florian Hahn a874d63344 [Clang] Add option to allow marking pass-by-value args as noalias.
After the recent discussion on cfe-dev 'Can indirect class parameters be
noalias?' [1], it seems like using using noalias is problematic for
current C++, but should be allowed for C-only code.

This patch introduces a new option to let the user indicate that it is
safe to mark indirect class parameters as noalias. Note that this also
applies to external callers, e.g. it might not be safe to use this flag
for C functions that are called by C++ functions.

In targets that allocate indirect arguments in the called function, this
enables more agressive optimizations with respect to memory operations
and brings a ~1% - 2% codesize reduction for some programs.

[1] : http://lists.llvm.org/pipermail/cfe-dev/2020-July/066353.html

Reviewed By: rjmccall

Differential Revision: https://reviews.llvm.org/D85473
2020-09-12 14:56:13 +01:00
Tyker 78de7297ab Reland [AssumeBundles] Use operand bundles to encode alignment assumptions
NOTE: There is a mailing list discussion on this: http://lists.llvm.org/pipermail/llvm-dev/2019-December/137632.html

Complemantary to the assumption outliner prototype in D71692, this patch
shows how we could simplify the code emitted for an alignemnt
assumption. The generated code is smaller, less fragile, and it makes it
easier to recognize the additional use as a "assumption use".

As mentioned in D71692 and on the mailing list, we could adopt this
scheme, and similar schemes for other patterns, without adopting the
assumption outlining.
2020-09-12 15:36:06 +02:00
Serge Pavlov de044f7562 Revert "[AST][FPEnv] Keep FP options in trailing storage of CastExpr"
This reverts commit 6c8041aa0f.
It caused some fails on buildbots.
2020-09-12 17:06:42 +07:00
Serge Pavlov 9c651c231f Missing change from previous commit 2020-09-12 15:11:09 +07:00
Serge Pavlov 6c8041aa0f [AST][FPEnv] Keep FP options in trailing storage of CastExpr
This change allow a CastExpr to have optional FPOptionsOverride object,
stored in trailing storage. Of all cast nodes only ImplicitCastExpr,
CStyleCastExpr, CXXFunctionalCastExpr and CXXStaticCastExpr are allowed
to have FPOptions.

Differential Revision: https://reviews.llvm.org/D85960
2020-09-12 14:30:44 +07:00
David Blaikie 928d419797 Fix a couple of tests that relied on the clang binary having 'clang' somewhere in the name
Because why would that be necessary? (I joke - I hadn't actually
expected this to be an issue but a content-hash-named filesystem means
the clang binary's just a bunch of numbers, and doesn't have 'clang'
anywhere in the name)
2020-09-11 17:45:56 -07:00
Vitaly Buka a8503b87f7 [NFC] Remove unused static function 2020-09-11 16:50:30 -07:00
Zequan Wu 83286a1a8f [MS ABI] Add mangled type for auto template parameter whose argument kind is Integeral 2020-09-11 16:19:43 -07:00
Dmitri Gribenko e10df779f0 Fix clang Wrange-loop-analysis in BuildTree.cpp
Building on Mac OS with clang 12:

```
jhemphill@jhemphill-mbp build % clang --version
Apple clang version 12.0.0 (clang-1200.0.26.2)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
```

yields one warning:

```
/Users/jhemphill/oss/llvm-project/clang/lib/Tooling/Syntax/BuildTree.cpp:1126:22: warning: loop variable 'Arg' is always a copy because the range of type 'llvm::iterator_range<clang::Stmt::CastIterator<clang::Expr, clang::Expr *, clang::Stmt *> >' does not return a reference [-Wrange-loop-analysis]
    for (const auto &Arg : Args) {
                     ^
/Users/jhemphill/oss/llvm-project/clang/lib/Tooling/Syntax/BuildTree.cpp:1126:10: note: use non-reference type 'clang::Expr *'
    for (const auto &Arg : Args) {
```

It appears that `Arg` is an `Expr*`, passed by value rather than by const reference.

Reviewed By: eduucaldas, gribozavr2

Differential Revision: https://reviews.llvm.org/D87482
2020-09-12 01:07:54 +02:00
Saleem Abdulrasool 43e6c59f1c docs: add a newline to appease Sphinx
Sphinx expects an empty newline after the bulleted list.
2020-09-11 22:09:29 +00:00
Yaxun (Sam) Liu ee13ae030e Fix test hip-gz-options.hip 2020-09-11 17:57:36 -04:00
Saleem Abdulrasool f5ab5b20fb Sema: add support for `__attribute__((__swift_error__))`
Introduce a new attribute that is used to indicate the error handling
convention used by a function.  This is used to translate the error
semantics from the decorated interface to a compatible Swift interface.

The supported error convention is one of:
- none: no error handling
- nonnull_error: a non-null error parameter indicates an error signifier
- null_result: a return value of NULL is an error signifier
- zero_result: a return value of 0 is an error signifier
- nonzero_result: a non-zero return value is an error signifier

Since this is the first of the attributes needed to support the semantic
annotation for Swift, this change also includes the necessary supporting
infrastructure for a new category of attributes (Swift).

This is based on the work of the original changes in
8afaf3aad2

Differential Revision: https://reviews.llvm.org/D87331
Reviewed By: John McCall, Aaron Ballman, Dmitri Gribenko
2020-09-11 21:20:38 +00:00
Yaxun (Sam) Liu ccb4124a41 Fix -gz=zlib options for linker
gcc translates -gz=zlib to --compress-debug-options=zlib for both assembler and linker
but clang only does this for assembler.

The linker needs --compress-debug-options=zlib option to compress the debug sections
in the generated executable or shared library.

Due to this bug, -gz=zlib has no effect on the generated executable or shared library.

This patch fixes that.

Differential Revision: https://reviews.llvm.org/D87321
2020-09-11 17:12:58 -04:00
Eduardo Caldas 7c37b82f5b [SyntaxTree][Synthesis] Add support for Tree.
In a future patch
* Implement helper function to generate Trees for tests
* and test Tree methods, namely `findFirstLeaf` and `findLastLeaf`

Differential Revision: https://reviews.llvm.org/D87533
2020-09-11 20:37:23 +00:00
Xun Li df477db5f9 [Coroutine][Sema] Tighten the lifetime of symmetric transfer returned handle
In generating the code for symmetric transfer, a temporary object is created to store the returned handle from await_suspend() call of the awaiter. Previously this temp won't be cleaned up until very later, which ends up causing this temp to be spilled to the heap. However, we know that this temp will no longer be needed after the coro_resume call. We can clean it up right after.

Differential Revision: https://reviews.llvm.org/D87470
2020-09-11 13:35:37 -07:00
Eduardo Caldas 238ae4eee0 [SyntaxTree] Add const qualifiers, from [llvm-qualified-auto]
Differential Revision: https://reviews.llvm.org/D87522
2020-09-11 18:39:02 +00:00
Eduardo Caldas 515238d5b1 [SyntaxTree] Reduce visibility of `Arena::lexBuffer`.
Differential Revision: https://reviews.llvm.org/D87523
2020-09-11 18:32:38 +00:00
Eduardo Caldas 5d152127d4 [SyntaxTree][Synthesis] Add support for simple Leafs and test based on tree dump
Differential Revision: https://reviews.llvm.org/D87495
2020-09-11 18:22:00 +00:00
David Green ab2ed8bce9 [SVE] Regenerate sve vector bits tests. NFC 2020-09-11 18:51:57 +01:00
Qiu Chaofan 8ecc8520bc [FPEnv] [Clang] Enable constrained FP support for PowerPC
d4ce862f introduced HasStrictFP to disable generating constrained FP
operations for platforms lacking support. Since work for enabling
constrained FP on PowerPC is almost done, we'd like to enable it.

Reviewed By: kpn, steven.zhang

Differential Revision: https://reviews.llvm.org/D87223
2020-09-12 00:39:52 +08:00
Eduardo Caldas 4c14ee61b7 [SyntaxTree] Rename functions to start with verb
According to LLVM coding standards:
https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly

Differential Revision: https://reviews.llvm.org/D87498
2020-09-11 14:54:18 +00:00
Simon Pilgrim 48b510c4bc [NFC] Fix compiler warnings due to integer comparison of different signedness
Fix by directly using INT_MAX and INT32_MAX.

Patch by: @nullptr.cpp (Yang Fan)

Differential Revision: https://reviews.llvm.org/D87347
2020-09-11 15:32:03 +01:00
Kristóf Umann b9bca883c9 [analyzer][NFC] Don't bind values to ObjCForCollectionStmt, replace it with a GDM trait
Based on the discussion in D82598#2171312. Thanks @NoQ!

D82598 is titled "Get rid of statement liveness, because such a thing doesn't
exist", and indeed, expressions express a value, non-expression statements
don't.

if (a && get() || []{ return true; }())
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ has a value
    ~ has a value
    ~~~~~~~~~~ has a value
                  ~~~~~~~~~~~~~~~~~~~~ has a value
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ doesn't have a value

That is simple enough, so it would only make sense if we only assigned symbolic
values to expressions in the static analyzer. Yet the interface checkers can
access presents, among other strange things, the following two methods:

ProgramState::BindExpr(const Stmt *S, const LocationContext *LCtx, SVal V,
                       bool Invalidate=true)
ProgramState::getSVal(const Stmt *S, const LocationContext *LCtx)

So, what gives? Turns out, we make an exception for ReturnStmt (which we'll
leave for another time) and ObjCForCollectionStmt. For any other loops, in order
to know whether we should analyze another iteration, among other things, we
evaluate it's condition. Which is a problem for ObjCForCollectionStmt, because
it simply doesn't have one (CXXForRangeStmt has an implicit one!). In its
absence, we assigned the actual statement with a concrete 1 or 0 to indicate
whether there are any more iterations left. However, this is wildly incorrect,
its just simply not true that the for statement has a value of 1 or 0, we can't
calculate its liveness because that doesn't make any sense either, so this patch
turns it into a GDM trait.

Fixing this allows us to reinstate the assert removed in
https://reviews.llvm.org/rG032b78a0762bee129f33e4255ada6d374aa70c71.

Differential Revision: https://reviews.llvm.org/D86736
2020-09-11 15:58:48 +02:00
Yitzhak Mandelbaum a5cefd95cc [libTooling] Fix use of `char` in comparison.
Fixes Transformer's `Range` parser to handle `char` in a platform-independent way.

Differential Revision: https://reviews.llvm.org/D87409
2020-09-11 12:24:09 +00:00
Kristóf Umann be0d79f329 [analyzer][MacroExpansion] Fix a crash where multiple parameters resolved to __VA_ARGS__
In short, macro expansions handled the case where a variadic parameter mapped to
multiple arguments, but not the other way around. An internal ticket was
submitted that demonstrated that we fail an assertion. Macro expansion so far
worked by lexing the source code token-by-token and using the Preprocessor to
turn these tokens into identifiers or just get their proper spelling, but what
this counter intuitively doesn't do, is actually expand these macros, so we have
to do the heavy lifting -- in this case, figure out what __VA_ARGS__ expands
into. Since this case can only occur in a nested macro, the information we
gathered from the containing macro does contain this information. If a parameter
resolves to __VA_ARGS__, we need to temporarily stop getting our tokens from the
lexer, and get the tokens from what __VA_ARGS__ maps to.

Differential Revision: https://reviews.llvm.org/D86135
2020-09-11 14:07:58 +02:00
Kirstóf Umann 7527898fef [analyzer][MacroExpansion][NFC] Fix a missing test output check 2020-09-11 13:48:26 +02:00
Kirstóf Umann 26d9a94681 [analyzer][MacroExpansion][NFC] Fix incorrectly calling parameters arguments 2020-09-11 13:33:02 +02:00
Kirstóf Umann 1c08da3867 [analyzer][MacroExpansion] Add a few dumps functions 2020-09-11 13:29:14 +02:00
Cullen Rhodes cabd60c26b [clang][aarch64] Fix mangling of bfloat16 neon vectors
The AAPCS64 specifies the internal type is used for c++ mangling. For
bfloat16 it was defined as `BFloat16` when it should be `Bfloat16`, i.e.
lowercase 'f'.

For more information, see:

https://github.com/ARM-software/abi-aa/blob/master/aapcs64/aapcs64.rst#appendix-support-for-advanced-simd-extensions

Reviewed By: stuij

Differential Revision: https://reviews.llvm.org/D87463
2020-09-11 10:11:45 +00:00
Caroline Concatto 257b29715b [flang][driver] Add the new flang compiler and frontend drivers
Summary:

This is the first patch implementing the new Flang driver as outlined in [1],
[2] & [3]. It creates Flang driver (`flang-new`) and Flang frontend driver
(`flang-new -fc1`). These will be renamed as `flang` and `flang -fc1` once the
current Flang throwaway driver, `flang`, can be replaced with `flang-new`.

Currently only 2 options are supported: `-help` and `--version`.

`flang-new` is implemented in terms of libclangDriver, defaulting the driver
mode to `FlangMode` (added to libclangDriver in [4]). This ensures that the
driver runs in Flang mode regardless of the name of the binary inferred from
argv[0].

The design of the new Flang compiler and frontend drivers is inspired by it
counterparts in Clang [3]. Currently, the new Flang compiler and frontend
drivers re-use Clang libraries: clangBasic, clangDriver and clangFrontend.

To identify Flang options, this patch adds FlangOption/FC1Option enums.
Driver::printHelp is updated so that `flang-new` prints only Flang options.
The new Flang driver is disabled by default. To enable it, set
`-DBUILD_FLANG_NEW_DRIVER=ON` when configuring CMake and add clang to
`LLVM_ENABLE_PROJECTS` (e.g. -DLLVM_ENABLE_PROJECTS=“clang;flang;mlir”).

[1] “RFC: new Flang driver - next steps”
http://lists.llvm.org/pipermail/flang-dev/2020-July/000470.html
[2] “RFC: Adding a fortran mode to the clang driver for flang”
http://lists.llvm.org/pipermail/cfe-dev/2019-June/062669.html
[3] “RFC: refactoring libclangDriver/libclangFrontend to share with Flang”
http://lists.llvm.org/pipermail/cfe-dev/2020-July/066393.html
[4] https://reviews.llvm.org/rG6bf55804924d5a1d902925ad080b1a2b57c5c75c

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

Reviewed By: richard.barton.arm, sameeranjoshi

Differential Revision: https://reviews.llvm.org/D86089
2020-09-11 10:55:54 +01:00
Cullen Rhodes 002f5ab3b1 [clang][aarch64] Fix ILP32 ABI for arm_sve_vector_bits
The element types of scalable vectors are defined in terms of stdint
types in the ACLE. This patch fixes the mapping to builtin types for the
ILP32 ABI when creating VLS types with the arm_sve_vector_bits, where
the mapping is as follows:

  int32_t -> LongTy
  int64_t -> LongLongTy
  uint32_t -> UnsignedLongTy
  uint64_t -> UnsignedLongLongTy

This is implemented by leveraging getBuiltinVectorTypeInfo which is
target agnostic since it calls ASTContext::getIntTypeForBitwidth for
integer types. The element type for svfloat16_t is changed from
Float16Ty to HalfTy when creating VLS types since this is what is used
elsewhere.

For more information, see:

https://github.com/ARM-software/abi-aa/blob/master/aapcs64/aapcs64.rst#types-varying-by-data-model
https://github.com/ARM-software/abi-aa/blob/master/aapcs64/aapcs64.rst#appendix-support-for-scalable-vectors

Reviewed By: efriedma

Differential Revision: https://reviews.llvm.org/D87358
2020-09-11 09:46:35 +00:00
Guillaume Chatelet b8ea47a380
Uncapitalize word in LanguageExtensions.rst 2020-09-11 10:08:02 +02:00
Rainer Orth 76e85ae268 [clang][Sparc] Default to -mcpu=v9 for Sparc V8 on Solaris
As reported in Bug 42535, `clang` doesn't inline atomic ops on 32-bit
Sparc, unlike `gcc` on Solaris.  In a 1-stage build with `gcc`, only two
testcases are affected (currently `XFAIL`ed), while in a 2-stage build more
than 100 tests `FAIL` due to this issue.

The reason for this `gcc`/`clang` difference is that `gcc` on 32-bit
Solaris/SPARC defaults to `-mpcu=v9` where atomic ops are supported, unlike
with `clang`'s default of `-mcpu=v8`.  This patch changes `clang` to use
`-mcpu=v9` on 32-bit Solaris/SPARC, too.

Doing so uncovered two bugs:

`clang -m32 -mcpu=v9` chokes with any Solaris system headers included:

  /usr/include/sys/isa_defs.h:461:2: error: "Both _ILP32 and _LP64 are defined"
  #error "Both _ILP32 and _LP64 are defined"

While `clang` currently defines `__sparcv9` in a 32-bit `-mcpu=v9`
compilation, neither `gcc` nor Studio `cc` do.  In fact, the Studio 12.6
`cc(1)` man page clearly states:

            These predefinitions are valid in all modes:
  [...]
               __sparcv8 (SPARC)
               __sparcv9 (SPARC -m64)

At the same time, the patch defines `__GCC_HAVE_SYNC_COMPARE_AND_SWAP_[1248]`
for a 32-bit Sparc compilation with any V9 cpu.  I've also changed
`MaxAtomicInlineWidth` for V9, matching what `gcc` does and the Oracle
Developer Studio 12.6: C User's Guide documents (Ch. 3, Support for Atomic
Types, 3.1 Size and Alignment of Atomic C Types).

The two testcases that had been `XFAIL`ed for Bug 42535 are un-`XFAIL`ed
again.

Tested on `sparcv9-sun-solaris2.11` and `amd64-pc-solaris2.11`.

Differential Revision: https://reviews.llvm.org/D86621
2020-09-11 09:53:19 +02:00
Guillaume Chatelet e38be7091e [Clang] Clarify __builtin_memcpy_inline documentation
This patch updates the documentation about `__builtin_memcpy_inline` and reorders the sections so it is more consitent and understandable.

Differential Revision: https://reviews.llvm.org/D87458
2020-09-11 07:20:39 +00:00
Michael Liao b22d450496 Remove dependency on clangASTMatchers.
- It seems no long required for shared library builds.
2020-09-10 22:17:48 -04:00
Florian Hahn fb109c42d9 [DSE] Switch to MemorySSA-backed DSE by default.
The tests have been updated and I plan to move them from the MSSA
directory up.

Some end-to-end tests needed small adjustments. One difference to the
legacy DSE is that legacy DSE also deletes trivially dead instructions
that are unrelated to memory operations. Because MemorySSA-backed DSE
just walks the MemorySSA, we only visit/check memory instructions. But
removing unrelated dead instructions is not really DSE's job and other
passes will clean up.

One noteworthy change is in llvm/test/Transforms/Coroutines/ArgAddr.ll,
but I think this comes down to legacy DSE not handling instructions that
may throw correctly in that case. To cover this with MemorySSA-backed
DSE, we need an update to llvm.coro.begin to treat it's return value to
belong to the same underlying object as the passed pointer.

There are some minor cases MemorySSA-backed DSE currently misses, e.g. related
to atomic operations, but I think those can be implemented after the switch.

This has been discussed on llvm-dev:
http://lists.llvm.org/pipermail/llvm-dev/2020-August/144417.html

For the MultiSource/SPEC2000/SPEC2006 the number of eliminated stores
goes from ~17500 (legayc DSE) to ~26300 (MemorySSA-backed). More numbers
and details in the thread on llvm-dev.

Impact on CTMark:
```
                                     Legacy Pass Manager
                        exec instrs    size-text
O3                       + 0.60%        - 0.27%
ReleaseThinLTO           + 1.00%        - 0.42%
ReleaseLTO-g.            + 0.77%        - 0.33%
RelThinLTO (link only)   + 0.87%        - 0.42%
RelLO-g (link only)      + 0.78%        - 0.33%
```
http://llvm-compile-time-tracker.com/compare.php?from=3f22e96d95c71ded906c67067d75278efb0a2525&to=ae8be4642533ff03803967ee9d7017c0d73b0ee0&stat=instructions
```
                                     New Pass Manager
                       exec instrs.   size-text
O3                       + 0.95%       - 0.25%
ReleaseThinLTO           + 1.34%       - 0.41%
ReleaseLTO-g.            + 1.71%       - 0.35%
RelThinLTO (link only)   + 0.96%       - 0.41%
RelLO-g (link only)      + 2.21%       - 0.35%
```
http://195.201.131.214:8000/compare.php?from=3f22e96d95c71ded906c67067d75278efb0a2525&to=ae8be4642533ff03803967ee9d7017c0d73b0ee0&stat=instructions

Reviewed By: asbirlea, xbolva00, nikic

Differential Revision: https://reviews.llvm.org/D87163
2020-09-10 22:24:32 +01:00
Yaxun (Sam) Liu 4934127e62 Diable sanitizer options for amdgpu
Currently AMDGPU does not support sanitizer. Disable
sanitizer options for now until they are supported.

Differential Revision: https://reviews.llvm.org/D87461
2020-09-10 15:41:07 -04:00
Fangrui Song ab1de1fcfb [gcov] Delete flush_fn_list (unused since D83149) 2020-09-10 10:15:27 -07:00
Eduardo Caldas c01d28dc51 [SyntaxTree] Specialize `TreeTestBase` for `BuildTreeTest`, `MutationsTest` and `SynthesisTest`
Differential Revision: https://reviews.llvm.org/D87374
2020-09-10 16:44:14 +00:00
Nico Weber 33c9dbbd38 Add an explicit toggle for the static analyzer in clang-tidy
Instead of using CLANG_ENABLE_STATIC_ANALYZER for use of the
static analyzer in both clang and clang-tidy, add a second
toggle CLANG_TIDY_ENABLE_STATIC_ANALYZER.

This allows enabling the static analyzer in clang-tidy while
disabling it in clang.

Differential Revison: https://reviews.llvm.org/D87118
2020-09-10 10:48:17 -04:00
Guillaume Chatelet 05d02e5a4e Fix invalid link format in Clang LanguageExtension 2020-09-10 12:27:50 +00:00
Simon Pilgrim 2239882f7d [CodeGen][X86] Move x86 builtin intrinsic/codegen tests into X86 subfolder.
There are still plenty of tests that specify x86 as a triple but most shouldn't be doing anything very target specific - we can move any ones that I have missed on a case by case basis.
2020-09-10 12:58:21 +01:00
Simon Pilgrim 576bd52f77 [Codegen][X86] Move AMX specific codegen tests into X86 subfolder. 2020-09-10 12:38:23 +01:00
Gabor Marton a97648b938 [analyzer][StdLibraryFunctionsChecker] Add better diagnostics
Differential Revision: https://reviews.llvm.org/D79431
2020-09-10 12:43:40 +02:00
Gabor Marton b7586afc4d [analyzer][StdLibraryFunctionsChecker] Remove strcasecmp
There are 2 reasons to remove strcasecmp and strncasecmp.
1) They are also modeled in CStringChecker and the related argumentum
   contraints are checked there.
2) The argument constraints are checked in CStringChecker::evalCall.
   This is fundamentally flawed, they should be checked in checkPreCall.
   Even if we set up CStringChecker as a weak dependency for
   StdLibraryFunctionsChecker then the latter reports the warning always.
   Besides, CStringChecker fails to discover the constraint violation
   before the call, so, its evalCall returns with `true` and then
   StdCLibraryFunctions also tries to evaluate, this causes an assertion
   in CheckerManager.

Either we fix CStringChecker to handle the call prerequisites in
checkPreCall, or we must not evaluate any pure functions in
StdCLibraryFunctions that are also handled in CStringChecker.
We do the latter in this patch.

Differential Revision: https://reviews.llvm.org/D87239
2020-09-10 12:29:39 +02:00
Snehasish Kumar 157cd93b48 [clang] Disallow fbasic-block-sections on non-ELF, non-x86 targets.
Basic block sections is untested on other platforms and binary formats apart
from x86,elf. This patch emits a warning and drops the flag if the platform
and binary format are not compatible. Add a test to ensure that
specifying an incompatible target in the driver does not enable the
feature.

Differential Revision: https://reviews.llvm.org/D87426
2020-09-10 00:15:33 -07:00
Mark de Wever 08196e0b2e Implements [[likely]] and [[unlikely]] in IfStmt.
This is the initial part of the implementation of the C++20 likelihood
attributes. It handles the attributes in an if statement.

Differential Revision: https://reviews.llvm.org/D85091
2020-09-09 20:48:37 +02:00
Qiu Chaofan 88ff4d2ca1 [PowerPC] Fix STRICT_FRINT/STRICT_FNEARBYINT lowering
In standard C library, both rint and nearbyint returns rounding result
in current rounding mode. But nearbyint never raises inexact exception.
On PowerPC, x(v|s)r(d|s)pic may modify FPSCR XX, raising inexact
exception. So we can't select constrained fnearbyint into xvrdpic.

One exception here is xsrqpi, which will not raise inexact exception, so
fnearbyint f128 is okay here.

Reviewed By: uweigand

Differential Revision: https://reviews.llvm.org/D87220
2020-09-09 22:40:58 +08:00
Roman Lebedev 8427885e27
Temporairly revert "Thread safety analysis: Consider global variables in scope" & followup
This appears to cause false-positives because it started to warn on local non-global variables.

Repro posted to https://reviews.llvm.org/D84604#2262745

This reverts commit 9dcc82f34e.
This reverts commit b2ce79ef66.
2020-09-09 12:15:56 +03:00
Eduardo Caldas c0e5e3fbfa [Ignore Expressions] Fix performance regression by inlining `Ignore*SingleStep`
We also add a `const` versions of `IgnoreExprNodes`

Differential Revision: https://reviews.llvm.org/D87278
2020-09-09 07:32:40 +00:00
Yaxun (Sam) Liu 041da0d828 [HIP] Add gfx1031 and gfx1030
Differential Revision: https://reviews.llvm.org/D87324
2020-09-08 16:38:34 -04:00
Saleem Abdulrasool f4ac79a364 Sema: extract a check for `isCFError` (NFC)
Extract a simple check to check if a `RecordDecl` is a `CFError` Decl.
This is a simple refactoring to prepare for an upcoming change.  NFC.

Patch is extracted from
8afaf3aad2.
2020-09-08 20:07:47 +00:00
Azharuddin Mohammed d95ef009bd Update clang/test/Driver/darwin-infer-simulator-sdkroot.c
- Fix it to work on Apple Silicon
 - Add testcases for simulators running on Apple Silicon
2020-09-08 11:27:18 -07:00
Craig Topper e6bb4c8e7b [X86] SSE4_A should only imply SSE3 not SSSE3 in the frontend.
SSE4_1 and SSE4_2 due imply SSSE3. So I guess I got confused when
switching the code to being table based in D83273.

Fixes PR47464
2020-09-08 10:50:59 -07:00
Ties Stuij d6f3f61231 Revert "[ARM] Follow AACPS standard for volatile bit-fields access width"
This reverts commit 514df1b2bb.

Some of the buildbots got llvm-lit errors on CodeGen/volatile.c
2020-09-08 18:46:27 +01:00
Ties Stuij 514df1b2bb [ARM] Follow AACPS standard for volatile bit-fields access width
This patch resumes the work of D16586.
According to the AAPCS, volatile bit-fields should
be accessed using containers of the widht of their
declarative type. In such case:
```
struct S1 {
  short a : 1;
}
```
should be accessed using load and stores of the width
(sizeof(short)), where now the compiler does only load
the minimum required width (char in this case).
However, as discussed in D16586,
that could overwrite non-volatile bit-fields, which
conflicted with C and C++ object models by creating
data race conditions that are not part of the bit-field,
e.g.
```
struct S2 {
  short a;
  int  b : 16;
}
```
Accessing `S2.b` would also access `S2.a`.

The AAPCS Release 2020Q2
(https://documentation-service.arm.com/static/5efb7fbedbdee951c1ccf186?token=)
section 8.1 Data Types, page 36, "Volatile bit-fields -
preserving number and width of container accesses" has been
updated to avoid conflict with the C++ Memory Model.
Now it reads in the note:
```
This ABI does not place any restrictions on the access widths of bit-fields where the container
overlaps with a non-bit-field member or where the container overlaps with any zero length bit-field
placed between two other bit-fields. This is because the C/C++ memory model defines these as being
separate memory locations, which can be accessed by two threads simultaneously. For this reason,
compilers must be permitted to use a narrower memory access width (including splitting the access into
multiple instructions) to avoid writing to a different memory location. For example, in
struct S { int a:24; char b; }; a write to a must not also write to the location occupied by b, this requires at least two
memory accesses in all current Arm architectures. In the same way, in struct S { int a:24; int:0; int b:8; };,
writes to a or b must not overwrite each other.
```

Patch D16586 was updated to follow such behavior by verifying that we
only change volatile bit-field access when:
 - it won't overlap with any other non-bit-field member
 - we only access memory inside the bounds of the record
 - avoid overlapping zero-length bit-fields.

Regarding the number of memory accesses, that should be preserved, that will
be implemented by D67399.

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

The following people contributed to this patch:
- Diogo Sampaio
- Ties Stuij
2020-09-08 17:49:49 +01:00
mydeveloperday c81dd3d159 [clang-format] Handle shifts within conditions
In some situation shifts can be treated as a template, and is thus formatted as one. So, by doing a couple extra checks to assure that the condition doesn't contain a template, and is in fact a bit shift should solve this problem.

This is a fix for [[ https://bugs.llvm.org/show_bug.cgi?id=46969 | bug 46969 ]]

Reviewed By: MyDeveloperDay

Patch By: Saldivarcher

Differential Revision: https://reviews.llvm.org/D86581
2020-09-08 16:40:04 +01:00
Hans Wennborg 2d9d270e77 Revert 3e782bf809 "[Sema][MSVC] warn at dynamic_cast when /GR- is given"
This caused more warnings than expected, see https://crbug.com/1126019

Also reverts the follow-up 7907e5516.

> Differential Revision: https://reviews.llvm.org/D86369
2020-09-08 16:10:18 +02:00
Haojian Wu 9c9974c3cc [clang] Limit the maximum level of fold-expr expansion.
Introduce a new diagnostic, and respect the bracket-depth (256) by default.

Differential Revision: https://reviews.llvm.org/D86936
2020-09-08 15:40:09 +02:00
Denys Petrov e674051418 [analyzer] [NFC] Introduce refactoring of PthreadLockChecker
Change capitalization of some names due to LLVM naming rules.
Change names of some variables to make them more speaking.
Rework similar bug reports into one common function.

Prepare code for the next patches to reduce unrelated changes.

Differential Revision: https://reviews.llvm.org/D87138
2020-09-08 16:04:19 +03:00
Raul Tambre 86bd8f82cc [CMake] Remove dead FindPythonInterp code
LLVM has bumped the minimum required CMake version to 3.13.4, so this has become dead code.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D87189
2020-09-08 15:23:23 +03:00
Simon Pilgrim ae85da86ad [Codegen][X86] Begin moving X86 specific codegen tests into X86 subfolder.
Discussed with @craig.topper and @spatel - this is to try and tidyup the codegen folder and move the x86 specific tests (as opposed to general tests that just happen to use x86 triples) into subfolders. Its up to other targets if they follow suit.

It also helps speed up test iterations as using wildcards on lit commands often misses some filenames.
2020-09-08 13:01:24 +01:00
Simon Pilgrim 58970eb7d1 [OpenMP] Fix typo in CodeGenFunction::EmitOMPWorksharingLoop (PR46412)
Fixes issue noticed by static analysis where we have a copy+paste typo, testing ScheduleKind.M1 twice instead of ScheduleKind.M2.

Differential Revision: https://reviews.llvm.org/D87250
2020-09-08 11:59:38 +01:00
Eduardo Caldas f5087d5c72 [SyntaxTree] Fix crash on functions with default arguments.
* Do not visit `CXXDefaultArgExpr`
* To build `CallArguments` nodes, just go through non-default arguments

Differential Revision: https://reviews.llvm.org/D87249
2020-09-08 09:49:30 +00:00
Eduardo Caldas 134455a07c [SyntaxTree] Ignore implicit `CXXFunctionalCastExpr` wrapping constructor
Differential Revision: https://reviews.llvm.org/D87229
2020-09-08 09:44:23 +00:00
Eduardo Caldas 46f4439dc9 [SyntaxTree] Ignore implicit leaf `CXXConstructExpr`
Differential Revision: https://reviews.llvm.org/D86700
2020-09-08 09:44:23 +00:00
Eduardo Caldas 2325d6b42f [SyntaxTree] Ignore implicit non-leaf `CXXConstructExpr`
Differential Revision: https://reviews.llvm.org/D86699
2020-09-08 09:44:23 +00:00
Shivanshu Goyal 2168dbf4cc getClangStripDependencyFileAdjuster(): Do not remove -M args when using MSVC cl driver
MSVC's cl.exe has a few command line arguments which start with -M such
as "-MD", "-MDd", "-MT", "-MTd", "-MP".
These arguments are not dependency file generation related, and these
arguments were being removed by getClangStripDependencyFileAdjuster()
which was wrong.

Differential revision: https://reviews.llvm.org/D86999
2020-09-08 10:21:18 +02:00
Martin Storsjö 28b9ace85f [clang] Remove a stray semicolon, fixing pedantic GCC warnings. NFC. 2020-09-08 09:26:39 +03:00
Zequan Wu 7907e5516a [Sema] fix /gr warning test case 2020-09-07 20:55:11 -07:00
Zequan Wu 3e782bf809 [Sema][MSVC] warn at dynamic_cast when /GR- is given
Differential Revision: https://reviews.llvm.org/D86369
2020-09-07 16:46:58 -07:00
Gabor Marton 8248c2af94 [analyzer][StdLibraryFunctionsChecker] Have proper weak dependencies
We want the generice StdLibraryFunctionsChecker to report only if there
are no specific checkers that would handle the argument constraint for a
function.

Note, the assumptions are still evaluated, even if the arguement
constraint checker is set to not report. This means that the assumptions
made in the generic StdLibraryFunctionsChecker should be an
over-approximation of the assumptions made in the specific checkers. But
most importantly, the assumptions should not contradict.

Differential Revision: https://reviews.llvm.org/D87240
2020-09-07 17:56:26 +02:00
Gabor Marton d01280587d [analyzer][StdLibraryFunctionsChecker] Add POSIX pthread handling functions
Differential Revision: https://reviews.llvm.org/D84415
2020-09-07 17:47:01 +02:00
Simon Pilgrim 2853ae3c1b [X86] Update SSE/AVX ABS intrinsics to emit llvm.abs.* (PR46851)
We're now getting close to having the necessary analysis/combines etc. for the new generic llvm.abs.* intrinsics.

This patch updates the SSE/AVX ABS vector intrinsics to emit the generic equivalents instead of the icmp+sub+select code pattern.

Differential Revision: https://reviews.llvm.org/D87101
2020-09-07 13:54:12 +01:00
Raphael Isemann 23f700c785 Revert "[clang] Prevent that Decl::dump on a CXXRecordDecl deserialises further declarations."
This reverts commit 0478720157. This probably
doesn't work when forcing deserialising while dumping (which the ASTDumper
optionally supports).
2020-09-07 14:50:13 +02:00
Simon Pilgrim a8a91533dd [X86] Replace EmitX86AddSubSatExpr with EmitX86BinaryIntrinsic generic helper. NFCI.
Feed the Intrinsic::ID value directly instead of via the IsSigned/IsAddition bool flags.
2020-09-07 13:33:48 +01:00
Raphael Isemann 0478720157 [clang] Prevent that Decl::dump on a CXXRecordDecl deserialises further declarations.
Decl::dump is primarily used for debugging to visualise the current state of a
declaration. Usually Decl::dump just displays the current state of the Decl and
doesn't actually change any of its state, however since commit
457226e02a the method actually started loading
additional declarations from the ExternalASTSource. This causes that calling
Decl::dump during a debugging session now actually does permanent changes to the
AST and will cause the debugged program run to deviate from the original run.

The change that caused this behaviour is the addition of
`hasConstexprDestructor` (which is called from the TextNodeDumper) which
performs a lookup into the current CXXRecordDecl to find the destructor. All
other similar methods just return their respective bit in the DefinitionData
(which obviously doesn't have such side effects).

This just changes the node printer to emit "unknown_constexpr" in case a
CXXRecordDecl is dumped that could potentially call into the ExternalASTSource
instead of the usually empty string/"constexpr". For CXXRecordDecls that can
safely be dumped the old behaviour is preserved

Reviewed By: bruno

Differential Revision: https://reviews.llvm.org/D80878
2020-09-07 12:31:30 +02:00
Eduardo Caldas 1a7a2cd747 [Ignore Expressions][NFC] Refactor to better use `IgnoreExpr.h` and nits
This change groups
* Rename: `ignoreParenBaseCasts` -> `IgnoreParenBaseCasts` for uniformity
* Rename: `IgnoreConversionOperator` -> `IgnoreConversionOperatorSingleStep` for uniformity
* Inline `IgnoreNoopCastsSingleStep` into a lambda inside `IgnoreNoopCasts`
* Refactor `IgnoreUnlessSpelledInSource` to make adequate use of `IgnoreExprNodes`

Differential Revision: https://reviews.llvm.org/D86880
2020-09-07 09:32:30 +00:00
Eduardo Caldas 81aa66f65f Extract infrastructure to ignore intermediate expressions into `clang/AST/IgnoreExpr.h`
Rationale:
This allows users to use `IgnoreExprNodes` and `Ignore*SingleStep` outside of
`clang/AST/Expr.cpp`.

Minor:
Rename `IgnoreImp...SingleStep`  into `IgnoreImplicit...SingleStep`.

Differential Revision: https://reviews.llvm.org/D86778
2020-09-07 09:32:30 +00:00
Alex Richardson 05147d3309 [clang-format] Correctly parse function declarations with TypenameMacros
When using the always break after return type setting:
Before:
SomeType funcdecl(LIST(uint64_t));
After:
SomeType
funcdecl(LIST(uint64_t));"

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D87007
2020-09-07 10:09:18 +01:00
Alex Richardson 9a22eba150 [clang-format] Parse __underlying_type(T) as a type
Before: MACRO(__underlying_type(A) * a);
After:  MACRO(__underlying_type(A) *a);

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D86960
2020-09-07 10:09:18 +01:00
Alex Richardson 56fa7d1dc6 [clang-format] Fix formatting of _Atomic() qualifier
Before: _Atomic(uint64_t) * a;
After: _Atomic(uint64_t) *a;

This treats _Atomic the same as the the TypenameMacros and decltype. It
also allows some cleanup by removing checks whether the token before a
paren is kw_decltype and instead checking for TT_TypeDeclarationParen.
While touching this code also extend the decltype test cases to also check
for typeof() and _Atomic(T).

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D86959
2020-09-07 10:09:18 +01:00
Alex Richardson cd01eec14b [clang-format] Check that */& after typename macros are pointers/references
Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D86950
2020-09-07 10:09:18 +01:00