Leonard Chan [Mon, 27 Aug 2018 17:57:29 +0000 (17:57 +0000)]
[Sema/Attribute] Make types declared with address_space an AttributedType
Currently an address_space is stored in a qualifier. This makes any type
declared with an address_space attribute in the form
`__attribute__((address_space(1))) int 1;` be wrapped in an AttributedType.
This is for a later patch where if `address_space` is declared in a macro,
any diagnostics that would normally print the address space will instead dump
the macro name. This will require saving any macro information in the
AttributedType.
Chandler Carruth [Mon, 27 Aug 2018 08:49:20 +0000 (08:49 +0000)]
Try to fix this clang driver test case after r340709.
If any of the bots complain about this, I'll just revert. This test case
is essentially trying to test the exact change made, but I think this
matches the intent of the patch in question.
Jonas Hahnfeld [Sat, 25 Aug 2018 13:42:40 +0000 (13:42 +0000)]
[CUDA/OpenMP] Define only some host macros during device compilation
When compiling CUDA or OpenMP device code Clang parses header files
that expect certain predefined macros from the host architecture. To
make this work the compiler passes the host triple via the -aux-triple
argument and (until now) pulls in all macros for that "auxiliary triple"
unconditionally.
However this results in defines like __SSE_MATH__ that will trigger
inline assembly making use of the "advertised" target features. See
the discussion of D47849 and PR38464 for a detailed explanation of
the encountered problems.
Instead of blacklisting "known bad" examples this patch starts adding
defines that are needed for certain headers like bits/wordsize.h and
bits/mathinline.h.
The disadvantage of this approach is that it decouples the definitions
from their target toolchain. However in my opinion it's more important
to keep definitions for one header close together. For one this will
include a clear documentation why these particular defines are needed.
Furthermore it simplifies maintenance because adding defines for a new
header or support for a new aux-triple only needs to touch one piece
of code.
Hans Wennborg [Fri, 24 Aug 2018 22:46:33 +0000 (22:46 +0000)]
Revert r323281 "Adjust MaxAtomicInlineWidth for i386/i486 targets."
As reported on http://lists.llvm.org/pipermail/cfe-dev/2018-August/058760.html,
this broke i386-freebsd11 due to its lack of atomic 64 bit primitives.
While that's not really this commit's fault, let's revert back to the old
behaviour until this can be fixed. This means generating cmpxchg8b etc for i386
and i486 which don't technically support those, but that's been the behaviour
for a long time, so a little longer probably doesn't hurt that much.
> Adjust MaxAtomicInlineWidth for i386/i486 targets.
>
> This is to fix the bug reported in https://bugs.llvm.org/show_bug.cgi?id=34347#c6.
> Currently, all MaxAtomicInlineWidth of x86-32 targets are set to 64. However,
> i386 doesn't support any cmpxchg related instructions. i486 only supports cmpxchg.
> So in this patch MaxAtomicInlineWidth is reset as follows:
> For i386, the MaxAtomicInlineWidth should be 0 because no cmpxchg is supported.
> For i486, the MaxAtomicInlineWidth should be 32 because it supports cmpxchg.
> For others 32 bits x86 cpu, the MaxAtomicInlineWidth should be 64 because of cmpxchg8b.
>
> Differential Revision: https://reviews.llvm.org/D42154
Eric Liu [Fri, 24 Aug 2018 08:59:54 +0000 (08:59 +0000)]
[FileManager] Do not call 'real_path' in getFile().
Summary:
This partially rolls back the change in D48903:
https://github.com/llvm-mirror/clang/commit/89aa7f45a1f728144935289d4ce69d8522999de0#diff-0025af005307891b5429b6a834823d5eR318
`real_path` can be very expensive on real file systems, and calling it on each
opened file can slow down the compilation. This also slows down deserialized
ASTs for which real paths need to be recalculated for each input files again.
For clangd code completion latency (using preamble):
Before
{F7039629}
After
{F7039630}
[analyzer] added cache for SMT queries in the SMTConstraintManager
Summary:
This patch implements a new cache for the result of SMT queries; with this patch the regression tests are 25% faster.
It's implemented as a `llvm::DenseMap` where the key is the hash of the set of the constraints in a state.
There is still one method that does not use the cache, `getSymVal`, because it needs to get a symbol interpretation from the SMT, which is not cached yet.
[analyzer] Moved all CSA code from the SMT API to a new header, `SMTConv.h`. NFC.
Summary:
With this patch, the SMT backend is almost completely detached from the CSA.
Unfortunate consequence is that we missed the `ConditionTruthVal` from the CSA and had to use `Optional<bool>`.
The Z3 solver implementation is still in the same file as the `Z3ConstraintManager`, in `lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp` though, but except for that, the SMT API can be moved to anywhere in the codebase.
[analyzer] Templatefy SMTConstraintManager so more generic code can be moved from solver specific implementations. NFC.
Summary:
By making SMTConstraintManager a template and passing the SMT constraint type and expr, we can further move code from the Z3ConstraintManager class to the generic SMT constraint Manager.
Now, each SMT specific constraint manager only needs to implement the method `bool canReasonAbout(SVal X) const`.
Update avr attributes test for output change in r340519
After this commit there is an addrspace(1) before the attribute #. Since
these tests are only checking the value of the attribute add a {{.*}} to
make the test resilient to future output changes.
Ivan Donchevskii [Thu, 23 Aug 2018 09:48:11 +0000 (09:48 +0000)]
[libclang] Fix cursors for arguments of Subscript and Call operators
The DeclRefExpr of CXXOperatorCallExpr refering to the custom operator
is visited before the arguments to the operator call. For the Call and
Subscript operator the range of this DeclRefExpr includes the whole call
expression, so that all tokens in that range were mapped to the operator
function, even the tokens of the arguments.
Fix this by ensuring that this particular DeclRefExpr is visited last.
Chandler Carruth [Thu, 23 Aug 2018 06:06:38 +0000 (06:06 +0000)]
[x86/retpoline] Split the LLVM concept of retpolines into separate
subtarget features for indirect calls and indirect branches.
This is in preparation for enabling *only* the call retpolines when
using speculative load hardening.
I've continued to use subtarget features for now as they continue to
seem the best fit given the lack of other retpoline like constructs so
far.
The LLVM side is pretty simple. I'd like to eventually get rid of the
old feature, but not sure what backwards compatibility issues that will
cause.
This does remove the "implies" from requesting an external thunk. This
always seemed somewhat questionable and is now clearly not desirable --
you specify a thunk the same way no matter which set of things are
getting retpolines.
I really want to keep this nicely isolated from end users and just an
LLVM implementation detail, so I've moved the `-mretpoline` flag in
Clang to no longer rely on a specific subtarget feature by that name and
instead to be directly handled. In some ways this is simpler, but in
order to preserve existing behavior I've had to add some fallback code
so that users who relied on merely passing -mretpoline-external-thunk
continue to get the same behavior. We should eventually remove this
I suspect (we have never tested that it works!) but I've not done that
in this patch.
Petr Hosek [Wed, 22 Aug 2018 22:56:46 +0000 (22:56 +0000)]
[Driver] Check normalized triples for multiarch runtime path
Previously we only used target triple as provided which matches the
GCC behavior, but it also means that all clients have to be consistent
in their spelling of target triples since e.g. x86_64-linux-gnu and
x86_64-unknown-linux-gnu will result in Clang driver looking at two
different paths when searching for runtime libraries.
Unfortunatelly, as it turned out many clients aren't consistent in
their spelling of target triples, e.g. many Linux distributions use
the shorter spelling but config.guess and rustc insist on using the
normalized variant which is causing issues. To avoid having to ship
multiple copies of runtimes for different triple spelling or rely on
symlinks which are not portable, we should also check the normalized
triple when constructing paths for multiarch runtimes.
Raphael Isemann [Wed, 22 Aug 2018 22:50:45 +0000 (22:50 +0000)]
[ASTImporter] Actually test ArrayInitLoopExpr in the array-init-loop-expr test.
Summary:
The `array-init-loop-expr` test is currently not testing the importing of ArrayInitLoopExprs.
This is because we import the `S` struct into the `test.cpp` context
and only do a copy-assignment in `test.cpp`, so the actual ArrayInitLoopExpr we wanted to
import is generated by clang directly in the target context. This means we actually
never test the importing of ArrayInitLoopExpr with this test, which becomes obvious
when looking at the missing test coverage for the respective VisitArrayInitLoopExpr method.
This patch moves the copy-assignment of our struct to the `S.cpp` context, which means
that `test.cpp` now actually has to import the ArrayInitLoopExpr.
Raphael Isemann [Wed, 22 Aug 2018 22:49:32 +0000 (22:49 +0000)]
[ASTImporter] Remove duplicated and dead CXXNamedCastExpr handling code.
Summary:
`CXXNamedCastExpr` importing is already handled in the respective `VisitCXXNamedCastExpr` method.
So this code here can never be reached under normal circumstances and we might as well remove it.
This patch shouldn't change any observable behavior of the ASTImporter.
Currently clang does not emit unused static constants. GCC emits these
constants by default when there is no optimization.
GCC's option -fno-keep-static-consts can be used to not emit
unused static constants.
In Clang, since default behavior does not keep unused static constants,
-fkeep-static-consts can be used to emit these if required. This could be
useful for producing identification strings like SVN identifiers
inside the object file even though the string isn't used by the program.
Chih-Hung Hsieh [Wed, 22 Aug 2018 17:13:40 +0000 (17:13 +0000)]
[Tooling] Allow -flto flags and filter out -Wa, flags
This change fixes the problem in https://bugs.llvm.org/show_bug.cgi?id=38332
by allowing driver::Action::BackendJobClass to run with the analyzer.
Otherwise, such jobs will look up the non-existing compilation database
and then run without flags.
Also filter out the -Wa,* flags that could be passed to and ignored
by the clang compiler. Clang-tidy gives warnings about unused -Wa,* flags.
Akira Hatanaka [Wed, 22 Aug 2018 13:41:19 +0000 (13:41 +0000)]
[CodeGen] Look at the type of a block capture field rather than the type
of the captured variable when determining whether the capture needs
special handing when the block is copied or disposed.
This fixes bugs in the handling of variables captured by a block that is
nested inside a lambda that captures the variables by reference.
Henry Wong [Wed, 22 Aug 2018 13:30:46 +0000 (13:30 +0000)]
[analyzer] Improve `CallDescription` to handle c++ method.
Summary:
`CallDecription` can only handle function for the time being. If we want to match c++ method, we can only use method name to match and can't improve the matching accuracy through the qualifiers.
This patch add the support for `QualifiedName` matching to improve the matching accuracy.
Gabor Marton [Wed, 22 Aug 2018 11:52:14 +0000 (11:52 +0000)]
Fix import of class templates partial specialization
Summary:
Currently there are several issues with the import of class template
specializations. (1) Different TUs may have class template specializations
with the same template arguments, but with different set of instantiated
MethodDecls and FieldDecls. In this patch we provide a fix to merge these
methods and fields. (2) Currently, we search the partial template
specializations in the set of simple specializations and we add partial
specializations as simple specializations. This is bad, this patch fixes it.
Set __mips_fpr to 0 if o32 ABI is used with either -mfpxx
or none of -mfp32, -mfpxx, -mfp64 being specified.
Introduce additional checks:
-mfpxx is only to be used in conjunction with the o32 ABI.
report an error when incompatible options are provided.
Formerly no errors were raised when combining n32/n64 ABIs
with -mfp32 and -mfpxx.
There are other cases when __mips_fpr should be set to 0
that are not covered, ex. using o32 on a mips64 cpu
which is valid but not supported in the backend as of yet.
Simon Tatham [Wed, 22 Aug 2018 09:20:39 +0000 (09:20 +0000)]
[clang-tblgen] Add -print-records and -dump-json modes.
Currently, if clang-tblgen is run without a mode option, it defaults
to the first mode in its 'enum Action', which happens to be
-gen-clang-attr-classes. I think it makes more sense for it to behave
the same way as llvm-tblgen, i.e. print a diagnostic dump if it's not
given any more specific instructions.
I've also added the same -dump-json that llvm-tblgen supports. This
means any tblgen command line (whether llvm- or clang-) can be
mechanically turned into one that processes the same input into JSON.
Hiroshi Inoue [Wed, 22 Aug 2018 05:43:27 +0000 (05:43 +0000)]
[AST] correct the behavior of -fvisibility-inlines-hidden option (don't make static local variables hidden)
The command line option -fvisibility-inlines-hidden makes inlined method hidden, but it is expected not to affect the visibility of static local variables in the function.
However, Clang makes the static local variables in the function also hidden as reported in PR37595. This problem causes LLVM bootstarp failure on Fedora 28 if configured with -DBUILD_SHARED_LIBS=ON.
This patch makes the behavior of -fvisibility-inlines-hidden option to be consistent with that of gcc; the option does not change the visibility of the static local variables if the containing function does not associated with explicit visibility attribute and becomes hidden due to this option.
Martin Storsjo [Tue, 21 Aug 2018 20:41:17 +0000 (20:41 +0000)]
[CodeGen] Implicitly set stackrealign on the main function, if custom stack alignment is used
If using a custom stack alignment, one is expected to make sure
that all callers provide such alignment, or realign the stack in
all entry points (and callbacks).
Despite this, the compiler can assume that the main function will
need realignment in these cases, since the startup routines calling
the main function most probably won't provide the custom alignment.
This matches what GCC does in similar cases; if compiling with
-mincoming-stack-boundary=X -mpreferred-stack-boundary=X, GCC normally
assumes such alignment on entry to a function, but specifically for
the main function still does realignment.
Erik Pilkington [Tue, 21 Aug 2018 17:24:06 +0000 (17:24 +0000)]
Add a new flag and attributes to control static destructor registration
This commit adds the flag -fno-c++-static-destructors and the attributes
[[clang::no_destroy]] and [[clang::always_destroy]]. no_destroy specifies that a
specific static or thread duration variable shouldn't have it's destructor
registered, and is the default in -fno-c++-static-destructors mode.
always_destroy is the opposite, and is the default in -fc++-static-destructors
mode.
A variable whose destructor is disabled (either because of
-fno-c++-static-destructors or [[clang::no_destroy]]) doesn't count as a use of
the destructor, so we don't do any access checking or mark it referenced. We
also don't emit -Wexit-time-destructors for these variables.
Louis Dionne [Tue, 21 Aug 2018 15:54:24 +0000 (15:54 +0000)]
[clang][NFC] Fix typo in the name of a note
Summary:
r306722 introduced a new note called note_silence_unligned_allocation_unavailable
where I believe what was meant is note_silence_aligned_allocation_unavailable.
Kristof Umann [Tue, 21 Aug 2018 12:16:59 +0000 (12:16 +0000)]
[analyzer][UninitializedObjectChecker] Explicit namespace resolution for inherited data members
For the following example:
struct Base {
int x;
};
// In a different translation unit
struct Derived : public Base {
Derived() {}
};
For a call to Derived::Derived(), we'll receive a note that
this->x is uninitialized. Since x is not a direct field of Derived,
it could be a little confusing. This patch aims to fix this, as well
as the case when the derived object has a field that has the name as
an inherited uninitialized data member:
struct Base {
int x; // note: uninitialized field 'this->Base::x'
};
struct Derived : public Base {
int x = 5;
Derived() {}
};
libclang: add install/distribution targets for python
Add installation support for the python bindings for libclang. Add an
additional CMake configuration variable to enumerate the python versions for
which the bindings should be installed. This allows for a LLVM/clang
distribution to distribute the python bindings for libclang as part of the
image. Because the python versions need to be explicitly stated by the user,
the default image remains unchanged.