[Driver] Support for -save-stats in AddGoldPlugin.
This patch updates AddGoldPlugin to pass stats-file to the Gold plugin,
if -save-stats is passed. It also moves the save-stats option handling
to a helper function tools::getStatsFileName.
[analyzer] When we fail to evaluate a pointer cast, escape the pointer.
If a pointer cast fails (evaluates to an UnknownVal, i.e. not implemented in the
analyzer) and such cast is in fact the last use of the pointer, the pointer
symbol is no longer referenced by the program state and a leak is
(mis-)diagnosed.
"Escape" the pointer upon a failed cast, i.e. inform the checker that we can no
longer reliably track it.
This implements support for the previously ignored flag
`-falign-functions`. This allows the frontend to request alignment on
function definitions in the translation unit where they are not
explicitly requested in code. This is compatible with the GCC behaviour
and the ICC behaviour.
The scalar value passed to `-falign-functions` aligns functions to a
power-of-two boundary. If flag is used, the functions are aligned to
16-byte boundaries. If the scalar is specified, it must be an integer
less than or equal to 4096. If the value is not a power-of-two, the
driver will round it up to the nearest power of two.
[CFG] [analyzer] Don't treat argument constructors as temporary constructors.
Function argument constructors (that are used for passing objects into functions
by value) are completely unlike temporary object constructors, but we were
treating them as such because they are also wrapped into a CXXBindTemporaryExpr.
This patch adds a partial construction context layer for call argument values,
but doesn't proceed to transform it into an actual construction context yet.
This is tells the clients that we aren't supporting these constructors yet.
[analyzer] RetainCount: Accept more "safe" CFRetain wrappers.
r315736 added support for the misplaced CF_RETURNS_RETAINED annotation on
CFRetain() wrappers. It works by trusting the function's name (seeing if it
confirms to the CoreFoundation naming convention) rather than the annotation.
There are more false positives caused by users using a different naming
convention, namely starting the function name with "retain" or "release"
rather than suffixing it with "retain" or "release" respectively.
Because this isn't according to the naming convention, these functions
are usually inlined and the annotation is therefore ignored, which is correct.
But sometimes we run out of inlining stack depth and the function is
evaluated conservatively and then the annotation is trusted.
Add support for the "alternative" naming convention and test the situation when
we're running out of inlining stack depth.
David Zarzycki [Thu, 19 Apr 2018 18:19:02 +0000 (18:19 +0000)]
[UnitTests] NFC/build-perf: Break up nontrivial compile jobs
RecursiveASTVisitorTest.cpp is one of the longest compile jobs and a
build bottleneck on many-core machines. This patch breaks that file and
some peer files up into smaller files to increase build concurrency and
overall rebuild performance.
Steven Wu [Thu, 19 Apr 2018 15:46:43 +0000 (15:46 +0000)]
[CXX] Templates specialization visibility can be wrong
Summary:
Under some conditions, LinkageComputer can get the visibility for
ClassTemplateSpecializationDecl wrong because it failed to find the Decl
that has the explicit visibility.
This fixes:
llvm.org/bugs/pr36810
rdar://problem/38080953
The force_align_arg_pointer attribute was using a hardcoded 16-byte
alignment value which in combination with -mstack-alignment=32 (or
larger) would produce a misaligned stack which could result in crashes
when accessing stack buffers using aligned AVX load/store instructions.
Fix the issue by using the "stackrealign" function attribute instead
of using a hardcoded 16-byte alignment.
[CodeGen] Do not push a destructor cleanup for a struct that doesn't
have a non-trivial destructor.
This fixes a bug introduced in r328731 where CodeGen emits calls to
synthesized destructors for non-trivial C structs in C++ mode when the
struct passed to EmitCallArg doesn't have a non-trivial destructor.
Under Microsoft's ABI, ASTContext::isParamDestroyedInCallee currently
always returns true, so it's necessary to check whether the struct has a
non-trivial destructor before pushing a cleanup in EmitCallArg.
For C++17 the wording of [over.built] p4 excluded bool:
For every pair (T , vq), where T is an arithmetic type other than bool, there exist
candidate operator functions of the form
vq T & operator++(vq T &);
T operator++(vq T &, int);
[Modules] Turn on system header validation for implicit modules
After r300027 implicit builds might fail when updating the SDK on
darwin. Make validation of system headers default when implicit modules
is on and allow modules to be rebuild when system headers change.
Erich Keane [Tue, 17 Apr 2018 22:00:54 +0000 (22:00 +0000)]
Add Microsoft mangling for _Float16
Enables _Float16 on Windows by creating a mangling
mechanism in MicrosoftMangle. It accomplishes this by
mangling as a structure type of __clang::_Float16, similar
to how Complex works.
Keith Wyss [Tue, 17 Apr 2018 21:32:43 +0000 (21:32 +0000)]
[XRay] Add clang builtin for xray typed events.
Summary:
A clang builtin for xray typed events. Differs from
__xray_customevent(...) by the presence of a type tag that is vended by
compiler-rt in typical usage. This allows xray handlers to expand logged
events with their type description and plugins to process traced events
based on type.
This change depends on D45633 for the intrinsic definition.
Teresa Johnson [Tue, 17 Apr 2018 20:36:51 +0000 (20:36 +0000)]
Require shell for test
Attempt to fix windows bot which doesn't like the "(cd .." invocation
added in r330194:
http://lab.llvm.org:8011/builders/clang-with-thin-lto-windows/builds/8704/steps/stage%202%20check/logs/stdio
Add a command line option 'fregister_global_dtors_with_atexit' to
register destructor functions annotated with __attribute__((destructor))
using __cxa_atexit or atexit.
Register destructor functions annotated with __attribute__((destructor))
calling __cxa_atexit in a synthesized constructor function instead of
emitting references to the functions in a special section.
The primary reason for adding this option is that we are planning to
deprecate the __mod_term_funcs section on Darwin in the future. This
feature is enabled by default only on Darwin. Users who do not want this
can use command line option 'fno_register_global_dtors_with_atexit' to
disable it.
Teresa Johnson [Tue, 17 Apr 2018 16:39:25 +0000 (16:39 +0000)]
[ThinLTO] Pass -save-temps to LTO backend for distributed ThinLTO builds
Summary:
The clang driver option -save-temps was not passed to the LTO config,
so when invoking the ThinLTO backends via clang during distributed
builds there was no way to get LTO to save temp files.
Getting this to work with ThinLTO distributed builds also required
changing the driver to avoid a separate compile step to emit unoptimized
bitcode when the input was already bitcode under -save-temps. Not only is
this unnecessary in general, it is problematic for ThinLTO backends since
the temporary bitcode file to the backend would not match the module path
in the combined index, leading to incorrect ThinLTO backend index-based
optimizations.
Add some infuriatingly necessary comments to this test case.
Without these comments, by "luck" the contents of SomeKit's SKWidget.h
are precisely the same as SomeKitCore's SomeKitCore.h. This can create
havoc if anything canonicalizes on the inode and your filesystem assigns
a common inode to files with identical file content. Alternatively, if
your build system uses symlinks into a content-addressed-storage (as
Google's does), you end up with these files being symlinks to the same
file.
The end result is that Clang deduplicates them internally, and then
believes that the SomeKit framework includes the SomeKitCore.h header,
and does not include the SKWidget.h in SomeKit. This in turn results in
warnings in this test and eventually errors as Clang becomes confused
because the umbrella header for SomeKitCore has already been included
into another framework's module (SomeKit). Yay.
If anyone has a better idea about how to avoid this, I'm all ears.
Nothing other than causing the file content to change worked for me.
Eli Friedman [Mon, 16 Apr 2018 23:52:58 +0000 (23:52 +0000)]
[ARM] Compute a target feature which corresponds to the ARM version.
Currently, the interaction between the triple, the CPU, and the
supported features is a mess: the driver edits the triple to indicate
the supported architecture version, and the LLVM backend uses this to
figure out what instructions are legal. This makes it difficult to
understand what's happening, and makes it impossible to LTO together two
modules with different computed architectures.
Instead of relying on triple rewriting to get the correct target
features, we should add the right target features explicitly.
Steven Wu [Mon, 16 Apr 2018 23:34:18 +0000 (23:34 +0000)]
[Availability] Improve availability to consider functions run at load time
Summary:
There are some functions/methods that run when the application launches
or the library loads. Those functions will run reguardless the OS
version as long as it satifies the minimum deployment target. Annotate
them with availability attributes doesn't really make sense because they
are essentially available on all targets since minimum deployment
target.
Erich Keane [Mon, 16 Apr 2018 21:30:08 +0000 (21:30 +0000)]
Limit types of builtins that can be redeclared.
As reported here: https://bugs.llvm.org/show_bug.cgi?id=37033
Any usage of a builtin function that uses a va_list by reference
will cause an assertion when redeclaring it.
After discussion in the review, it was concluded that the correct
way of accomplishing this fix is to make attempts to redeclare certain
builtins an error. Unfortunately, doing this limitation for all builtins
is likely a breaking change, so this commit simply limits it to
types with custom type checking and those that take a reference.
Defer adding keywords to the identifier table until after the language options have been loaded from the AST file.
This fixes issues with "class" being reported as an identifier in "enum class" because the construct is not present when using default language options.
[OPENMP] Allow to use declare target variables in map clauses
Global variables marked as declare target are allowed to be used in map
clauses. Patch fixes the crash of the compiler on the declare target
variables in map clauses.
[CodeGen] Fix a crash that occurs when a non-trivial C struct with a
volatile array field is copied.
The crash occurs because method 'visitArray' passes a null FieldDecl to
method 'visit' and some of the methods called downstream expect a
non-null FieldDecl to be passed.
This reapplies r330151 with a fix to the test case.
Given the module above, while generting autolink information during
codegen, clang should to emit '-framework SomeKitCore' only if SomeKit
was not imported in the relevant TU, otherwise it should use '-framework
SomeKit' instead.
[CodeGen] Fix a crash that occurs when a non-trivial C struct with a
volatile array field is copied.
The crash occurs because method 'visitArray' passes a null FieldDecl to
method 'visit' and some of the methods called downstream expect a
non-null FieldDecl to be passed.
[CodeView] Initial support for emitting S_THUNK32 symbols for compiler...
When emitting CodeView debug information, compiler-generated thunk routines
should be emitted using S_THUNK32 symbols instead of S_GPROC32_ID symbols so
Visual Studio can properly step into the user code. This initial support only
handles standard thunk ordinals.
Clean carriage returns from lib/ and include/. NFC.
Summary:
Clean carriage returns from lib/ and include/. NFC.
(I have to make this change locally in order for `git diff` to show sane output after I edit a file, so I might as well ask for it to be committed. I don't have commit privs myself.)
(Without this patch, `git rebase`ing any change involving SemaDeclCXX.cpp is a real nightmare. :( So while I have no right to ask for this to be committed, geez would it make my workflow easier if it were.)
Here's the command I used to reformat things. (Requires bash and OSX/FreeBSD sed.)
git grep -l $'\r' lib include | xargs sed -i -e $'s/\r//'
find lib include -name '*-e' -delete
Henry Wong [Sun, 15 Apr 2018 10:34:06 +0000 (10:34 +0000)]
[analyzer] Do not invalidate the `this` pointer.
Summary:
`this` pointer is not an l-value, although we have modeled `CXXThisRegion` for `this` pointer, we can only bind it once, which is when we start to inline method. And this patch fixes https://bugs.llvm.org/show_bug.cgi?id=35506.
In addition, I didn't find any other cases other than loop-widen that could invalidate `this` pointer.
stderr: Assertion failed: (M && "imported decl from no module file"), function loadPendingDeclChain, file /Users/vsk/src/llvm.org-lldbsan/llvm/tools/clang/lib/Serialization/ASTReaderDecl.cpp, line 3861.
Adam Balogh [Fri, 13 Apr 2018 20:23:02 +0000 (20:23 +0000)]
[Analyzer] Fix for SValBuilder expressions rearrangement
Expression rearrangement in SValBuilder (see rL329780) crashes with an assert if the type of the integer is different from the type of the symbol. This fix adds a check that prevents rearrangement in such cases.
Fix evaluation of `__has_include_next` during -frewrite-includes.
`__has_include_next` requires correct DirectoryLookup for being
evaluated correctly. We were using Preprocessor::GetCurDirLookup() but
we were calling it after the preprocessor finished its work. And in this
case CurDirLookup is always nullptr which makes `__has_include_next`
behave as `__has_include`.
Fix by storing and using CurDirLookup when preprocessor enters a file,
not when we rewrite the includes.
[clang-format] Improve Incomplete detection for (text) protos
Summary:
This patch improves detection of incomplete code for protos and text protos.
This is especially important for text protos in raw string literals, since they
might be partial strings concatenated, and we'd like to disable formatting in
these cases.
It's important to be able to do this in cases where we'd like to
specialise the configuration for the invocation of the compiler, in
various scripting environments.
This is related to llvm.org/PR37066, a follow-up to D45474.
[XRay][clang] Add flag to choose instrumentation bundles
Summary:
This change addresses http://llvm.org/PR36926 by allowing users to pick
which instrumentation bundles to use, when instrumenting with XRay. In
particular, the flag `-fxray-instrumentation-bundle=` has four valid
values:
- `all`: the default, emits all instrumentation kinds
- `none`: equivalent to -fnoxray-instrument
- `function`: emits the entry/exit instrumentation
- `custom`: emits the custom event instrumentation
These can be combined either as comma-separated values, or as
repeated flag values.
Eli Friedman [Thu, 12 Apr 2018 22:50:50 +0000 (22:50 +0000)]
Fix test failure caused by r329965.
"-mllvm" options get parsed slightly earlier, and -arm-restrict-it is
only available if the ARM target is compiled in. Invoke "clang -cc1"
directly to avoid the issue.
Martin Storsjo [Thu, 12 Apr 2018 20:07:38 +0000 (20:07 +0000)]
[MinGW] Look for libc++ headers in a triplet prefixed path as well
This makes it consistent with libstdc++ and the other default
include directories.
If these headers are found in both locations and one isn't a
symlink to the other, this will cause errors due to libc++ headers
having wrapper headers for some standard C headers, wrappers that
do #include_next the actual one.
If the same libc++ standard C wrapper header exists in more than one
include directory before the real system one, the header include
guard will stop it from doing another #include_next to pick up the
real one, breaking things.
As this is a rather uncommon situation, this should be acceptable
and toolchain maintainers can adapt accordingly if necessary.
Also simplify some of the existing code with a local variable.
Correctly diagnose when a conversion function is declared with a type qualifier in the declaration specifiers rather than in the conversion type id. Fixes PR30595.
This looks fairly odd, as we could have kept the category extension
on the previous line.
Category extensions are a single item, so they are generally very
short compared to protocol lists. We should prefer breaking after the
opening `<` of the protocol list over breaking after the opening `(`
of the category extension.
With this diff, we now avoid breaking after the category extension's
open paren, which causes us to break after the protocol list's
open angle bracket:
Test Plan: New test added. Confirmed test failed before diff and
passed after diff by running:
% make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests
Ben Hamilton [Thu, 12 Apr 2018 15:11:53 +0000 (15:11 +0000)]
[clang-format] Improve ObjC guessing heuristic by supporting all @keywords
Summary:
This diff improves the Objective-C guessing heuristic by
replacing the hard-coded list of a subset of Objective-C @keywords
with a general check which supports all @keywords.
I also added a few more Foundation keywords which were missing from
the heuristic.
Test Plan: Unit tests updated. Ran tests with:
% make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests
Ben Hamilton [Thu, 12 Apr 2018 15:11:51 +0000 (15:11 +0000)]
[clang-format] Don't insert space between ObjC class and lightweight generic
Summary:
In D45185, I added clang-format parser support for Objective-C
generics. However, I didn't touch the whitespace logic, so they
got the same space logic as Objective-C protocol lists.
In every example in the Apple SDK and in the documentation,
there is no space between the class name and the opening `<`
for the lightweight generic specification, so this diff
removes the space and updates the tests.
Test Plan: Tests updated. Ran tests with:
% make -j16 FormatTests && ./tools/clang/unittests/Format/FormatTests
Summary:
Currently, indentation of Objective-C method names which are wrapped
onto the next line due to a long return type is controlled by the
style option `IndentWrappedFunctionNames`.
This diff changes the behavior so we always indent wrapped Objective-C
selector names.
NOTE: I partially reverted https://github.com/llvm-mirror/clang/commit/6159c0fbd1876c7f5f984b4830c664cc78f16e2e / rL242484, as it was causing wrapped selectors to be double-indented. Its tests in FormatTestObjC.cpp still pass.
Test Plan: Tests updated. Ran tests with:
% make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests
Diagnose cases of "return x" that should be "return std::move(x)" for efficiency
Summary:
This patch adds two new diagnostics, which are off by default:
**-Wreturn-std-move**
This diagnostic is enabled by `-Wreturn-std-move`, `-Wmove`, or `-Wall`.
Diagnose cases of `return x` or `throw x`, where `x` is the name of a local variable or parameter, in which a copy operation is performed when a move operation would have been available. The user probably expected a move, but they're not getting a move, perhaps because the type of "x" is different from the return type of the function.
A place where this comes up in the wild is `stdext::inplace_function<Sig, N>` which implements conversion via a conversion operator rather than a converting constructor; see https://github.com/WG21-SG14/SG14/issues/125#issue-297201412
Another place where this has come up in the wild, but where the fix ended up being different, was
where the appropriate fix in that case was to replace `throw ex;` with `throw;`, and incidentally to catch by reference instead of by value. (But one could contrive a scenario where the slicing was intentional, in which case throw-by-move would have been the appropriate fix after all.)
Another example (intentional slicing to a base class) is dissected in https://github.com/accuBayArea/Slides/blob/master/slides/2018-03-07.pdf
**-Wreturn-std-move-in-c++11**
This diagnostic is enabled only by the exact spelling `-Wreturn-std-move-in-c++11`.
Diagnose cases of "return x;" or "throw x;" which in this version of Clang *do* produce moves, but which prior to Clang 3.9 / GCC 5.1 produced copies instead. This is useful in codebases which care about portability to those older compilers.
The name "-in-c++11" is not technically correct; what caused the version-to-version change in behavior here was actually CWG 1579, not C++14. I think it's likely that codebases that need portability to GCC 4.9-and-earlier may understand "C++11" as a colloquialism for "older compilers." The wording of this diagnostic is based on feedback from @rsmith.
**Discussion**
Notice that this patch is kind of a negative-space version of Richard Trieu's `-Wpessimizing-move`. That diagnostic warns about cases of `return std::move(x)` that should be `return x` for speed. These diagnostics warn about cases of `return x` that should be `return std::move(x)` for speed. (The two diagnostics' bailiwicks do not overlap: we don't have to worry about a `return` statement flipping between the two states indefinitely.)
I propose to write a paper for San Diego that would relax the implicit-move rules so that in C++2a the user //would// see the moves they expect, and the diagnostic could be re-worded in a later version of Clang to suggest explicit `std::move` only "in C++17 and earlier." But in the meantime (and/or forever if that proposal is not well received), this diagnostic will be useful to detect accidental copy operations.