Commit Graph

56688 Commits

Author SHA1 Message Date
Dan Gohman 812828984c [WebAssembly] Use wasm-opt and LTO libraries when available.
When there's a wasm-opt in the PATH, run the it to optimize LLVM's
output. This fixes PR43796.

And, add an "llvm-lto" directory to the sysroot library search paths,
so that sysroots can provide LTO-enabled system libraries.

Differential Revision: https://reviews.llvm.org/D70500
2019-11-22 22:16:28 -08:00
George Burgess IV 380a6452b2 [ASTMatchers] work around a miscompile; "NFC"
I chatted with Reid offline, and we agreed that having a workaround here
would be appropriate until PR43879 is resolved.

The given transformation Works On My Machine(TM), and should hopefully
hold more broadly, but my fingers are crossed nonetheless. :)
2019-11-22 20:11:16 -08:00
Duncan P. N. Exon Smith 20d51b2f14 clang/Modules: Rename CompilerInstance::ModuleManager, NFC
Fix the confusing naming of `CompilerInstance::ModuleManager`.  This is
actually an instance of `ASTReader`, which contains an instance of
`ModuleManager`.  I have to assume there was a point in the past where
they were just one class, but it's been pretty confusing for a while.  I
think it's time to fix it.

The new name is `TheASTReader`; the annoying `The` prefix is so that we
don't shadow the `ASTReader` class.  I tried out `ASTRdr` but that
seemed less clear, and this choice matches `ThePCHContainerOperations`
just a couple of declarations below.

Also rename `CompilerInstance::getModuleManager` and
`CompilerInstance::createModuleManager` to `*ASTReader`, making some
cases of `getModuleManager().getModuleManager()` a little more clear.

https://reviews.llvm.org/D70583
2019-11-22 18:24:11 -08:00
Duncan P. N. Exon Smith 5cca622310 clang/Modules: Refactor CompilerInstance::loadModule, NFC
Refactor the logic on CompilerInstance::loadModule and a couple of
surrounding methods in order to clarify what's going on.

- Rename ModuleLoader::loadModuleFromSource to compileModuleFromSource
  and fix its documentation, since it never loads a module.  It just
  creates/compiles one.
- Rename one of the overloads of compileModuleImpl to compileModule,
  making it more obvious which one calls the other.
- Rename compileAndLoadModule to compileModuleAndReadAST.  This
  clarifies the relationship between this helper and its caller,
  CompilerInstance::loadModule (the old name implied the opposite
  relationship).  It also (correctly) indicates that more needs to be
  done to load the module than this function is responsible for.
- Split findOrCompileModuleAndReadAST out of loadModule.  Besides
  reducing nesting for this code thanks to early returns and the like,
  this refactor clarifies the logic in loadModule, particularly around
  calls to ModuleMap::cacheModuleLoad and
  ModuleMap::getCachedModuleLoad.  findOrCompileModuleAndReadAST also
  breaks early if the initial ReadAST call returns Missing or OutOfDate,
  allowing the last ditch call to compileModuleAndReadAST to come at the
  end of the function body.
    - Additionally split out selectModuleSource, clarifying the logic
      due to early returns.
    - Add ModuleLoadResult::isNormal and OtherUncachedFailure, so that
      loadModule knows whether to cache the result.
      OtherUncachedFailure was added to keep this patch NFC, but there's
      a chance that these cases were uncached by accident, through
      copy/paste/modify failures.  These should be audited as a
      follow-up (maybe we can eliminate this case).
    - Do *not* lift the setting of `ModuleLoadFailed = true` to
      loadModule because there isn't a clear pattern for when it's set.
      This should be reconsidered in a follow-up, in case it would be
      correct to set `ModuleLoadFailed` whenever no module is returned
      and the result is either Normal or OtherUncachedFailure.
- Add some header documentation where it was missing, and fix it where
  it was wrong.

This should have no functionality change.

https://reviews.llvm.org/D70556
2019-11-22 18:23:47 -08:00
David Blaikie e956952ede DebugInfo: Flag Dwarf Version metadata for merging during LTO
When the Dwarf Version metadata was initially added (r184276) there was
no support for Module::Max - though the comment suggested that was the
desired behavior. The original behavior was Module::Warn which would
warn and then pick whichever version came first - which is pretty
arbitrary/luck-based if the consumer has some need for one version or
the other.

Now that the functionality's been added (r303590) this change updates
the implementation to match the desired goal.

The general logic here is - if you compile /some/ of your program with a
more recent DWARF version, you must have a consumer that can handle it,
so might as well use it for /everything/.

The only place where this might fall down is if you have a need to use
an old tool (supporting only the older DWARF version) for some subset of
your program. In which case now it'll all be the higher version. That
seems pretty narrow (& the inverse could happen too - you specifically
/need/ the higher DWARF version for some extra expressivity, etc, in
some part of the program)
2019-11-22 17:16:35 -08:00
Reid Kleckner a9cc64e50e Separate the MS inheritance model enum from the attribute, NFC
This avoids the need to include Attr.h in DeclCXX.h for a four-value
enum. Removing the include will be done separately, since it is large
and risky change.
2019-11-22 16:06:30 -08:00
Reid Kleckner 2692eb0b86 Move vtordisp mode from Attr class to LangOptions.h, NFC
This removes one of the two uses of Attr.h in DeclCXX.h, reducing the
need to include Attr.h as widely. LangOptions is already very popular.
2019-11-22 15:47:46 -08:00
Josh Kunz 6551ac7489 [Driver] Make -static-libgcc imply static libunwind
In the GNU toolchain, `-static-libgcc` implies that the unwindlib will
be linked statically. However, when `--unwindlib=libunwind`, this flag is
ignored, and a bare `-lunwind` is added to the linker args.  Unfortunately,
this means that if both `libunwind.so`, and `libunwind.a` are present
in the library path, `libunwind.so` will be chosen in all cases where
`-static` is not set.

This change makes `-static-libgcc` affect the `-l` flag produced by
`--unwindlib=libunwind`. After this patch, providing
`-static-libgcc --unwindlib=libunwind` will cause the driver to explicitly
emit `-l:libunwind.a` to statically link libunwind. For all other cases
it will emit `-l:libunwind.so` matching current behavior with a more
explicit link line.

