Michael Kruse [Wed, 4 Jul 2018 01:37:11 +0000 (01:37 +0000)]
[Sema] Consider all format_arg attributes.
If a function has multiple format_arg attributes, clang only considers
the first it finds (because AttributeLists are in reverse order, not
necessarily the textually first) and ignores all others.
Loop over all FormatArgAttr to print warnings for all declared
format_arg attributes.
For instance, libintl's ngettext (select plural or singular version of
format string) has two __format_arg__ attributes.
Erik Pilkington [Tue, 3 Jul 2018 22:15:36 +0000 (22:15 +0000)]
[Sema] Discarded statment should be an evaluatable context.
The constexpr evaluator was erroring out because these templates weren't
defined. Despite being used in a discarded statement, we still need to constexpr
evaluate them, which means that we need to instantiate them. Fixes PR37585.
Erich Keane [Tue, 3 Jul 2018 20:30:34 +0000 (20:30 +0000)]
Fix allocation of Nullability attribute.
Existing code always allocates for on the declarator's attribute pool,
but sometimes adds it to the declspec. This patch ensures that the
correct pool is used.
Discovered while testing: https://reviews.llvm.org/D48788
This happened during a recent refactor. toStringRefArray() returns
a vector<StringRef>, which was being implicitly converted to an
ArrayRef<StringRef>, and then the vector was immediately being
destroyed, so the ArrayRef<> was losing its backing storage.
Fix this by making sure the vector gets permanent storage.
Summary:
Scudo works on PPC64 as is, so mark the architecture as supported for it. This
will also require a change to config-ix.cmake on the compiler-rt side.
Hans Wennborg [Tue, 3 Jul 2018 07:51:41 +0000 (07:51 +0000)]
Revert r336021 "PR33924: merge local declarations that have linkage of some kind within"
This caused test failures in 32-bit builds (PR38015).
> merged function definitions; also merge functions with deduced return
> types.
>
> This seems like two independent fixes, but unfortunately they are hard
> to separate because it's challenging to reliably test either one of them
> without also testing the other.
>
> A complication arises with deduced return type support: we need the type
> of the function in order to know how to merge it, but we can't load the
> actual type of the function because it might reference an entity
> declared within the function (and we need to have already merged the
> function to correctly merge that entity, which we would need to do to
> determine if the function types match). So we instead compare the
> declared function type when merging functions, and defer loading the
> actual type of a function with a deduced type until we've finished
> loading and merging the function.
Steven Wu [Tue, 3 Jul 2018 04:15:49 +0000 (04:15 +0000)]
[Driver][Darwin] Use Host Triple to infer target os version
Summary:
When clang required to infer target os version from --target option and
the os version is not specified in targets, check the host triple. If the
host and target are both macOS, use host triple to infer target os
version.
[ms] Fix mangling of char16_t and char32_t to be compatible with MSVC.
MSVC limits char16_t and char32_t string literal names to 32 bytes of character
data, not to 32 characters. wchar_t string literal names on the other hand can
get up to 64 bytes of character data.
Craig Topper [Sat, 30 Jun 2018 06:05:17 +0000 (06:05 +0000)]
[X86] Correct the width of mask arguments in intrinsic headers and tests.
All of these found by grepping through IR from the builtin tests for extra trunc and zext/sext instructions that shouldn't have been there.
Some of these were real bugs where we lost bits from the user input:
_mm512_mask_broadcast_f32x8
_mm512_maskz_broadcast_f32x8
_mm512_mask_broadcast_i32x8
_mm512_maskz_broadcast_i32x8
_mm256_mask_cvtusepi16_storeu_epi8
Tom Stellard [Sat, 30 Jun 2018 02:55:54 +0000 (02:55 +0000)]
Driver: Don't mix system tools with devtoolset tools on RHEL
Summary:
On RHEL, devtoolset provides a more up-to-date toolchain than the base
install, and we want to make sure all the tools use are from the same
toolchain.
Add protocol redefinition to the current scope/context
Not doing so causes the AST writter to assert since the decl in question
never gets emitted. This is fine when modules is not used, but otherwise
we need to serialize something other than garbage.
Richard Smith [Fri, 29 Jun 2018 21:58:50 +0000 (21:58 +0000)]
PR33924: merge local declarations that have linkage of some kind within
merged function definitions; also merge functions with deduced return
types.
This seems like two independent fixes, but unfortunately they are hard
to separate because it's challenging to reliably test either one of them
without also testing the other.
A complication arises with deduced return type support: we need the type
of the function in order to know how to merge it, but we can't load the
actual type of the function because it might reference an entity
declared within the function (and we need to have already merged the
function to correctly merge that entity, which we would need to do to
determine if the function types match). So we instead compare the
declared function type when merging functions, and defer loading the
actual type of a function with a deduced type until we've finished
loading and merging the function.
Richard Smith [Fri, 29 Jun 2018 20:46:25 +0000 (20:46 +0000)]
[modules] Emit the type of the TypeSourceInfo for a DeclaratorDecl (but
not the corresponding location information) earlier.
We need the type as written in order to properly merge functions with
deduced return types, so we need to load that early. But we don't want
to load the location information early, because that contains
problematic things such as the function parameters.
Richard Smith [Fri, 29 Jun 2018 20:41:23 +0000 (20:41 +0000)]
Specify an explicit underlying type for this enum to fix Windows
buildbots.
On Windows targets, enums always get an underlying type of 'int', even
if they have wider enumerators. (This is non-conforming, but it's
effectively part of the target ABI.)
Dimitry Andric [Fri, 29 Jun 2018 19:18:17 +0000 (19:18 +0000)]
Request init/fini array on FreeBSD 12 and later
Summary:
It seems a bad idea to change the default in the middle of a release
branch due to possible changes in global ctor / dtor ordering between
.ctors and .init_array. With FreeBSD 11.0's release imminent lets change
the default now for FreeBSD 12 (the current development stream) and
later.
FreeBSD rtld has supported .init_array / .fini_array for many years. As
of Jan 1 2017 all supported FreeBSD releases and branches will have
support.
[analyzer] Replace the vector of ConstraintSets by a single ConstraintSet and a function to merge ConstraintSets
Now, instead of adding the constraints when they are removed, this patch adds them when they first appear and, since we walk the bug report backward, it should be the last set of ranges generated by the CSA for a given symbol.
These are the number before and after the patch:
```
Project | current | patch |
tmux | 283.222 | 123.052 |
redis | 614.858 | 400.347 |
openssl | 308.292 | 307.149 |
twin | 274.478 | 245.411 |
git | 547.687 | 477.335 |
postgresql | 2927.495 | 2002.526 |
sqlite3 | 3264.305 | 1028.416 |
```
Major speedups in tmux and sqlite (less than half of the time), redis and postgresql were about 25% faster while the rest are basically the same.
Jessica Paquette [Fri, 29 Jun 2018 18:06:10 +0000 (18:06 +0000)]
[MachineOutliner] Make -mno-outline use -enable-machine-outliner=never
This updates -mno-outline so that it passes -enable-machine-outliner=never
instead of nothing. This puts it in sync with the behaviour in llc and
other tools.
Leonard Chan [Fri, 29 Jun 2018 17:08:19 +0000 (17:08 +0000)]
[Fixed Point Arithmetic] Rename `-fsame-fbits` flag
- Rename the `-fsame-fbits` flag to `-fpadding-on-unsigned-fixed-point`
- Move the flag from a driver option to a cc1 option
- Rename the `SameFBits` member in TargetInfo to `PaddingOnUnsignedFixedPoint`
- Updated descriptions
Ben Hamilton [Fri, 29 Jun 2018 15:26:37 +0000 (15:26 +0000)]
[clang-format/ObjC] Fix NS_SWIFT_NAME(foo(bar:baz:)) after ObjC method decl
Summary:
In D44638, I partially fixed `NS_SWIFT_NAME(foo(bar:baz:))`-style
annotations on C functions, but didn't add a test for Objective-C
method declarations.
For ObjC method declarations which are annotated with `NS_SWIFT_NAME(...)`,
we currently fail to annotate the final component of the selector
name as `TT_SelectorName`.
Because the token type is left unknown, clang-format will happily
cause a compilation error when it changes the following:
The logic which decides whether or not to annotate the token before a
`:` with `TT_SelectorName` is pretty fragile, and has to handle some
pretty odd cases like pair-parameters:
So, to minimize the effect of this change, I decided to only annotate
unknown identifiers before a `:` as `TT_SelectorName` for Objective-C
declaration lines.
Test Plan: New tests included. Confirmed tests failed before change and
passed after change. Ran tests with:
% make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests
Kristof Umann [Fri, 29 Jun 2018 11:25:24 +0000 (11:25 +0000)]
[analyzer][UninitializedObjectChecker] Added a NotesAsWarnings flag
In order to better support consumers of the plist output that don't
parse note entries just yet, a 'NotesAsWarnings' flag was added.
If it's set to true, all notes will be converted to warnings.
Gabor Marton [Fri, 29 Jun 2018 10:25:19 +0000 (10:25 +0000)]
[ASTImporter] Eliminated some unittest warnings.
Summary:
When running the ASTTests test, warnings produced by the compiler can be
distracting when looking for test errors. A part of the warnings is removed
by setting extra compiler options.
Alex Lorenz [Thu, 28 Jun 2018 23:23:45 +0000 (23:23 +0000)]
[frontend] Don't include the C++ stdlib for -x assembler-with-cpp
The new C++ stdlib warning added in r335081 gets
triggered when compiling an assembly file with -x assembler-with-cpp.
This commit ensures that the C++ stdlib is not included when compiling assembly.
In general, it's not really useful to include the C++ stdlib search path when
compiling assembly source.
[Parse] Make -Wgcc-compat complain about for loop inits in C89
While clang allows declarations in for loop init statements in c89 and
gnu89, gcc does not. So, we should probably warn if users care about gcc
compatibility.
[analyzer] Fix wrong comparison generation of the ranges generated by the refutation manager
The refutation manager is removing a true bug from the test in this patch.
The problem is that the following constraint:
```
(conj_$1{struct o *}) - (reg_$3<int * r>): [-9223372036854775808, 0]
```
is encoded as:
```
(and (bvuge (bvsub $1 $3) #x8000000000000000)
(bvule (bvsub $1 $3) #x0000000000000000))
```
The issue is that unsigned comparisons (bvuge and bvule) are being generated instead of signed comparisons (bvsge and bvsle).
When generating the expressions:
```
(conj_$1{p *}) - (reg_$3<int * r>) >= -9223372036854775808
```
and
```
(conj_$1{p *}) - (reg_$3<int * r>) <= 0
```
both -9223372036854775808 and 0 are casted to pointer type and `LTy->isSignedIntegerOrEnumerationType()` in `Z3ConstraintManager::getZ3BinExpr` only checks if the type is signed, not if it's a pointer.
Richard Smith [Thu, 28 Jun 2018 21:17:55 +0000 (21:17 +0000)]
PR37979: integral promotions in C++ treat enum bit-fields like enums,
not like bit-fields.
We used to get this right "by accident", because conversions for the
selected built-in overloaded operator would convert the enum bit-field
to its corresponding underlying type early. But after DR1687 that no
longer happens.
Technically this change should also apply to C, where bit-fields only
have special promotion rules if the bit-field's declared type is
_Bool, int, signed int, or unsigned int, but for GCC compatibility we
only look at the bit-width and not the underlying type when performing
bit-field integral promotions in C.
[clang-format] Do not format raw string literals inside a recognized function with a non-recognized delimiter
Summary:
This stops clang-format from touching raw string contents with unrecognized delimiters inside recognized functions.
Unrecognized delimiters signal that the string might be special.
David Carlier [Thu, 28 Jun 2018 13:49:41 +0000 (13:49 +0000)]
OpenBSD driver needs ld.lld in sanitizer context
Base GNU ld is pretty ancient and does not support --dynamic-list flag.
For conveniency, we can it automatically when compile with ubsan sanitizer flag.
Vassil Vassilev [Thu, 28 Jun 2018 13:28:44 +0000 (13:28 +0000)]
[ODRHash] Do not rely on Type* when computing the hash.
ODRHash aims to provide Cross-TU stable hashing. Making clang::Type pointer
part of the hash connects (remotely) the ODRHash with the TU-specific
::Profile hasher.
r332281 exposed the issue by changing the way the ASTContext different
elaborated types if there is an owning tag. In that case, ODRHash stores two
different types in its TypeMap which yields false ODR violation in modules.
The current state of implementation shouldn't need the TypeMap concept
anymore. Rip it out.
Adam Balogh [Thu, 28 Jun 2018 10:58:53 +0000 (10:58 +0000)]
[Analyzer] Iterator Checker - Part 2: Increment, decrement operators and ahead-of-begin checks
Add handling of the begin() funcion of containers to the iterator checkers,
together with the pre- and postfix ++ and -- operators of the iterators. This
makes possible the checking of iterators dereferenced ahead of the begin of the
container.
Adam Balogh [Thu, 28 Jun 2018 07:35:23 +0000 (07:35 +0000)]
[Analyzer] Constraint Manager Negates Difference
If range [m .. n] is stored for symbolic expression A - B, then we can deduce the range for B - A which is [-n .. -m]. This is only true for signed types, unless the range is [0 .. 0].
Petr Hosek [Thu, 28 Jun 2018 05:15:46 +0000 (05:15 +0000)]
[CMake] Use explicit targets for building Linux runtimes
Previously we were using default logic when building Linux runtimes
in Fuchsia toolchain, but that leads to various issues due to how
the CMake logic in compiler-rt for determining the platform support
is implemented. With this change, we will use explicit target for
every provided Linux sysroot.
Petr Hosek [Thu, 28 Jun 2018 03:54:08 +0000 (03:54 +0000)]
Handle both Linux and Windows path separator for the resource dir
The resource dir path used for the multiarch runtimes support is
constructed in a platform independent way and therefore will use
native path separators on each platform. We need to make sure that
the per target runtime directory test handles both to not fail
when the test is being executed on Windows.
Petr Hosek [Thu, 28 Jun 2018 03:11:52 +0000 (03:11 +0000)]
Support for multiarch runtimes layout
This change adds a support for multiarch style runtimes layout, so in
addition to the existing layout where runtimes get installed to:
lib/clang/$version/lib/$os
Clang now allows runtimes to be installed to:
lib/clang/$version/$target/lib
This also includes libc++, libc++abi and libunwind; today those are
assumed to be in Clang library directory built for host, with the
new layout it is possible to install libc++, libc++abi and libunwind
into the runtime directory built for different targets.
The use of new layout is enabled by setting the
LLVM_ENABLE_RUNTIME_TARGET_DIR CMake variable and is supported by both
projects and runtimes layouts. The runtimes CMake build has been further
modified to use the new layout when building runtimes for multiple
targets.
Richard Smith [Thu, 28 Jun 2018 01:57:04 +0000 (01:57 +0000)]
[modules] Do not serialize / deserialize pending new/delete mismatch
checks across module boundaries. This was causing us to load constructor
definitions for all consumers of a module with a pending check.
(In one case we saw ~7% of total frontend time spent loading
constructors for this check.)
Richard Smith [Thu, 28 Jun 2018 01:07:28 +0000 (01:07 +0000)]
[modules] Ensure that an in-class function definition is attached to the
declaration of the function that ends up in the primary definition of
the class.
... at least for class templates. This is necessary for us to be able to
track when an inline friend function has a definition that needs to be
(lazily) instantiated.
Artem Dergachev [Thu, 28 Jun 2018 00:42:11 +0000 (00:42 +0000)]
[analyzer] Use sufficiently large types for index bounds calculation.
The ProgramState::assumeInBound() API is used by checkers to make an assumption
that a certain array index is within the array's bounds (i.e. is greater than or
equal to 0 and is less than the length of the array). When the type of the
index was unspecified by the caller, it assumed that the type is 'int', which
caused some indices and sizes to truncate during calculations.
Use ArrayIndexTy by default instead, which is used by the analyzer to represent
index types and is currently hardcoded to long long.
Artem Dergachev [Thu, 28 Jun 2018 00:30:18 +0000 (00:30 +0000)]
[analyzer] Add support for pre-C++17 copy elision.
r335795 adds copy elision information to CFG. This commit allows static analyzer
to elide elidable copy constructors by constructing the objects that were
previously subject to elidable copy directly in the target region of the copy.
The chain of elided constructors may potentially be indefinitely long. This
only happens when the object is being returned from a function which in turn is
returned from another function, etc.
Artem Dergachev [Thu, 28 Jun 2018 00:18:52 +0000 (00:18 +0000)]
[CFG] [analyzer] Simplify lifetime-extended temporary construction contexts.
When a temporary object is materialized and through that obtain lifetime that
is longer than the duration of the full-expression, it does not require a
temporary object destructor; it will be destroyed in a different manner.
Therefore it's not necessary to include CXXBindTemporaryExpr into the
construction context for such temporary in the CFG only to make clients
throw it away.
Artem Dergachev [Thu, 28 Jun 2018 00:11:42 +0000 (00:11 +0000)]
[analyzer] Re-enable lifetime extension for temporaries without destructors.
When an object's class provides no destructor, it's less important to
materialize that object properly because we don't have to model the destructor
correctly, so previously we skipped the support for these syntax patterns.
Additionally, fix support for construction contexts of "static temporaries"
(temporaries that are lifetime-extended by static references) because
it turned out that we only had tests for them without destructors, which caused
us to regress when we re-introduced the construction context for such
temporaries.
Artem Dergachev [Thu, 28 Jun 2018 00:04:54 +0000 (00:04 +0000)]
[CFG] [analyzer] Add construction contexts that explain pre-C++17 copy elision.
Before C++17 copy elision was optional, even if the elidable copy/move
constructor had arbitrary side effects. The elidable constructor is present
in the AST, but marked as elidable.
In these cases CFG now contains additional information that allows its clients
to figure out if a temporary object is only being constructed so that to pass
it to an elidable constructor. If so, it includes a reference to the elidable
constructor's construction context, so that the client could elide the
elidable constructor and construct the object directly at its final destination.
Richard Smith [Wed, 27 Jun 2018 20:30:34 +0000 (20:30 +0000)]
DR1687: When overload resolution selects a built-in operator, implicit
conversions are only applied to operands of class type, and the second
standard conversion sequence is not applied.
When diagnosing an invalid builtin binary operator, talk about the
original types rather than the converted types. If these differ by a
user-defined conversion, tell the user what happened.
[Modules][ObjC] Warn on the use of '@import' in framework headers
Using @import in framework headers inhibit the use of such headers
when not using modules, this is specially bad for headers that end
up in the SDK (or any other system framework). Add a warning to give
users some indication that this is discouraged.
Aaron Enye Shi [Wed, 27 Jun 2018 19:51:42 +0000 (19:51 +0000)]
[HIP] Fix ordering of device-libs linking
Summary:
HIP should link the bitcodes with caller functions before callee functions. Also added lit test to check the ordering of the linked bitcodes is matches.
Aaron Enye Shi [Wed, 27 Jun 2018 18:58:55 +0000 (18:58 +0000)]
[HIP] Support flush denormals bitcode
Summary:
Use oclc_daz_opt_on.amdgcn.bc bitcode when option fcuda-flush-denormal-to-zero is enabled, otherwise use oclc_daz_opt_off.amdgcn.bc bitcode. Added lit tests to verify that the correct bitcode is linked when -fcuda-flush-denormal-to-zero option is enabled or disabled.
Artem Belevich [Wed, 27 Jun 2018 18:32:51 +0000 (18:32 +0000)]
[CUDA] Use atexit() to call module destructor.
This matches the way NVCC does it. Doing module cleanup at global
destructor phase used to work, but is, apparently, too late for
the CUDA runtime in CUDA-9.2, which ends up crashing with double-free.
Matt Morehouse [Wed, 27 Jun 2018 18:24:46 +0000 (18:24 +0000)]
[UBSan] Add silence_unsigned_overflow flag.
Summary:
Setting UBSAN_OPTIONS=silence_unsigned_overflow=1 will silence all UIO
reports. This feature, combined with
-fsanitize-recover=unsigned-integer-overflow, is useful for providing
fuzzing signal without the excessive log output.
Helps with https://github.com/google/oss-fuzz/issues/910.
[DebugInfo] Emit ObjC methods as part of interface
As brought up during the discussion of the DWARF5 accelerator tables,
there is currently no way to associate Objective-C methods with the
interface they belong to, other than the .apple_objc accelerator table.
After due consideration we came to the conclusion that it makes more
sense to follow Pavel's suggestion of just emitting this information in
the .debug_info section. One concern was that categories were
emitted in the .apple_names as well, but it turns out that LLDB doesn't
rely on the accelerator tables for this information.
This patch changes the codegen behavior to emit subprograms for
structure types, like we do for C++. This will result in the
DW_TAG_subprogram being nested as a child under its
DW_TAG_structure_type. This behavior is only enabled for DWARF5 and
later, so we can have a unique code path in LLDB with regards to
obtaining the class methods.
This was tested on the LLDB side and doesn't lead to a regression.
There's already code in place to deal with member functions in C++,
which deals with this transparently.
For more background please refer to the discussion on the mailing list:
http://lists.llvm.org/pipermail/llvm-dev/2018-June/123986.html
Fails on Green Dragon:
http://green.lab.llvm.org/green/job/clang-stage1-cmake-RA-incremental/50174/consoleFull
UNRESOLVED: Clang :: CodeGen/vld_dup.c (5546 of 38947)
******************** TEST 'Clang :: CodeGen/vld_dup.c' FAILED ********************
Test has no run line!
Summary:
Add an extension point to allow registration of statically-linked Clang Static
Analyzer checkers that are not a part of the Clang tree. This extension point
employs the mechanism used when checkers are registered from dynamically loaded
plugins.
Gabor Marton [Wed, 27 Jun 2018 13:32:50 +0000 (13:32 +0000)]
Re-apply: [ASTImporter] Import the whole redecl chain of functions
Summary:
With this patch when any `FunctionDecl` of a redeclaration chain is imported
then we bring in the whole declaration chain. This involves functions and
function template specializations. Also friend functions are affected. The
chain is imported as it is in the "from" tu, the order of the redeclarations
are kept. I also changed the lookup logic in order to find friends, but first
making them visible in their declaration context. We may have long
redeclaration chains if all TU contains the same prototype, but our
measurements shows no degradation in time of CTU analysis (Tmux, Xerces,
Bitcoin, Protobuf). Also, as further work we could squash redundant
prototypes, but first ensure that functionality is working properly; then
should we optimize.
This may seem like a huge patch, sorry about that. But, most of the changes are
new tests, changes in the production code is not that much. I also tried to
create a smaller patch which does not affect specializations, but that patch
failed to pass some of the `clang-import-test`s because there we import
function specializations. Also very importantly, we can't just change the
import of `FunctionDecl`s without changing the import of function template
specializations because they are handled as `FunctionDecl`s.
Petr Hosek [Wed, 27 Jun 2018 05:50:43 +0000 (05:50 +0000)]
[CMake] Support passing FUCHSIA_SDK as the only variable
Now that the structure of Fuchsia SDK has been formalized, we no
longer need to pass all the different CFLAGS/LDFLAGS to the CMake
build separately, we can simply set the FUCHSIA_SDK variable and
derive all the necessary variables from that one inside the cache
file.