Akira Hatanaka [Fri, 6 Oct 2017 07:12:46 +0000 (07:12 +0000)]
[CodeGen] Emit a helper function for __builtin_os_log_format to reduce
code size.
Currently clang expands a call to __builtin_os_log_format into a long
sequence of instructions at the call site, causing code size to
increase in some cases.
This commit attempts to reduce code size by emitting a helper function
that can be shared by calls to __builtin_os_log_format with similar
formats and arguments. The helper function has linkonce_odr linkage to
enable the linker to merge identical functions across translation units.
Attribute 'noinline' is attached to the helper function at -Oz so that
the inliner doesn't inline functions that can potentially be merged.
This commit also fixes a bug where the generated IR writes past the end
of the buffer when "%m" is the last specifier appearing in the format
string passed to __builtin_os_log_format.
Summary:
* Rename -shared-libasan to -shared-libsan, keeping the old name as alias.
* Add -static-libsan for targets that default to shared.
* Remove an Android special case. It is now possible (but untested) to use static compiler-rt libraries there.
* Support libclang_rt.ubsan_standalone as a shared library.
Unlike GCC, this change applies -shared-libsan / -static-libsan to all sanitizers.
I don't see a point in multiple flags like -shared-libubsan, considering that most sanitizers
are not compatible with each other, and each link has basically a single shared/static choice.
Richard Smith [Thu, 5 Oct 2017 19:35:51 +0000 (19:35 +0000)]
Fix two-phase name lookup for non-dependent overloaded operators.
If we resolve an overloaded operator call to a specific function during
template definition, don't perform ADL during template instantiation.
Doing so finds overloads that we're not supposed to find.
Alexey Bataev [Thu, 5 Oct 2017 17:51:39 +0000 (17:51 +0000)]
[OPENMP] Fix mapping|privatization of implicitly captured variables.
If the `defaultmap(tofrom:scalar)` clause is specified, the scalars must
be mapped with 'tofrom' modifiers, otherwise they must be captured as
firstprivates.
Ivan A. Kosarev [Thu, 5 Oct 2017 11:08:17 +0000 (11:08 +0000)]
[CodeGen] Unify generation of scalar and struct-path TBAA tags
This patch makes it possible to produce access tags in a uniform
manner regardless whether the resulting tag will be a scalar or a
struct-path one. getAccessTagInfo() now takes care of the actual
translation of access descriptors to tags and can handle all
kinds of accesses. Facilities that specific to scalar accesses
are eliminated.
Some more details:
* DecorateInstructionWithTBAA() is not responsible for conversion
of types to access tags anymore. Instead, it takes an access
descriptor (TBAAAccessInfo) and generates corresponding access
tag from it.
* getTBAAInfoForVTablePtr() reworked to
getTBAAVTablePtrAccessInfo() that now returns the
virtual-pointer access descriptor and not the virtual-point
type metadata.
* Added function getTBAAMayAliasAccessInfo() that returns the
descriptor for may-alias accesses.
* getTBAAStructTagInfo() renamed to getTBAAAccessTagInfo() as now
it is the only way to generate access tag by a given access
descriptor. It is capable of producing both scalar and
struct-path tags, depending on options and availability of the
base access type. getTBAAScalarTagInfo() and its cache
ScalarTagMetadataCache are eliminated.
* Now that we do not need to care about whether the resulting
access tag should be a scalar or struct-path one,
getTBAAStructTypeInfo() is renamed to getBaseTypeInfo().
* Added function getTBAAAccessInfo() that constructs access
descriptor by a given QualType access type.
This is part of D37826 reworked to be a separate patch to
simplify review.
Ivan A. Kosarev [Thu, 5 Oct 2017 10:47:51 +0000 (10:47 +0000)]
[CodeGen] Unify generation of scalar and struct-path TBAA tags
This patch makes it possible to produce access tags in a uniform
manner regardless whether the resulting tag will be a scalar or a
struct-path one. getAccessTagInfo() now takes care of the actual
translation of access descriptors to tags and can handle all
kinds of accesses. Facilities that specific to scalar accesses
are eliminated.
Some more details:
* DecorateInstructionWithTBAA() is not responsible for conversion
of types to access tags anymore. Instead, it takes an access
descriptor (TBAAAccessInfo) and generates corresponding access
tag from it.
* getTBAAInfoForVTablePtr() reworked to
getTBAAVTablePtrAccessInfo() that now returns the
virtual-pointer access descriptor and not the virtual-point
type metadata.
* Added function getTBAAMayAliasAccessInfo() that returns the
descriptor for may-alias accesses.
* getTBAAStructTagInfo() renamed to getTBAAAccessTagInfo() as now
it is the only way to generate access tag by a given access
descriptor. It is capable of producing both scalar and
struct-path tags, depending on options and availability of the
base access type. getTBAAScalarTagInfo() and its cache
ScalarTagMetadataCache are eliminated.
* Now that we do not need to care about whether the resulting
access tag should be a scalar or struct-path one,
getTBAAStructTypeInfo() is renamed to getBaseTypeInfo().
* Added function getTBAAAccessInfo() that constructs access
descriptor by a given QualType access type.
This is part of D37826 reworked to be a separate patch to
simplify review.
Artem Dergachev [Thu, 5 Oct 2017 08:43:32 +0000 (08:43 +0000)]
[analyzer] Fix leak false positives on stuff put in C++/ObjC initializer lists.
The analyzer now realizes that C++ std::initializer_list objects and
Objective-C boxed structure/array/dictionary expressions can potentially
maintain a reference to the objects that were put into them. This avoids
false memory leak posivites and a few other issues.
This is a conservative behavior; for now, we do not model what actually happens
to the objects after being passed into such initializer lists.
Richard Smith [Thu, 5 Oct 2017 00:43:38 +0000 (00:43 +0000)]
Remove PendingBody mechanism for function and ObjC method deserialization.
In its place, track on the canonical function declaration whether there is a
declaration with a body (and if so, which one). This brings function definition
handling in line with what we do in all other contexts, and is necessary to
allow us to merge declarations within multiple definitions of the same function
(eg, PR33924).
Yaxun Liu [Wed, 4 Oct 2017 20:32:17 +0000 (20:32 +0000)]
[OpenCL] Clean up and add missing fields for block struct
Currently block is translated to a structure equivalent to
struct Block {
void *isa;
int flags;
int reserved;
void *invoke;
void *descriptor;
};
Except invoke, which is the pointer to the block invoke function,
all other fields are useless for OpenCL, which clutter the IR and
also waste memory since the block struct is passed to the block
invoke function as argument.
On the other hand, the size and alignment of the block struct is
not stored in the struct, which causes difficulty to implement
__enqueue_kernel as library function, since the library function
needs to know the size and alignment of the argument which needs
to be passed to the kernel.
This patch removes the useless fields from the block struct and adds
size and align fields. The equivalent block struct will become
struct Block {
int size;
int align;
generic void *invoke;
/* custom fields */
};
It also changes the pointer to the invoke function to be
a generic pointer since the address space of a function
may not be private on certain targets.
Artem Dergachev [Wed, 4 Oct 2017 15:59:40 +0000 (15:59 +0000)]
[analyzer] Fix autodetection of binding types.
In ProgramState::getSVal(Location, Type) API which dereferences a pointer value,
when the optional Type parameter is not supplied and the Location is not typed,
type should have been guessed on a best-effort basis by inspecting the Location
more deeply. However, this never worked; the auto-detected type was instead
a pointer type to the correct type.
Fixed the issue and added various test cases to demonstrate which parts of the
analyzer were affected (uninitialized pointer argument checker, C++ trivial copy
modeling, Google test API modeling checker).
Additionally, autodetected void types are automatically replaced with char,
in order to simplify checker APIs. Which means that if the location is a void
pointer, getSVal() would read the first byte through this pointer
and return its symbolic value.
Jonas Hahnfeld [Wed, 4 Oct 2017 13:32:59 +0000 (13:32 +0000)]
[OpenMP] Fix passing of -m arguments correctly
The recent fix in D38258 was wrong: getAuxTriple() only returns
non-null values for the CUDA toolchain. That is why the now added
test for PPC and X86 failed.
Fix assertion failure in thread safety analysis (PR34800).
Summary:
Fix an assertion failure (http://llvm.org/PR34800) and clean up unused code relevant to the fixed logic.
A bit of context: when `SExprBuilder::translateMemberExpr` is called on a member expression that involves a conversion operator, for example, `til::Project` constructor can't just call `getName()` on it, since the name is not a simple identifier. In order to handle this case I've introduced an optional string to print the member name to. I discovered that the other two `til::Project` constructors are not used, so it was better to delete them instead of ensuring they work correctly with the new logic.
Richard Smith [Wed, 4 Oct 2017 01:49:22 +0000 (01:49 +0000)]
PR34822: Fix a collection of related bugs with our handling of C89 implicit function declarations.
We were injecting the function into the wrong semantic context, resulting in it
failing to be registered as a global for redeclaration lookup. As a
consequence, we accepted invalid code since r310616.
Fixing that resulted in the "out-of-scope declaration" diagnostic firing a lot
more often. It turned out that warning codepath was non-conforming, because it
did not cause us to inject the implicitly-declared function into the enclosing
block scope. We now only warn if the type of the out-of-scope declaration
doesn't match the type of an implicitly-declared function; in all other cases,
we produce the normal warning for an implicitly-declared function.
Richard Smith [Tue, 3 Oct 2017 20:36:00 +0000 (20:36 +0000)]
Suppress -Wmissing-braces warning when aggregate-initializing a struct with a single field that is itself an aggregate.
In C++, such initialization of std::array<T, N> types is guaranteed to work by
the standard, is completely idiomatic, and the "suggested" alternative from
Clang was technically invalid.
Alexey Bataev [Tue, 3 Oct 2017 20:00:00 +0000 (20:00 +0000)]
[OPENMP] Allow use of declare target directive inside struct
declaration.
Patch allows using of the `#pragma omp declare target`| `#pragma omp end
declare target` directives inside the structures if we need to mark as
declare target only some static members.
Yaxun Liu [Tue, 3 Oct 2017 14:34:29 +0000 (14:34 +0000)]
[OpenCL] Fix checking of vector type casting
Currently clang allows the following code
int a;
int b = (const int) a;
However it does not the following code
int4 a;
int4 b = (const int4) a;
This is because Clang compares the qualified types instead of unqualified types for vector type casting, which causes the inconsistency.
Ivan A. Kosarev [Tue, 3 Oct 2017 11:31:42 +0000 (11:31 +0000)]
[CodeGen] Fix propagation of TBAA info for atomic accesses
This patch fixes clang to propagate complete TBAA information for
atomic accesses and not just the final access types. Prepared
against D38456 and requires it to be committed first.
This is part of D37826 reworked to be a separate patch to
simplify review.
With this patch we implement a concept of TBAA access descriptors
that are capable of representing both scalar and struct-path
accesses in a generic way.
This is part of D37826 reworked to be a separate patch to
simplify review.
Vedant Kumar [Tue, 3 Oct 2017 01:27:26 +0000 (01:27 +0000)]
[ubsan] Skip alignment checks which are folded away
Don't emit alignment checks which the IR constant folder throws away.
I've tested this out on X86FastISel.cpp. While this doesn't decrease
end-to-end compile-time significantly, it results in 122 fewer type
checks (1% reduction) overall, without adding any real complexity.
Faisal Vali [Tue, 3 Oct 2017 00:52:14 +0000 (00:52 +0000)]
[NFC] Refactor PasteTokens so that it can be passed the Token Stream and Index to start concatenating at.
In passing:
- change the name of the function to pasteTokens c/w coding standards
- rename CurToken to CurTokenIdx (since it is not the token, but the index)
- add doxygen comments to document some of pasteTokens' functionality
- use parameter names different from the data member names.
This will be useful for implementing __VA_OPT__ (https://reviews.llvm.org/D35782#inline-322587)
Alex Lorenz [Mon, 2 Oct 2017 18:42:43 +0000 (18:42 +0000)]
[refactor] Simplify the refactoring interface
This commit simplifies the interface for the refactoring action rules and the
refactoring requirements. It merges the selection constraints and the selection
requirements into one class. The refactoring actions rules must now be
implemented using subclassing instead of raw function / lambda pointers. This
change also removes a bunch of template-based traits and other
template definitions that are now redundant.
Reid Kleckner [Mon, 2 Oct 2017 17:16:14 +0000 (17:16 +0000)]
Revert "[Sema] Warn on attribute nothrow conflicting with language specifiers"
This reverts r314461.
It is warning on user code that uses END_COM_MAP(), which expands to
declare QueryInterface with conflicting exception specifers. I've spent
a while trying to understand why, but haven't been able to extract a
reduced test case. Let's revert and I'll keep trying.
Alexey Bataev [Mon, 2 Oct 2017 16:32:39 +0000 (16:32 +0000)]
[OPENMP] Capture argument of `device` clause for target-based
directives.
The argument of the `device` clause in target-based executable
directives must be captured to support codegen for the `target`
directives with the `depend` clauses.
[clang-format] Fix regression about short functions after #else
Summary:
This patch fixes a regression introduced in r312904, where the formatter confuses
the `else` in `#else` with an `else` of an `if-else` statement.
For example, formatting this code with google style
```
#ifdef A
int f() {}
#else
int f() {}
#endif
```
resulted in
```
#ifdef A
int f() {}
#else
int f() {
}
#endif
```
Andrew Gozillon [Mon, 2 Oct 2017 13:32:59 +0000 (13:32 +0000)]
Dependent Address Space Support Test Fix
Modifying a non-type template integer arguement that is causing errors
in some builds as it's too large for 32-bit longs. This hopefully (and
seems to when testing) should fix all of the build bot errors relating
to this test. I also modified the name of the function call to be more
apt.
Andrew Gozillon [Mon, 2 Oct 2017 06:31:25 +0000 (06:31 +0000)]
Dependent Address Space Support Test File
Adding regression test for Dependent Address Spaces in relation to
https://reviews.llvm.org/D33666 I forgot to svn add the test file
before commiting the prior changes. I appologies.
Andrew Gozillon [Mon, 2 Oct 2017 06:25:51 +0000 (06:25 +0000)]
Dependent Address Space Support
This patch relates to: https://reviews.llvm.org/D33666 This adds support
for template parameters to be passed to the address_space attribute.
The main goal is to add further flexibility to the attribute and allow
for it to be used easily with templates.
The main additions are a new type (DependentAddressSpaceType) alongside
its TypeLoc and its mangling. As well as the logic required to support
dependent address spaces which mainly resides in TreeTransform.h and
SemaType.cpp.
[NFC] Remove superfluous parameter
- MacroArgs already knows the maximum number of arguments that can be supplied to the macro. No need to pass MacroInfo (information about the macro definition) to the call to getPreExpArgument (which by the way might benefit from being called getExpandedArgument() ?) for it to compute the number of arguments.
clang/test/SemaCXX/ms-iunknown-template-function.cpp: Appease for targeting *-win32.
This expects the warning;
File clang/test/SemaCXX/ms-iunknown-template-function.cpp Line 19: __declspec attribute 'novtable' is not supported
But for targeting *-win32, the warning is not seen.
error: 'warning' diagnostics expected but not seen:
File clang\test\SemaCXX\ms-iunknown-template-function.cpp Line 19 (directive at clang\test\SemaCXX\ms-iunknown-template-function.cpp:18): __declspec attribute 'novtable'
Richard Smith [Fri, 29 Sep 2017 23:57:25 +0000 (23:57 +0000)]
Add a "vexing parse" warning for ambiguity between a variable declaration and a
function-style cast.
This fires for cases such as
T(x);
... where 'x' was previously declared and T is a type. This construct declares
a variable named 'x' rather than the (probably expected) interpretation of a
function-style cast of 'x' to T.
Erich Keane [Fri, 29 Sep 2017 21:06:00 +0000 (21:06 +0000)]
[Sema] Correct IUnknown to support Unknwnbase.h Header.
Apparently, the MSVC SDK has a strange implementation that
causes a number of implicit functions as well as a template member
function of the IUnknown type. This patch allows these as InterfaceLike
types as well.
Additionally, it corrects the behavior where extern-C++ wrapped around an
Interface-Like type would permit an interface-like type to exist in a namespace.
Coby Tayree [Fri, 29 Sep 2017 07:02:49 +0000 (07:02 +0000)]
[X86][MS-InlineAsm] Extended support for variables / identifiers on memory / immediate expressions
Allow the proper recognition of Enum values and global variables inside ms inline-asm memory / immediate expressions, as they require some additional overhead and treated incorrect if doesn't early recognized.
supersedes D33278, D35774
C11 standard refers to the unsigned counterpart of the type ptrdiff_t
in the paragraph 7.21.6.1p7 where it defines the format specifier %tu.
In Clang (in PrintfFormatString.cpp, lines 508-510) there is a FIXME for this case,
in particular, Clang didn't diagnose %tu issues at all, i.e.
it didn't emit any warnings on the code printf("%tu", 3.14).
In this diff we add a method getUnsignedPointerDiffType for getting the corresponding type
similarly to how it's already done in the other analogous cases (size_t, ssize_t, ptrdiff_t etc)
and fix -Wformat diagnostics for %tu plus the emitted fix-it as well.
Erich Keane [Thu, 28 Sep 2017 20:47:10 +0000 (20:47 +0000)]
[Sema] Correct nothrow inherited by noexcept
As reported in https://bugs.llvm.org/show_bug.cgi?id=33235,
a noexcept function was unable to inherit from a nothrow defaulted
constructor. Attribute "nothrow" is supposed to be semantically
identical to noexcept, and in fact, a number of other places in the
code treat them identically.
This patch simply checks the RecordDecl for the correct attribute in
the case where no other exception specifier was set.
Paul Robinson [Thu, 28 Sep 2017 18:37:02 +0000 (18:37 +0000)]
[DWARF] Allow forward declarations of a class template instantiation
to have child entries describing the template parameters. This will
be on by default for SCE tuning.
Benjamin Kramer [Thu, 28 Sep 2017 08:50:30 +0000 (08:50 +0000)]
Use std::is_trivial instead of is_trivially_copyable.
The oldest versions of GCC we support (before 5) didn't support that
trait. is_trivial is stronger superset that clang::Token fulfills, so
just use that instead.