https://reviews.llvm.org/D70416
2019-11-22 15:33:13 -08:00
Akira Hatanaka 825235c140 Revert "[Sema] Use the canonical type in function isVector"
This reverts commit a6150b48ce.
The commit broke a few neon CodeGen tests.
2019-11-22 13:48:39 -08:00
Dávid Bolvanský 9353c5dd06 [Diagnostics] Put "deprecated copy" warnings into -Wdeprecated-copy
Summary:
GCC 9 added -Wdeprecated-copy (as part of -Wextra). This diagnostic is already implemented in Clang too, just hidden under -Wdeprecated (not on by default).
This patch adds -Wdeprecated-copy and makes it compatible with GCC 9+.
This diagnostic is heavily tested in deprecated.cpp, so I added simple tests just to check we warn when new flag/-Wextra is enabled.

Reviewers: rsmith, dblaikie

Reviewed By: dblaikie

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70342
2019-11-22 22:37:19 +01:00
Akira Hatanaka a6150b48ce [Sema] Use the canonical type in function isVector
This fixes an assertion in Sema::CreateBuiltinBinOp that fails when one
of the vector operand's element type is a typedef of __fp16.

rdar://problem/55983556
2019-11-22 12:57:24 -08:00
Bill Wendling 9180f8a574 Don't report "main" as missing a prototype in freestanding mode
Summary:
A user may want to use freestanding mode with the standard "main" entry
point. It's not useful to warn about a missing prototype as it's not
typical to have a prototype for "main".

Reviewers: efriedma, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: aaron.ballman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70588
2019-11-22 12:35:43 -08:00
Edward Jones e0f22fe04a [RISCV] Use compiler-rt if no GCC installation detected
If a GCC installation is not detected, then this attempts to
use compiler-rt and the compiler-rt crtbegin/crtend
implementations as a fallback.

Differential Revision: https://reviews.llvm.org/D68407
2019-11-22 20:05:29 +00:00
Yitzhak Mandelbaum 01e8dd2e7a [libTooling] Add stencil combinators for nodes that may be pointers or values.
Summary:
Adds combinators `maybeDeref` and `maybeAddressOf` to provide a uniform way to handle
nodes which may be bound to either a pointer or a value (most often in the
context of member expressions). Such polymorphism is already supported by
`access`; these combinators extend it to more general uses.

Reviewers: gribozavr

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70554
2019-11-22 12:36:40 -05:00
Alexey Bataev 5459a905c2 [OPENMP]Simplify processing of context selectors, NFC. 2019-11-22 11:53:06 -05:00
Brian Gesiak 0b3d1d1348 [coroutines] Remove assert on CoroutineParameterMoves in Sema::buildCoroutineParameterMoves
Summary:
The assertion of CoroutineParameterMoves happens when build coroutine function with arguments  multiple time while fails to build promise type.

Fix: use return false instead.

Test Plan: check-clang

Reviewers: modocache, GorNishanov, rjmccall

Reviewed By: modocache

Subscribers: rjmccall, EricWF, cfe-commits

Tags: #clang

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

