Richard Smith [Mon, 7 Jan 2019 06:00:46 +0000 (06:00 +0000)]
DR674, PR38883, PR40238: Qualified friend lookup should look for a
template specialization if there is no matching non-template function.
This exposed a couple of related bugs:
- we would sometimes substitute into a friend template instead of a
suitable non-friend declaration; this would now crash because we'd
decide the specialization of the friend is a redeclaration of itself
- ADL failed to properly handle the case where an invisible local
extern declaration redeclares an invisible friend
Both are fixed herein: in particular, we now never make invisible
friends or local extern declarations visible to name lookup unless
they are the only declaration of the entity. (We already mostly did
this for local extern declarations.)
Brian Gesiak [Mon, 7 Jan 2019 03:25:59 +0000 (03:25 +0000)]
[SemaCXX] Fix ICE for unexpanded parameter pack
Summary:
The documentation for RecursiveASTVisitor::TraverseDecl states that the
Decl being traversed may be null. In fact, this is the case when a
CXXCatchStmt with no exception decl is traversed. Because the visitor
for diagnosing unexpanded parameter packs does not check for null, it
ends up crashing when it attempts to call the Decl::isParameterPack
method on a null Decl pointer.
Add a null check to prevent an ICE, and a test case that would crash
otherwise. Also, because the test requires C++ exceptions and C++14,
change the test parameters for the entire test file. (Alternatively, I
thought about adding a new test file, but went with this approach for my
own convenience.)
Co-authored-by: Andreas Molzer <andreas.molzer@gmx.de> Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
Reviewers: rsmith
The autolinking extension for ELF uses a slightly different format for
encoding the autolink information compared to COFF and MachO. Account
for this in the CGM to ensure that we do not assert when emitting
assembly or an object file.
Serge Guelton [Sat, 5 Jan 2019 12:07:36 +0000 (12:07 +0000)]
[python] Make the collections import future-proof
On Python 3.7 the old code raises a warning:
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
class ArgumentsIterator(collections.Sequence):
Petr Hosek [Sat, 5 Jan 2019 07:57:46 +0000 (07:57 +0000)]
[CMake][Fuchsia] Enable x86 relaxation by default
This enables x86 relaxation by default. This depends on a linker new
enough to support the new reloc types but since we default to lld we
don't worry about host system linkers that might be too old to support
the new reloc types.
Joel E. Denny [Fri, 4 Jan 2019 22:12:13 +0000 (22:12 +0000)]
[OpenMP] Refactor const restriction for linear
As discussed in D56113, this patch refactors the implementation of the
const restriction for linear to reuse a function introduced by D56113.
A side effect is that, if a variable has mutable members, this
diagnostic is now skipped, and the diagnostic for the variable not
being an integer or pointer is reported instead.
Joel E. Denny [Fri, 4 Jan 2019 22:11:56 +0000 (22:11 +0000)]
[OpenMP] Refactor const restriction for reductions
As discussed in D56113, this patch refactors the implementation of the
const restriction for reductions to reuse a function introduced by
D56113. A side effect is that diagnostics sometimes now say
"variable" instead of "list item" when a list item is a variable.
Joel E. Denny [Fri, 4 Jan 2019 22:11:31 +0000 (22:11 +0000)]
[OpenMP] Replace predetermined shared for const variable
The following appears in OpenMP 3.1 sec. 2.9.1.1 as a predetermined
data-sharing attribute:
> Variables with const-qualified type having no mutable member are
> shared.
It does not appear in OpenmP 4.0, 4.5, or 5.0. This patch removes the
implementation of that attribute when the requested OpenMP version is
greater than 3.1.
One effect of that removal is that `default(none)` affects const
variables without mutable members.
Also, without this patch, if a const variable without mutable members
was explicitly lastprivate or private, it was an error because it was
predetermined shared. Now, clang instead complains that it's const
without mutable fields, which is a more intelligible diagnostic. That
should be fine for all of the above versions because they all have
something like the following, which is quoted from OpenMP 5.0
sec. 2.19.3:
> A variable that is privatized must not have a const-qualified type
> unless it is of class type with a mutable member. This restriction does
> not apply to the firstprivate clause.
reduction and linear clauses already have separate checks for const
variables. Future patches will merge the implementations.
hwasan: Implement lazy thread initialization for the interceptor ABI.
The problem is similar to D55986 but for threads: a process with the
interceptor hwasan library loaded might have some threads started by
instrumented libraries and some by uninstrumented libraries, and we
need to be able to run instrumented code on the latter.
The solution is to perform per-thread initialization lazily. If a
function needs to access shadow memory or add itself to the per-thread
ring buffer its prologue checks to see whether the value in the
sanitizer TLS slot is null, and if so it calls __hwasan_thread_enter
and reloads from the TLS slot. The runtime does the same thing if it
needs to access this data structure.
This change means that the code generator needs to know whether we
are targeting the interceptor runtime, since we don't want to pay
the cost of lazy initialization when targeting a platform with native
hwasan support. A flag -fsanitize-hwaddress-abi={interceptor,platform}
has been introduced for selecting the runtime ABI to target. The
default ABI is set to interceptor since it's assumed that it will
be more common that users will be compiling application code than
platform code.
Because we can no longer assume that the TLS slot is initialized,
the pthread_create interceptor is no longer necessary, so it has
been removed.
Ideally, lazy initialization should only cost one instruction in the
hot path, but at present the call may cause us to spill arguments
to the stack, which means more instructions in the hot path (or
theoretically in the cold path if the spills are moved with shrink
wrapping). With an appropriately chosen calling convention for
the per-thread initialization function (TODO) the hot path should
always need just one instruction and the cold path should need two
instructions with no spilling required.
Aaron Enye Shi [Fri, 4 Jan 2019 19:09:20 +0000 (19:09 +0000)]
[HIP][DRIVER][OFFLOAD] Do not unbundle unsupported file types
The offload bundler action should not unbundle the input file types that does not match the action type. This fixes an issue where .so files are unbundled when the action type is object files.
Aaron Enye Shi [Fri, 4 Jan 2019 19:05:41 +0000 (19:05 +0000)]
[HIP][DRIVER][OFFLOAD] Do not unbundle unsupported file types
The offload bundler action should not unbundle the input file types that does not match the action type. This fixes an issue where .so files are unbundled when the action type is object files.
Erik Pilkington [Fri, 4 Jan 2019 18:33:06 +0000 (18:33 +0000)]
[ObjCARC] Add an new attribute, objc_externally_retained
This attribute, called "objc_externally_retained", exposes clang's
notion of pseudo-__strong variables in ARC. Pseudo-strong variables
"borrow" their initializer, meaning that they don't retain/release
it, instead assuming that someone else is keeping their value alive.
If a function is annotated with this attribute, implicitly strong
parameters of that function aren't implicitly retained/released in
the function body, and are implicitly const. This is useful to expose
for performance reasons, most functions don't need the extra safety
of the retain/release, so programmers can opt out as needed.
This attribute can also apply to declarations of local variables,
with similar effect.
Aaron Ballman [Fri, 4 Jan 2019 17:20:00 +0000 (17:20 +0000)]
Add two new pragmas for controlling software pipelining optimizations.
This patch adds #pragma clang loop pipeline and #pragma clang loop pipeline_initiation_interval for debugging or reducing compile time purposes. It is possible to disable SWP for concrete loops to save compilation time or to find bugs by not doing SWP to certain loops. It is possible to set value of initiation interval to concrete number to save compilation time by not doing extra pipeliner passes or to check created schedule for specific initiation interval.
Aaron Ballman [Fri, 4 Jan 2019 16:58:14 +0000 (16:58 +0000)]
Refactor the way we handle diagnosing unused expression results.
Rather than sprinkle calls to DiagnoseUnusedExprResult() around in places where we want diagnostics, we now diagnose unused expression statements and full expressions in a more generic way when acting on the final expression statement. This results in more appropriate diagnostics for [[nodiscard]] where we were previously lacking them, such as when the body of a for loop is not a compound statement.
Erich Keane [Fri, 4 Jan 2019 15:24:06 +0000 (15:24 +0000)]
Prevent unreachable when checking invalid multiversion decls.
CPUSpecifc/CPUDispatch call resolution assumed that all declarations
that would be passed are valid, however this was an invalid assumption.
This patch deals with those situations by making the valid version take
priority. Note that the checked ordering is arbitrary, since both are
replaced by calls to the resolver later.
[Basic] Extend DiagnosticEngine to store and format Qualifiers.
Qualifiers can now be streamed into the DiagnosticEngine using
regular << operator. If Qualifiers are empty 'unqualified' will
be printed in the diagnostic otherwise regular qual syntax is
used.
Daniel Dunbar [Thu, 3 Jan 2019 23:24:50 +0000 (23:24 +0000)]
Adopt SwiftABIInfo for WebAssembly.
Summary:
- This adopts SwiftABIInfo as the base class for WebAssemblyABIInfo, which is in keeping with what is done for other targets for which Swift is supported.
- This is a minimal patch to unblock exploration of WASM support for Swift (https://bugs.swift.org/browse/SR-9307)
Alexey Bataev [Thu, 3 Jan 2019 16:25:35 +0000 (16:25 +0000)]
[OPENMP][NVPTX]Use __kmpc_barrier_simple_spmd(nullptr, 0) instead of
nvvm_barrier0.
Use runtime functions instead of the direct call to the nvvm intrinsics.
It allows to prevent some dangerous LLVM optimizations, that breaks the
code for the NVPTX target.
Aaron Ballman [Thu, 3 Jan 2019 14:24:31 +0000 (14:24 +0000)]
Diagnose an unused result from a call through a function pointer whose return type is marked [[nodiscard]].
When a function returns a type and that type was declared [[nodiscard]], we diagnose any unused results from that call as though the function were marked nodiscard. The same behavior should apply to calls through a function pointer.
Philip Pfaffe [Thu, 3 Jan 2019 13:42:44 +0000 (13:42 +0000)]
[NewPM] Port Msan
Summary:
Keeping msan a function pass requires replacing the module level initialization:
That means, don't define a ctor function which calls __msan_init, instead just
declare the init function at the first access, and add that to the global ctors
list.
Changes:
- Pull the actual sanitizer and the wrapper pass apart.
- Add a newpm msan pass. The function pass inserts calls to runtime
library functions, for which it inserts declarations as necessary.
- Update tests.
Caveats:
- There is one test that I dropped, because it specifically tested the
definition of the ctor.
Alex Lorenz [Thu, 3 Jan 2019 01:13:33 +0000 (01:13 +0000)]
[libclang] CoroutineBody/Coreturn statements are UnexposedStmts and not Exprs
This change ensures that the libclang CXCursor represents the CoroutineBody
and the Coreturn statement using the appropriate CXCursor_UnexposedStmt kind
instead of CXCursor_UnexposedExpr. The problem with CXCursor_UnexposedExpr is
that the consumer functions assumed that CoroutineBody/Coreturn statements
were valid expressions and performed an invalid downcast to Expr causing
assertion failures or other crashes.
Nico Weber [Thu, 3 Jan 2019 00:17:02 +0000 (00:17 +0000)]
Make test/Driver/darwin-sdk-version.c pass if the host triple is 32-bit
For some reason, the cmake build on my macbook has
LLVM_HOST_TRIPLE:STRING=i386-apple-darwin16.7.0 .
test/Driver/darwin-sdk-version.c assumed that the host triple is 64-bit, so
make it resilient against 32-bit host triples.
David Chisnall [Fri, 28 Dec 2018 17:44:54 +0000 (17:44 +0000)]
[objc-gnustep2] Fix a bug in category generation.
We were not emitting a protocol definition while generating the category
method list. This was fine in most cases, because something else in the
library typically referenced any given protocol, but it caused linker
failures if the category was the only reference to a given protocol.
Alexey Bataev [Fri, 28 Dec 2018 17:27:32 +0000 (17:27 +0000)]
[OPENMP]Fix processing of the clauses on target combined directives.
For constants with the predefined data-sharing clauses we may had
troubles with the target combined directives. It may cause compiler
crash in some corner cases.
Reid Kleckner [Wed, 26 Dec 2018 21:04:08 +0000 (21:04 +0000)]
[clang-cl] Treat inputs as C++ with /E, like MSVC
midl invokes the compiler on .idl files with /E. Before this change, we
would treat unrecognized inputs as object files. Now we pre-process to
stdout as expected. I checked that MSVC defines __cplusplus when invoked
this way, so treating the input as C++ seems like the right thing to do.
After this change, I was able to run midl like this with clang-cl:
$ midl -cpp_cmd clang-cl.exe foo.idl
Things worked for the example IDL file in the Microsoft documentation,
but beyond that, I don't know if this will work well.
Reid Kleckner [Wed, 26 Dec 2018 17:44:40 +0000 (17:44 +0000)]
Ignore ConstantExpr in IgnoreParens
Summary:
This moves it up from IgnoreParenImpCasts to IgnoreParens, so that more
helpers ignore it. For most clients, this ensures that these helpers
behave the same with and without C++17 enabled, which is what appears to
introduce these new expression nodes.
Nico Weber [Wed, 26 Dec 2018 16:06:26 +0000 (16:06 +0000)]
Pass a concrete triple for two OpenMP tests that depend on TLS
Not all %itanium_abi_triple values support TLS. Makes
OpenMP/declare_reduction_codegen.cpp, OpenMP/parallel_copyin_codegen.cpp for
%itanium_abi_triples without TLS support.
Alternatively we could pass -fnoopenmp-use-tls and tweak some of the CHECK
lines, but this seems a bit simpler.
George Karpenkov [Mon, 24 Dec 2018 18:45:18 +0000 (18:45 +0000)]
[analyzer] [NFC] Clean up the mess of constructing argument effects in RetainCountChecker
Previously, argument effects were stored in a method variable, which was
effectively global.
The global state was reset at each (hopefully) entrance point to the
summary construction,
and every function could modify it.
Michal Gorny [Sun, 23 Dec 2018 15:07:26 +0000 (15:07 +0000)]
[Driver] Disable -faddrsig on Gentoo by default
Gentoo supports combining clang toolchain with GNU binutils, and many
users actually do that. As -faddrsig is not supported by GNU strip,
this results in a lot of warnings. Disable it by default and let users
enable it explicitly if they want it; with the intent of reevaluating
when the underlying feature becomes standarized.
Michal Gorny [Sun, 23 Dec 2018 15:07:19 +0000 (15:07 +0000)]
[Distro] Support detecting Gentoo
Add support for distinguishing plain Gentoo distribution, and a unit
test for it. This is going to be used to introduce distro-specific
customizations in the driver code; most notably, it is going to be used
to disable -faddrsig.
Bruno Ricci [Sat, 22 Dec 2018 14:39:30 +0000 (14:39 +0000)]
[AST] Store the arguments of CXXConstructExpr in a trailing array
Store the arguments of CXXConstructExpr in a trailing array. This is very
similar to the CallExpr case in D55771, with the exception that there is
only one derived class (CXXTemporaryObjectExpr) and that we compute the
offset to the trailing array instead of storing it.
This saves one pointer per CXXConstructExpr and CXXTemporaryObjectExpr.
Artem Dergachev [Sat, 22 Dec 2018 02:06:51 +0000 (02:06 +0000)]
[analyzer] pr38668: Do not attempt to cast loaded integers to floats.
This patch is a different approach to landing the reverted r349701.
It is expected to have the same object (memory region) treated as if it has
different types in different program points. The correct behavior for
RegionStore when an object is stored as an object of type T1 but loaded as
an object of type T2 is to store the object as if it has type T1 but cast it
to T2 during load.
Note that the cast here is some sort of a "reinterpret_cast" (even in C). For
instance, if you store an integer and load a float, you won't get your integer
represented as a float; instead, you will get garbage.
Admit that we cannot perform the cast and return an unknown value.
Alex Lorenz [Fri, 21 Dec 2018 19:33:09 +0000 (19:33 +0000)]
Remove stat cache chaining as it's no longer needed after PTH support has been
removed
Stat cache chaining was implemented for a StatListener in the PTH writer so that
it could write out the stat information to PTH. r348266 removed support for PTH,
and it doesn't seem like there are other uses of stat cache chaining. We can
remove the chaining support.
Bruno Ricci [Fri, 21 Dec 2018 15:20:32 +0000 (15:20 +0000)]
[AST] Store the callee and argument expressions of CallExpr in a trailing array.
Since CallExpr::setNumArgs has been removed, it is now possible to store the
callee expression and the argument expressions of CallExpr in a trailing array.
This saves one pointer per CallExpr, CXXOperatorCallExpr, CXXMemberCallExpr,
CUDAKernelCallExpr and UserDefinedLiteral.
Given that CallExpr is used as a base of the above classes we cannot use
llvm::TrailingObjects. Instead we store the offset in bytes from the this pointer
to the start of the trailing objects and manually do the casts + arithmetic.
Some notes:
1.) I did not try to fit the number of arguments in the bit-fields of Stmt.
This leaves some space for future additions and avoid the discussion about
whether x bits are sufficient to hold the number of arguments.
2.) It would be perfectly possible to recompute the offset to the trailing
objects before accessing the trailing objects. However the trailing objects
are frequently accessed and benchmarks show that it is slightly faster to
just load the offset from the bit-fields. Additionally, because of 1),
we have plenty of space in the bit-fields of Stmt.
Bruno Ricci [Fri, 21 Dec 2018 14:10:18 +0000 (14:10 +0000)]
[AST][NFC] Pass the AST context to one of the ctor of DeclRefExpr.
All of the other constructors already take a reference to the AST context.
This avoids calling Decl::getASTContext in most cases. Additionally move
the definition of the constructor from Expr.h to Expr.cpp since it is calling
DeclRefExpr::computeDependence. NFC.
Akira Hatanaka [Fri, 21 Dec 2018 07:05:36 +0000 (07:05 +0000)]
[Sema] Produce diagnostics when C++17 aligned allocation/deallocation
functions that are unavailable on Darwin are explicitly called or called
from deleting destructors.
Reid Kleckner [Fri, 21 Dec 2018 01:40:29 +0000 (01:40 +0000)]
[mingw] Don't mangle thiscall like fastcall etc
GCC does not mangle it when it is not explicit in the source. The
mangler as currently written cannot differentiate between explicit and
implicit calling conventions, so we can't match GCC. Explicit thiscall
conventions are rare, so mangle as if the convention was implicit to be
as ABI compatible as possible.
Also fixes some tests using %itanium_abi_triple in some configurations
as a side effect.
Artem Dergachev [Fri, 21 Dec 2018 00:18:58 +0000 (00:18 +0000)]
[analyzer] RetainCount: Suppress retain detection heuristic on some CM methods.
If it ends with "Retain" like CFRetain and returns a CFTypeRef like CFRetain,
then it is not necessarily a CFRetain. But it is indeed true that these two
return something retained.
Volodymyr Sapsai [Thu, 20 Dec 2018 22:43:26 +0000 (22:43 +0000)]
[CodeGen] Fix assertion on emitting cleanup for object with inlined inherited constructor and non-trivial destructor.
Fixes assertion
> Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file llvm/Support/Casting.h, line 255.
It was triggered by trying to cast `FunctionDecl` to `CXXMethodDecl` as
`CGF.CurCodeDecl` in `CallBaseDtor::Emit`. It was happening because
cleanups were emitted in `ScalarExprEmitter::VisitExprWithCleanups`
after destroying `InlinedInheritingConstructorScope`, so
`CodeGenFunction.CurCodeDecl` didn't correspond to expected cleanup decl.
Fix the assertion by emitting cleanups before leaving
`InlinedInheritingConstructorScope` and changing `CurCodeDecl`.
Erik Pilkington [Thu, 20 Dec 2018 22:32:04 +0000 (22:32 +0000)]
Add support for namespaces on #pragma clang attribute
Namespaces are introduced by adding an "identifier." before a
push/pop directive. Pop directives with namespaces can only pop a
attribute group that was pushed with the same namespace. Push and pop
directives that don't opt into namespaces have the same semantics.
This is necessary to prevent a pitfall of using multiple #pragma
clang attribute directives spread out in a large file, particularly
when macros are involved. It isn't easy to see which pop corripsonds
to which push, so its easy to inadvertently pop the wrong group.
Alex Lorenz [Thu, 20 Dec 2018 22:11:11 +0000 (22:11 +0000)]
[ObjC] Messages to 'self' in class methods that return 'instancetype' should
use the pointer to the class as the result type of the message
Prior to this commit, messages to self in class methods were treated as instance
methods to a Class value. When these methods returned instancetype the compiler
only saw id through the instancetype, and not the Interface *. This caused
problems when that return value was a receiver in a message send, as the
compiler couldn't select the right method declaration and had to rely on a
selection from the global method pool.
This commit modifies the semantics of such message sends and uses class messages
that are dispatched to the interface that corresponds to the class that contains
the class method. This ensures that instancetypes are correctly interpreted by
the compiler. This change is safe under ARC (as self can't be reassigned),
however, it also applies to MRR code as we are assuming that the user isn't
doing anything unreasonable.