Patch by junparser (JunMa)!
2019-11-22 11:39:13 -05:00
Alexey Bataev 6f7c8760a5 [OPENMP]Fix behaviour of defaultmap for OpenMP 4.5.
In OpenMP 4.5 pointers also must be considered as scalar types and
defaultmap(tofrom:scalar) clause must affect mapping of the pointers
too.
2019-11-22 11:26:09 -05:00
Kirill Bobyrev 7f0dcf665d
[clangd] Show lambda signature for lambda autocompletions
The original bug report can be found
[here](https://github.com/clangd/clangd/issues/85)

Given the following code:

```c++
void function() {
  auto Lambda = [](int a, double &b) {return 1.f;};
  La^
}
```

Triggering the completion at `^` would show `(lambda)` before this patch
and would show signature `(int a, double &b) const`, build a snippet etc
with this patch.

Reviewers: sammccall

Reviewed by: sammccall

Differential revision: https://reviews.llvm.org/D70445
2019-11-22 12:48:06 +01:00
Artem Dergachev a3b22da4e0 [CFG] Fix a flaky crash in CFGBlock::getLastCondition().
Using an end iterator of an empty CFG block was causing
a garbage pointer dereference.

Differential Revision: https://reviews.llvm.org/D69962
2019-11-21 21:55:58 -08:00
Zakk Chen 4fccd383d5 [RISCV] Support mutilib in baremetal environment
1. Currently only support the set of multilibs same to riscv-gnu-toolchain.
2. Fix testcase typo causes fail on Windows.
3. Fix testcases to set empty sysroot.

Reviewers: espindola, asb, kito-cheng, lenary

Reviewed By: lenary

Differential Revision: https://reviews.llvm.org/D67508
2019-11-21 19:58:21 -08:00
Duncan P. N. Exon Smith f7170d17a8 clang/Modules: Move Serialization/Module.{h,cpp} to ModuleFile, NFC
Remove some cognitive load by renaming clang/Serialization/Module.h to
clang/Serialization/ModuleFile.h, since it declares the ModuleFile
class.  This also makes editing a bit easier, since the basename of the
file no long conflicts with clang/Basic/Module.h, which declares the
Module class.  Also move lib/Serialization/Module.cpp to
lib/Serialization/ModuleFile.cpp.
2019-11-21 19:07:00 -08:00
Artem Dergachev 0b58b80edb [analyzer] Fix Objective-C accessor body farms after 2073dd2d.
Fix a canonicalization problem for the newly added property accessor stubs that
was causing a wrong decl to be used for 'self' in the accessor's body farm.

Fix a crash when constructing a body farm for accessors of a property
that is declared and @synthesize'd in different (but related) interfaces.

Differential Revision: https://reviews.llvm.org/D70158
2019-11-21 18:59:46 -08:00
Artem Dergachev bbc8662db1 [analyzer] NFC: Don't clean up range constraints twice.
Slightly improves static analysis speed.

Differential Revision: https://reviews.llvm.org/D70150
2019-11-21 18:59:46 -08:00
Petr Hosek 68a3a3b281 [Clang] Enable RISC-V support for Fuchsia
We don't have a full sysroot yet, so for now we only include compiler
support and compiler-rt builtins, the rest of the runtimes will get
enabled later.

Differential Revision: https://reviews.llvm.org/D70477
2019-11-21 16:02:26 -08:00
Alexey Bataev f8ff3d7ebd [OPENMP]Remove unused template parameter, NFC. 2019-11-21 16:42:26 -05:00
Stefan Pintilie 5fcf89f778 [PowerPC] Add new Future CPU for PowerPC
This patch will add -mcpu=future into clang for PowerPC.

A CPU type is required for work that may possibly be enabled for some future
Power CPU. The CPU type future will serve that purpose. This patch introduces
no new functionality. It is an incremental patch on top of which Power PC work
for some future CPU can be done.

Differential Revision: https://reviews.llvm.org/D70262
2019-11-21 13:35:48 -06:00
Adrian Prantl e0cabe280b Debug info: Emit objc_direct methods as members of their containing class
even in DWARF 4 and earlier. This allows the debugger to recognize
them as direct functions as opposed to Objective-C methods.

<rdar://problem/57327663>

Differential Revision: https://reviews.llvm.org/D70544
2019-11-21 11:01:10 -08:00
Alexey Bataev 4e8231b5cf [OPENMP50]Add device/kind context selector support.
Summary: Added basic parsing/sema support for device/kind context selector.

Reviewers: jdoerfert

Subscribers: rampitec, aheejin, fedor.sergeev, simoncook, guansong, s.egerton, hfinkel, kkwli0, caomhin, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70245
2019-11-21 13:28:11 -05:00
Michael Liao c4afc6566a Fix compilation warning. NFC. 2019-11-21 12:07:13 -05:00
Alexey Bataev 77d049d0c6 [OPENMP]Fix datasharing checks for if clause in parallel taskloop
directives.

If the default datasharing is set to none, the datasharing attributes
for variables in the condition of the if clause for the inner taskloop
  directive must be verified.
2019-11-21 11:20:38 -05:00
Alexey Bataev 103f3c9e3b [OPENMP50]Add if clause in for simd directive.
According to OpenMP 5.0, if clause can be used in for simd directive. If
condition in the if clause if false, the non-vectorized version of the
loop must be executed.
2019-11-21 09:29:12 -05:00
Ehud Katz c63f1b160e [DeclCXX] Remove unknown external linkage specifications
Partial revert of r372681 "Support for DWARF-5 C++ language tags".

The change introduced new external linkage languages ("C++11" and
"C++14") which not supported in C++.

It also changed the definition of the existing enum to use the DWARF
constants. The problem is that "LinkageSpecDeclBits.Language" (the field
that reserves this enum) is actually defined as 3 bits length
(bitfield), which cannot contain the new DWARF constants. Defining the
enum as integer literals is more appropriate for maintaining valid
values.

Differential Revision: https://reviews.llvm.org/D69935
2019-11-21 15:23:05 +02:00
Zakk Chen bdb1f1dcb9 Revert "[RISCV] Support mutilib in baremetal environment"
This reverts commit df876a0269.
Clang::riscv32-toolchain.c Clang::riscv64-toolchain.c fails on Windows.
2019-11-21 04:34:56 -08:00
Ilya Biryukov aa981c1802 Reland 9f3fdb0d7fab: [Driver] Use VFS to check if sanitizer blacklists exist
With updates to various LLVM tools that use SpecialCastList.

It was tempting to use RealFileSystem as the default, but that makes it
too easy to accidentally forget passing VFS in clang code.
2019-11-21 11:56:09 +01:00
Sven van Haastregt 35388dcbbc [OpenCL] Fix address space for base method call (PR43145)
Clang was creating an UncheckedDerivedToBase ImplicitCastExpr that was
also casting between address spaces.  Insert an ImplicitCastExpr node
for doing the address space conversion.

Differential Revision: https://reviews.llvm.org/D69810
2019-11-21 10:39:33 +00:00
Tim Northover 5cf58768cb Atomics: support min/max orthogonally
We seem to have been gradually growing support for atomic min/max operations
(exposing longstanding IR atomicrmw instructions). But until now there have
been gaps in the expected intrinsics. This adds support for the C11-style
intrinsics (i.e. taking _Atomic, rather than individually blessed by C11
standard), and the variants that return the new value instead of the original
one.

That way, people won't be misled by trying one form and it not working, and the
front-end is more friendly to people using _Atomic types, as we recommend.
2019-11-21 10:37:56 +00:00
Ilya Biryukov 9f3fdb0d7f Revert "[Driver] Use VFS to check if sanitizer blacklists exist"
This reverts commit ba6f906854.
Commit caused compilation errors on llvm tests. Will fix and re-land.
2019-11-21 11:31:14 +01:00
Ilya Biryukov ba6f906854 [Driver] Use VFS to check if sanitizer blacklists exist
Summary:
This is a follow-up to 590f279c45, which
moved some of the callers to use VFS.

It turned out more code in Driver calls into real filesystem APIs and
also needs an update.

Reviewers: gribozavr2, kadircet

Reviewed By: kadircet

Subscribers: ormris, mgorny, hiraditya, llvm-commits, jkorous, cfe-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D70440
2019-11-21 11:00:30 +01:00
Zakk Chen df876a0269 [RISCV] Support mutilib in baremetal environment
1. Currently only support the set of multilibs same to riscv-gnu-toolchain.
2. Fix testcase typo causes fail on Windows

Reviewers: espindola, asb, kito-cheng, lenary

Reviewed By: lenary

Differential Revision: https://reviews.llvm.org/D67508
2019-11-21 01:13:41 -08:00
Puyan Lotfi fec3ca77bb [clang][IFS][test] GreenDragon and Fuchsia Darwin bot fix: BindArchClass Nest.
On Darwin the clang driver does not invoke Driver::BuildActions directly
due to the need to handle Universal apps. Because of this there is a
difference in code path where Driver::BuildUniversalActions is called
instead of Driver::BuildActions. BuildUniversalActions ends up calling
Driver::BuildAction but what it does differently is it takes the driver
actions returned and wraps them each into a BindArchAction.

In Driver::BuildJobs there is a check for '-o' to determine that
multiple files are not specified when passing -o, except for Clang
Interface Stub this need to be an exception as we actually want to write
out multiple files: for every libfoo.so we have a libfoo.ifso sidecar
ifso file, etc. To allow this to happen there is a check for
IfsMergeAction, which is permitted to write out a secondary file. Except
on Darwin, the IfsMergeAction gets wrapped in the BindArchAction by
Driver::BuildUniversalActions so the check fails.

This patch is to look inside a BindArchAction in Driver::BuildJobs to
determine if there is in fact an IfsMergeAction, and if-so (pun intended)
allow the secondary sidecard ifs/ifso file to be written out.
2019-11-20 22:12:28 -05:00
Erik Pilkington d9957c7405 [Sema] Add a 'Semantic' parameter to Expr::isKnownToHaveBooleanValue
Some clients of this function want to know about any expression that is known
to produce a 0/1 value, and others care about expressions that are semantically
boolean.

This fixes a -Wswitch-bool regression I introduced in 8bfb353bb3, pointed out
by Chris Hamilton!
2019-11-20 16:29:31 -08:00
Puyan Lotfi 73429126c9 [clang][IFS] Driver Pipeline: generate stubs after standard pipeline (3)
Third Landing Attempt (dropping any linker invocation from clang driver):

Up until now, clang interface stubs has replaced the standard
PP -> C -> BE -> ASM -> LNK pipeline. With this change, it will happen in
conjunction with it. So what when you build your code you will get an
a.out or lib.so as well as an interface stub file.

Example:

clang -shared -o libfoo.so -emit-interface-stubs ...

will generate both a libfoo.so and a libfoo.ifso. The .so file will
contain the code from the standard compilation pipeline and the .ifso
file will contain the ELF stub library.

Note: For driver-test.c I've added -S in order to prevent any bot failures on
bots that don't have the proper linker for their native triple. You could always
specify a triple like x86_64-unknown-linux-gnu and on bots like x86_64-scei-ps4
the clang driver would invoke regular ld instead of getting the error
'Executable "orbis-ld" doesn't exist!' but on bots like ppc64be and s390x you'd
get an error "/usr/bin/ld: unrecognised emulation mode: elf_x86_64"

Differential Revision: https://reviews.llvm.org/D70274
2019-11-20 16:22:50 -05:00
Richard Smith fd8d9155a9 Fix parser bug that permitted 'private' as a (no-op) decl-specifier even outside OpenCL. 2019-11-20 11:59:58 -08:00
Tim Northover e23d6f3184 NeonEmitter: remove special case on casting polymorphic builtins.
For some reason we were not casting a fairly obscure class of builtin calls we
expected to be polymorphic to vectors of char. It worked because the only
affected intrinsics weren't actually polymorphic after all, but is
unnecessarily complicated.
2019-11-20 13:20:02 +00:00
Djordje Todorovic ce1f95a6e0 Reland "[clang] Remove the DIFlagArgumentNotModified debug info flag"
It turns out that the ExprMutationAnalyzer can be very slow when AST
gets huge in some cases. The idea is to move this analysis to the LLVM
back-end level (more precisely, in the LiveDebugValues pass). The new
approach will remove the performance regression, simplify the
implementation and give us front-end independent implementation.

Differential Revision: https://reviews.llvm.org/D68206
2019-11-20 10:08:07 +01:00
Puyan Lotfi 9059854355 Revert "[clang][IFS] Driver Pipeline: generate stubs after standard pipeline (2)"
This reverts commit ea8e028223.
2019-11-19 21:59:50 -05:00
Duncan P. N. Exon Smith 8700831734 clang/Modules: Early return in CompilerInstance::createModuleManager, NFC
Reduce nesting with an early `return`.
2019-11-19 18:16:23 -08:00
Duncan P. N. Exon Smith 69242e9868 clang/Modules: Sink ASTReadResult in ReadControlBlock, NFC
Simplify the code by avoiding some state that wasn't being used.  The
function-level `Result` was only assigned a value other than `Success`
in the handler for `OPTIONS_BLOCK_ID`, but in that case it also hits an
early return.  Remove it at the function-level to make it obvious that
the normal case always returns `Success`.
2019-11-19 16:10:44 -08:00
Puyan Lotfi ea8e028223 [clang][IFS] Driver Pipeline: generate stubs after standard pipeline (2)
Second Landing Attempt:

Up until now, clang interface stubs has replaced the standard
PP -> C -> BE -> ASM -> LNK pipeline. With this change, it will happen in
conjunction with it. So what when you build your code you will get an
a.out or lib.so as well as an interface stub file.

Example:

clang -shared -o libfoo.so -emit-interface-stubs ...

will generate both a libfoo.so and a libfoo.ifso. The .so file will
contain the code from the standard compilation pipeline and the .ifso
file will contain the ELF stub library.

Differential Revision: https://reviews.llvm.org/D70274
2019-11-19 17:47:38 -05:00
Alexey Bataev d08c056695 [OPENMP50]Add if clause in simd directive.
According to OpenMP 5.0, if clause can be used in simd directive. If
condition in the if clause if false, the non-vectorized version of the
loop must be executed.
2019-11-19 15:58:19 -05:00
Vedant Kumar 568db780bb [CGDebugInfo] Emit subprograms for decls when AT_tail_call is understood (reland with fixes)
Currently, clang emits subprograms for declared functions when the
target debugger or DWARF standard is known to support entry values
(DW_OP_entry_value & the GNU equivalent).

Treat DW_AT_tail_call the same way to allow debuggers to follow cross-TU
tail calls.

Pre-patch debug session with a cross-TU tail call:

```
  * frame #0: 0x0000000100000fa4 main`target at b.c:4:3 [opt]
    frame #1: 0x0000000100000f99 main`main at a.c:8:10 [opt]
```

Post-patch (note that the tail-calling frame, "helper", is visible):

```
  * frame #0: 0x0000000100000fa4 main`target at b.c:4:3 [opt]
    frame #1: 0x0000000100000f80 main`helper [opt] [artificial]
    frame #2: 0x0000000100000f99 main`main at a.c:8:10 [opt]
```

This was reverted in 5b9a072c because it attached declaration
subprograms to inlinable builtin calls, which interacted badly with the
MergeICmps pass. The fix is to not attach declarations to builtins.

rdar://46577651

Differential Revision: https://reviews.llvm.org/D69743
2019-11-19 12:49:27 -08:00
Reid Kleckner 586f65d31f Add a key method to Sema to optimize debug info size
It turns out that the debug info describing the Sema class is an
appreciable percentage of the total object file size of objects in Sema.
By adding a key function, clang is able to optimize the debug info size
by emitting a forward declaration in TUs that do not define the key
function.

On Windows, with clang-cl, these are the total sizes of object files in
Sema before and after this change, compiling with optimizations and
debug info:
  before: 335,012 KB
  after:  278,116 KB
  delta:  -56,896 KB
  percent: -17.0%

The effect on link time was negligible, despite having ~56MB less input.

On Linux, with clang, these are the same sizes using DWARF -g and
optimizations:
  before: 603,756 KB
  after:  515,340 KB
  delta:  -88,416 KB
  percent: -14.6%

I didn't use type units, DWARF-5, fission, or any other special flags.

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D70340
2019-11-19 12:42:33 -08:00
Tyker c444a01df3 fixe leak found by asan build bot 2019-11-19 21:11:37 +01:00
Matt Arsenault e531750c6c clang: Add -fconvergent-functions flag
The CUDA builtin library is apparently compiled in C++ mode, so the
assumption of convergent needs to be made in a typically non-SPMD
language. The functions in the library should still be assumed
convergent. Currently they are not, which is potentially incorrect and
this happens to work after the library is linked.
2019-11-19 23:20:15 +05:30
Alexey Bataev 1d943ae44c [OPENMP]Rename function, NFC.
Change the name of the CGOpenMPRuntime::emitOMPIfClause to CGOpenMPRuntime::emitIfClause.
2019-11-19 12:27:10 -05:00
Tyker b0561b3346 [NFC] Refactor representation of materialized temporaries
Summary:
this patch refactor representation of materialized temporaries to prevent an issue raised by rsmith in https://reviews.llvm.org/D63640#inline-612718

Reviewers: rsmith, martong, shafik

Reviewed By: rsmith

Subscribers: thakis, sammccall, ilya-biryukov, rnkovacs, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69360
2019-11-19 18:20:45 +01:00
Yitzhak Mandelbaum dd471dbe99 [libTooling] Extend `buildASTFromCodeWithArgs` to take files argument.
Summary:
Adds an optional parameter to `buildASTFromCodeWithArgs` that allows the user to
pass additional files that the main code needs to compile. This change makes
`buildASTFromCodeWithArgs` consistent with `runToolOnCodeWithArgs`.

Patch by Alexey Eremin.

Reviewers: gribozavr

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70175
2019-11-19 12:18:36 -05:00
Matt Arsenault 7fe9435dc8 Work on cleaning up denormal mode handling
Cleanup handling of the denormal-fp-math attribute. Consolidate places
checking the allowed names in one place.

This is in preparation for introducing FP type specific variants of
the denormal-fp-mode attribute. AMDGPU will switch to using this in
place of the current hacky use of subtarget features for the denormal
mode.

Introduce a new header for dealing with FP modes. The constrained
intrinsic classes define related enums that should also be moved into
this header for uses in other contexts.

The verifier could use a check to make sure the denorm-fp-mode
attribute is sane, but there currently isn't one.

Currently, DAGCombiner incorrectly asssumes non-IEEE behavior by
default in the one current user. Clang must be taught to start
emitting this attribute by default to avoid regressions when this is
switched to assume ieee behavior if the attribute isn't present.
2019-11-19 22:01:14 +05:30
Thomas Preud'homme b81cc60329 [clang][NFC] Make various uses of Regex const
The const-correctness of match() was fixed in rL372764, which allows
uses of Regex objects to be const in cases they couldn't be before. This
patch tightens up the const-ness of Regex in various such cases.

Reviewers: thopre

Reviewed By: thopre

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68155
2019-11-19 16:15:21 +00:00
Nico Weber 3de7cc9fc0 Revert "[RISCV] Support mutilib in baremetal environment"
This reverts commit b6d7bbfa00.
Driver/riscv64-toolchain.c fails on Windows.
2019-11-19 08:16:55 -05:00
Zakk Chen b6d7bbfa00 [RISCV] Support mutilib in baremetal environment
Currently only support the set of multilibs same to riscv-gnu-toolchain.

Reviewers: espindola, asb, kito-cheng, lenary

Reviewed By: lenary

Differential Revision: https://reviews.llvm.org/D67508
2019-11-19 02:10:39 -08:00
Puyan Lotfi d044dcc5e4 Revert "[clang][IFS] Driver pipeline: generate interface stubs after standard pipeline."
This reverts commit 58ea00b51f.

Test for .o + .ifs sidecar files is brittle and failing on bots.
Reverting to unblock.
2019-11-19 02:08:22 -05:00
Puyan Lotfi 58ea00b51f [clang][IFS] Driver pipeline: generate interface stubs after standard pipeline.
Up until now, clang interface stubs has replaced the standard
PP -> C -> BE -> ASM -> LNK pipeline. With this change, it will happen in
conjunction with it. So what when you build your code you will get an
a.out or lib.so as well as an interface stub file.

Example:

clang -shared -o libfoo.so -emit-interface-stubs ...

will generate both a libfoo.so and a libfoo.ifso. The .so file will
contain the code from the standard compilation pipeline and the .ifso
file will contain the ELF stub library.

Differential Revision: https://reviews.llvm.org/D70274
2019-11-19 01:18:02 -05:00
Vedant Kumar ea1db31d20 [CodeGen] Assign locations to calls to special struct helpers
Assign artificial locations to calls to special struct-related helper
functions.

Such calls may not inherit a location if emitted within FinishFunction,
at which point the lexical scope stack may be empty, causing CGDebugInfo
to report the current DebugLoc as empty.

Fixes an IR verifier complaint about a call to '__destructor_8_s0' not
having a !dbg location attached.

rdar://57293361
2019-11-18 15:07:59 -08:00
Erich Keane 0213adde21 [NFC] Fix 'target' condition in checkTargetFeatures
checkTargetFeatures was incorrectly checking for cpu_specific instead of
just 'target'. While this function was never called in that situation,
it seemed correct to fix the condition.  Additionally, multiversion
functions can never be always_inline, but if any function accidentially
ended up here we shouldn't diagnose.

Note that the adding of target-features to the list is unnecessary since
the getFunctionFeatureMap actually considers attribute target,
however adding it results in significantly better error messages by
putting the 'target' features first (and thus first to fail).
Otherwise, the error message would be the first feature 'implied' by the
target attribute, and not necessarily the feature listed in the
attribute itself.
2019-11-18 13:43:52 -08:00
Dimitry Andric ee31adb7fa Populate CUDA flags on FreeBSD too, as many other toolchains do.
Summary:
This allows `clang` to be used to compile CUDA programs. Compiled
simple helloworld.cu with this.

Reviewers: dim, emaste, tra, yaxunl, ABataev

Reviewed By: tra

Subscribers: dim, emaste, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69990
2019-11-18 21:54:25 +01:00
Erik Pilkington 8bfb353bb3 [Sema] Fix a -Wobjc-signed-char-bool false-positive
Unsigned bit-field flags can only have boolean values, so handle that case in
Expr::isKnownToHaveBooleanValue.

rdar://56256999
2019-11-18 12:15:20 -08:00
Pierre Habouzit d4e1ba3fa9 Implement __attribute__((objc_direct)), __attribute__((objc_direct_members))
__attribute__((objc_direct)) is an attribute on methods declaration, and
__attribute__((objc_direct_members)) on implementation, categories or
extensions.

A `direct` property specifier is added (@property(direct) type name)

These attributes / specifiers cause the method to have no associated
Objective-C metadata (for the property or the method itself), and the
calling convention to be a direct C function call.

The symbol for the method has enforced hidden visibility and such direct
calls are hence unreachable cross image. An explicit C function must be
made if so desired to wrap them.

The implicit `self` and `_cmd` arguments are preserved, however to
maintain compatibility with the usual `objc_msgSend` semantics,
3 fundamental precautions are taken:

1) for instance methods, `self` is nil-checked. On arm64 backends this
   typically adds a single instruction (cbz x0, <closest-ret>) to the
   codegen, for the vast majority of the cases when the return type is a
   scalar.

2) for class methods, because the class may not be realized/initialized
   yet, a call to `[self self]` is emitted. When the proper deployment
   target is used, this is optimized to `objc_opt_self(self)`.

   However, long term we might want to emit something better that the
   optimizer can reason about. When inlining kicks in, these calls
   aren't optimized away as the optimizer has no idea that a single call
   is really necessary.

3) the calling convention for the `_cmd` argument is changed: the caller
   leaves the second argument to the call undefined, and the selector is
   loaded inside the body when it's referenced only.

As far as error reporting goes, the compiler refuses:
- making any overloads direct,
- making an overload of a direct method,
- implementations marked as direct when the declaration in the
  interface isn't (the other way around is allowed, as the direct
  attribute is inherited from the declaration),
- marking methods required for protocol conformance as direct,
- messaging an unqualified `id` with a direct method,
- forming any @selector() expression with only direct selectors.

As warnings:
- any inconsistency of direct-related calling convention when
  @selector() or messaging is used,
- forming any @selector() expression with a possibly direct selector.

Lastly an `objc_direct_members` attribute is added that can decorate
`@implementation` blocks and causes methods only declared there (and in
no `@interface`) to be automatically direct. When decorating an
`@interface` then all methods and properties declared in this block are
marked direct.

Radar-ID: rdar://problem/2684889
Differential Revision: https://reviews.llvm.org/D69991
Reviewed-By: John McCall
2019-11-18 11:48:40 -08:00
Francis Visoiu Mistrih e15b26fbbd Reland: [Remarks][Driver] Use different remark files when targeting multiple architectures
When the driver is targeting multiple architectures at once, for things
like Universal Mach-Os, we need to emit different remark files for each
cc1 invocation to avoid overwriting the files from a different
invocation.

For example:

$ clang -c -o foo.o -fsave-optimization-record -arch x86_64 -arch x86_64h

will create two remark files:

* foo-x86_64.opt.yaml
* foo-x86_64h.opt.yaml
2019-11-18 11:17:38 -08:00
Reid Kleckner 1ff5f0ced3 Revert "[Remarks][Driver] Use different remark files when targeting multiple architectures"
This reverts commit b4e2b112b5.

Test doesn't appear to pass on Windows, maybe all non-Mac.
2019-11-18 10:52:41 -08:00
Eric Christopher 30e7ee3c4b Temporarily Revert "Add support for options -frounding-math, ftrapping-math, -ffp-model=, and -ffp-exception-behavior="
and a follow-up NFC rearrangement as it's causing a crash on valid. Testcase is on the original review thread.

This reverts commits af57dbf12e and e6584b2b7b
2019-11-18 10:46:48 -08:00
Reid Kleckner a77b66a056 Allocate builtins table earlier to fix bug found by ubsan
Follow up to 979da9a4c3
2019-11-18 10:41:30 -08:00
Francis Visoiu Mistrih b4e2b112b5 [Remarks][Driver] Use different remark files when targeting multiple architectures
When the driver is targeting multiple architectures at once, for things
like Universal Mach-Os, we need to emit different remark files for each
cc1 invocation to avoid overwriting the files from a different
invocation.

For example:

$ clang -c -o foo.o -fsave-optimization-record -arch x86_64 -arch x86_64h

will create two remark files:

* foo-x86_64.opt.yaml
* foo-x86_64h.opt.yaml
2019-11-18 10:38:10 -08:00
Joel E. Denny c85fa79d36 [Attr] Fix `-ast-print` for `asm` attribute
Without this fix, the tests introduced here produce the following
assert fail:

```
clang: /home/jdenny/llvm/clang/include/clang/Basic/AttributeCommonInfo.h:163: unsigned int clang::AttributeCommonInfo::getAttributeSpellingListIndex() const: Assertion `(isAttributeSpellingListCalculated() || AttrName) && "Spelling cannot be found"' failed.
```

The bug was introduced by D67368, which caused `AsmLabelAttr`'s
spelling index to be set to `SpellingNotCalculated`.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D70349
2019-11-18 11:55:25 -05:00
Alexey Bataev c3eded068c [OPENMP50]Fix PR44024: runtime assert in distribute construct.
If the code is emitted for distribute construct, the nonmonotonic
modifier should not be added.
2019-11-18 11:14:27 -05:00
Sam McCall d27a16eb39 Revert "[DWARF5]Addition of alignment atrribute in typedef DIE."
This reverts commit 423f541c1a, which
breaks llvm-c ABI.
2019-11-18 15:53:22 +01:00
Simon Pilgrim 1e3cc06d98 Fix "not all control paths return a value" warning. NFCI. 2019-11-18 11:42:14 +00:00
Simon Cook c00e5cf29d [RISCV] Set triple based on -march flag
For RISC-V the value provided to -march should determine whether to
compile for 32- or 64-bit RISC-V irrespective of the target provided to
the Clang driver. This adds a test for this flag for RISC-V and sets the
Target architecture correctly in these cases.

Differential Revision: https://reviews.llvm.org/D54214
2019-11-18 10:44:24 +00:00
Simon Tatham 4a4dd85e5a [ARM,MVE] Add intrinsics for vector comparisons.
This adds the `vcmp` family of ACLE MVE intrinsics: vector/vector,
vector/scalar, and the predicated forms of both. All are represented
using standard existing IR: vector/scalar comparisons are represented
by making a vector out of the scalar first, and predicated forms are
represented by taking the bitwise AND of the input predicate and the
output of the comparison. Existing LLVM-side tests demonstrate that
ISel will pattern-match all of that back down to single MVE VCMPs.

The idiom of handling a vector/scalar operation by generating IR to
expand the scalar into a second vector is going to be needed for a lot
of MVE intrinsics, so to make that easy, I've provided a helper
function that automatically works out the element count.

The comparison intrinsics are the first ones that have to //return// a
predicate, in the user-facing `mve_pred16_t` format. This means we
have to use the `arm_mve_pred_v2i` low-level intrinsic to convert it
back from the logical `<n x i1>` form used in IR. I've done that
explicitly in the code gen specification for the builtins, because it
happens much more rarely in the ACLE API than passing a Predicate as
input, so it didn't seem worth automating in MveEmitter.

Reviewers: ostannard, MarkMurrayARM, dmgreen

Reviewed By: dmgreen

Subscribers: kristof.beyls, hiraditya, cfe-commits, llvm-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D70297
2019-11-18 10:39:30 +00:00
Sam McCall a433e7141f [AST] Attach comment in `/** doc */ typedef struct A {} B` to B as well as A.
Summary:
Semantically they're the same thing, and it's important when the underlying
struct is anonymous.

There doesn't seem to be a problem attaching the same comment to multiple things
as it already happens with `/** doc */ int a, b;`

This affects an Index test but the results look better (name present, USR points
to the typedef).

Fixes https://github.com/clangd/clangd/issues/189

Reviewers: kadircet, lh123

Subscribers: ilya-biryukov, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70203
2019-11-18 11:09:23 +01:00
Anna Welker 2d739f98d8 [ARM] Allocatable Global Register Variables for ARM
Provides support for using r6-r11 as globally scoped
      register variables. This requires a -ffixed-rN flag
      in order to reserve rN against general allocation.

      If for a given GRV declaration the corresponding flag
      is not found, or the the register in question is the
      target's FP, we fail with a diagnostic.

      Differential Revision: https://reviews.llvm.org/D68862
2019-11-18 10:07:37 +00:00
Nico Weber c9276fbfdf Revert "[NFC] Refactor representation of materialized temporaries"
This reverts commit 08ea1ee2db.
It broke ./ClangdTests/FindExplicitReferencesTest.All
on the bots, see comments on https://reviews.llvm.org/D69360
2019-11-17 02:09:25 -05:00
Tyker 08ea1ee2db [NFC] Refactor representation of materialized temporaries
Summary:
this patch refactor representation of materialized temporaries to prevent an issue raised by rsmith in https://reviews.llvm.org/D63640#inline-612718

Reviewers: rsmith, martong, shafik

Reviewed By: rsmith

Subscribers: rnkovacs, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69360
2019-11-16 17:56:09 +01:00
Sourabh Singh Tomar 423f541c1a [DWARF5]Addition of alignment atrribute in typedef DIE.
This patch, adds support for DW_AT_alignment[DWARF5] attribute, to be emitted with typdef DIE.
When explicit alignment is specified.

Patch by Awanish Pandey <Awanish.Pandey@amd.com>

Reviewers: aprantl, dblaikie, jini.susan.george, SouraVX, alok,
deadalinx

Differential Revision: https://reviews.llvm.org/D70111
2019-11-16 21:56:53 +05:30
mydeveloperday 5987cc1bb5 [clang-format] fix regression in middle pointer alignment
Summary:
a75f8d98d7 introduced a regression with Middle pointer alignment,
which this patch fixes.

Reviewers: MyDeveloperDay, klimek, sammccall

Reviewed By: MyDeveloperDay, sammccall

Subscribers: cfe-commits, merge_guards_bot

Patch by: Typz

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70305
2019-11-16 14:37:47 +00:00
Sylvestre Ledru 9b40a7f3bf Remove +x permission on some files 2019-11-16 14:47:20 +01:00
Sylvestre Ledru d4819fe0ec Remove +x permission on clang/lib/Format/Format.cpp 2019-11-16 14:44:35 +01:00
mydeveloperday a4a7c1259e [clang-format] Add SpaceBeforeBrackets
Summary: Adds a new option SpaceBeforeBrackets to add spaces before brackets (i.e. int a[23]; -> int a [23];)  This is present as an option in the Visual Studio C++ code formatting settings, but there was no matching setting in clang-format.

Reviewers: djasper, MyDeveloperDay, mitchell-stellar

Reviewed By: MyDeveloperDay

Subscribers: llvm-commits, cfe-commits, klimek

Patch by: Anteru

Tags: #clang, #clang-format, #llvm

Differential Revision: https://reviews.llvm.org/D6920
2019-11-16 11:54:21 +00:00
Sylvestre Ledru 42effc1069 Add support of the next Ubuntu (Ubuntu 20.04 - Focal Fossa) 2019-11-16 12:21:54 +01:00
Reid Kleckner 979da9a4c3 Avoid including Builtins.h in Preprocessor.h
Builtins are rarely if ever accessed via the Preprocessor. They are
typically found on the ASTContext, so there should be no performance
penalty to using a pointer indirection to store the builtin context.
2019-11-15 16:45:16 -08:00
Akira Hatanaka 4516dc1c20 Don't add optnone or noinline if the function is already marked as
always_inline.

The assertion in SetLLVMFunctionAttributesForDefinition used to fail
when there was attribute OptimizeNone on the AST function and attribute
always_inline on the IR function. This happens because base destructors
are annotated with always_inline when the code is compiled with
-fapple-kext (see r124757).

rdar://problem/57169694
2019-11-15 15:44:04 -08:00
Alexandre Ganea caf3166d40 Revert "re-land [DebugInfo] Add debug location to stubs generated by CGDeclCXX and mark them as artificial"
This reverts commit 9c1baa2352.
2019-11-15 16:21:17 -05:00
Alexandre Ganea 9c1baa2352 re-land [DebugInfo] Add debug location to stubs generated by CGDeclCXX and mark them as artificial
Differential Revision: https://reviews.llvm.org/D66328
2019-11-15 16:01:39 -05:00
cchen e06f3e064a [OpenMP 5.0] - Extend defaultmap, by Chi Chun Chen.
Summary:
For the extended defaultmap, most of the work is inside sema.
The only difference for codegen is to set different initial
maptype for different implicit-behavior.

Reviewers: jdoerfert, ABataev

Reviewed By: ABataev

Subscribers: dreachem, sandoval, cfe-commits

Tags: #clang, #openmp

Differential Revision: https://reviews.llvm.org/D69204
2019-11-15 13:53:32 -05:00
Sam McCall 575e09d9f8 [AST] Let DeclarationNameInfo printing use PrintingPolicy, and fix const-correctness 2019-11-15 19:19:41 +01:00
Cameron Desrochers 358eaa3dce [clang-format] Flexible line endings
Line ending detection is now set with the `DeriveLineEnding` option.
CRLF can now be used as the default line ending by setting `UseCRLF`.
When line ending detection is disabled, all line endings are converted
according to the `UseCRLF` option.

Differential Revision: https://reviews.llvm.org/D19031
2019-11-15 11:50:22 -05:00
Momchil Velikov aa6d48fa70 Implement target(branch-protection) attribute for AArch64
This patch implements `__attribute__((target("branch-protection=...")))`
in a manner, compatible with the analogous GCC feature:

https://gcc.gnu.org/onlinedocs/gcc-9.2.0/gcc/AArch64-Function-Attributes.html#AArch64-Function-Attributes

Differential Revision: https://reviews.llvm.org/D68711
2019-11-15 15:40:46 +00:00
Ed Maste cb1761465a clang: enable unwind tables on FreeBSD !amd64
There doesn't seem to be much sense in defaulting "on" unwind tables on
amd64 and not on other arches. It causes surprising differences between
platforms, such as the PR below[1].

Prior to this change, FreeBSD inherited the default implementation of the
method from the Gnu.h Generic_Elf => Generic_GCC parent class, which
returned true only for amd64 targets.  Override that and opt on always,
similar to, e.g., NetBSD's driver.

[1] https://bugs.freebsd.org/241562

Patch by cem (Conrad Meyer).

Reviewed By: dim

Differential Revision: https://reviews.llvm.org/D70110
2019-11-15 10:37:45 -05:00
Sam Elliott e3d5ff5a0b [RISCV] Match GCC `-march`/`-mabi` driver defaults
Summary:
Clang/LLVM is a cross-compiler, and so we don't have to make a choice
about `-march`/`-mabi` at build-time, but we may have to compute a
default `-march`/`-mabi` when compiling a program. Until now, each
place that has needed a default `-march` has calculated one itself.

This patch adds a single place where a default `-march` is calculated,
in order to avoid calculating different defaults in different places.

This patch adds a new function `riscv::getRISCVArch` which encapsulates
this logic based on GCC's for computing a default `-march` value
when none is provided. This patch also updates the logic in
`riscv::getRISCVABI` to match the logic in GCC's build system for
computing a default `-mabi`.

This patch also updates anywhere that `-march` is used to now use the
new function which can compute a default. In particular, we now
explicitly pass a `-march` value down to the gnu assembler.

GCC has convoluted logic in its build system to choose a default
`-march`/`-mabi` based on build options, which would be good to match.
This patch is based on the logic in GCC 9.2.0. This commit's logic is
different to GCC's only for baremetal targets, where we default
to rv32imac/ilp32 or rv64imac/lp64 depending on the target triple.

Tests have been updated to match the new logic.

Reviewers: asb, luismarques, rogfer01, kito-cheng, khchen

Reviewed By: asb, luismarques

Subscribers: sameer.abuasal, rbar, johnrusso, simoncook, apazos, sabuasal, niosHD, shiva0217, jrtc27, MaskRay, zzheng, edward-jones, MartinMosbeck, brucehoult, the_o, rkruppe, PkmX, jocewei, psnobl, benna, Jim, s.egerton, pzheng, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D69383
2019-11-15 15:10:42 +00:00
Sam McCall fa3b87fbeb [CodeComplete] Constructor overload candidates report as vector(int) instead of vector<string>(int)
Summary:
This is shorter, shouldn't be confusing (is consistent with how they're declared),
and avoids messy cases that are printed as myclass<type-param-0-0>(int) in the
case of partial specialization.

Fixes part of https://github.com/clangd/clangd/issues/76

Reviewers: hokein, lh123

Subscribers: ilya-biryukov, kadircet, usaxena95, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D70307
2019-11-15 15:42:18 +01:00