Correct handling for C++17 inline namespaces. We would previously fail to
identify the inline namespaces as a namespace name since multiple ones may be
concatenated now with C++17.
Ehsan Akhgari [Thu, 29 Oct 2015 17:20:17 +0000 (17:20 +0000)]
Add a link to the DXR project
DXR is a project developed at Mozilla that implements a code indexing
and browsing utility on top of libclang that has features such as
call graph querying.
[mips] Add support for the new mips-mti-linux toolchain.
The original commit in r249137 added the mips-mti-linux toolchain. However,
the newly added tests of that commit failed in few buildbots. This commit
re-applies the original changes but XFAILs the test file which caused
the buildbot failures. This will allow us to examine what's going wrong
without having to commit/revert large changes.
Sean Eveson [Thu, 29 Oct 2015 10:04:41 +0000 (10:04 +0000)]
[Analyzer] Widening loops which do not exit
Summary:
Dear All,
We have been looking at the following problem, where any code after the constant bound loop is not analyzed because of the limit on how many times the same block is visited, as described in bugzillas #7638 and #23438. This problem is of interest to us because we have identified significant bugs that the checkers are not locating. We have been discussing a solution involving ranges as a longer term project, but I would like to propose a patch to improve the current implementation.
Example issue:
```
for (int i = 0; i < 1000; ++i) {...something...}
int *p = 0;
*p = 0xDEADBEEF;
```
The proposal is to go through the first and last iterations of the loop. The patch creates an exploded node for the approximate last iteration of constant bound loops, before the max loop limit / block visit limit is reached. It does this by identifying the variable in the loop condition and finding the value which is “one away” from the loop being false. For example, if the condition is (x < 10), then an exploded node is created where the value of x is 9. Evaluating the loop body with x = 9 will then result in the analysis continuing after the loop, providing x is incremented.
The patch passes all the tests, with some modifications to coverage.c, in order to make the ‘function_which_gives_up’ continue to give up, since the changes allowed the analysis to progress past the loop.
This patch does introduce possible false positives, as a result of not knowing the state of variables which might be modified in the loop. I believe that, as a user, I would rather have false positives after loops than do no analysis at all. I understand this may not be the common opinion and am interested in hearing your views. There are also issues regarding break statements, which are not considered. A more advanced implementation of this approach might be able to consider other conditions in the loop, which would allow paths leading to breaks to be analyzed.
Lastly, I have performed a study on large code bases and I think there is little benefit in having “max-loop” default to 4 with the patch. For variable bound loops this tends to result in duplicated analysis after the loop, and it makes little difference to any constant bound loop which will do more than a few iterations. It might be beneficial to lower the default to 2, especially for the shallow analysis setting.
Please let me know your opinions on this approach to processing constant bound loops and the patch itself.
Regards,
Sean Eveson
SN Systems - Sony Computer Entertainment Group
GCC has a warning called -Wdouble-promotion, which warns you when
an implicit conversion increases the width of a floating point type.
This is useful when writing code for architectures that can perform
hardware FP ops on floats, but must fall back to software emulation for
larger types (i.e. double, long double).
This fixes PR15109 <https://llvm.org/bugs/show_bug.cgi?id=15109>.
Reid Kleckner [Wed, 28 Oct 2015 23:06:42 +0000 (23:06 +0000)]
[WinEH] Mark calls inside cleanups as noinline
This works around PR25162. The MSVC tables make it very difficult to
correctly inline a C++ destructor that contains try / catch. We've
attempted to address PR25162 in LLVM's backend, but it feels pretty
infeasible. MSVC and ICC both appear to avoid inlining such complex
destructors.
Long term, we want to fix this by making the inliner smart enough to
know when it is inlining into a cleanup, so it can inline simple
destructors (~unique_ptr and ~vector) while avoiding destructors
containing try / catch.
Ben Langmuir [Wed, 28 Oct 2015 22:25:37 +0000 (22:25 +0000)]
Fix missing builtin identifier infos with PCH+modules
Use the *current* state of "is-moduleness" rather than the state at
serialization time so that if we read a builtin identifier from a module
that wasn't "interesting" to that module, we will still write it out to
a PCH that imports that module.
Otherwise, we would get mysterious "unknown builtin" errors when using
PCH+modules.
Anton Yartsev [Wed, 28 Oct 2015 20:43:39 +0000 (20:43 +0000)]
[analyzer] Preserve the order checkers were enabled/disabled.
In addition to r251524: preserve the order the checkers were enabled/disabled to be deterministic.
Additionally return the number of arguments read by 'ProcessArgs' - for debug purpose.
Anton Yartsev [Wed, 28 Oct 2015 16:28:57 +0000 (16:28 +0000)]
[analyzer] Make inclusion/exclusion of checkers less ambiguous.
A checker may be enabled/disabled multiple times via -enable-checker and -disable-checker scan-build arguments. Currently the conflicting and repetitive arguments are passed to the analyzer as is.
With this patch only the last enable/disable of a particular checker is accepted and passed to the analyzer.
This change is mostly done for the upcoming 'config for scan-build' patch when multiple inclusions/exclusions of a checker are expected to be more common.
When running clang with an arm triple such as '--target=thumbv7m-none-eabi'
that has a thumb only CPU by default (cortex-m3), and when using the assembler,
the default thumb state of the CPU does not get passed via the triple to LLVM:
Daniel Jasper [Wed, 28 Oct 2015 01:08:22 +0000 (01:08 +0000)]
clang-format: When a line is formatted, also format subsequence lines if their indent is off.
Summary: This is especially important so that if a change is solely inserting a block around a few statements, clang-format-diff.py will still clean up and add indentation to the inner parts.
John McCall [Wed, 28 Oct 2015 00:17:34 +0000 (00:17 +0000)]
Add the ability to define "fake" arguments on attributes.
Fake arguments are automatically handled for serialization, cloning,
and other representational tasks, but aren't included in pretty-printing
or parsing (should we eventually ever automate that).
This is chiefly useful for attributes that can be written by the
user, but which are also frequently synthesized by the compiler,
and which we'd like to remember details of the synthesis for.
As a simple example, use this to narrow the cases in which we were
generating a specialized note for implicitly unavailable declarations.
Daniel Jasper [Tue, 27 Oct 2015 22:55:55 +0000 (22:55 +0000)]
clang-format: Increase cut-off limit for number of analyzed states.
With more complex structures in C++ Lambdas and JavaScript function
literals, the old value was simply to small. However, this is a
temporary solution, I need to look at this more closely a) to find a
fundamentally better approach and b) to look at whether the more recent
usage of NoLineBreak makes us visit stuff in an unfortunate order
where clang-format waste many states in dead ends.
Samuel Antao [Tue, 27 Oct 2015 22:20:26 +0000 (22:20 +0000)]
Minor fix in ToolChainTest.cpp to allow user defined GCC toolchain.
If the user configured clang with a custom GCC toolchain that will take precedence on what the ToolChainTest.cpp expects to evaluate.
This is fixed here by passing --gcc-toolchain= to the driver, in order to override any user defined GCC toolchain.
Anna Zaks [Tue, 27 Oct 2015 20:19:45 +0000 (20:19 +0000)]
[analyzer] Assume escape is possible through system functions taking void*
The analyzer assumes that system functions will not free memory or modify the
arguments in other ways, so we assume that arguments do not escape when
those are called. However, this may lead to false positive leak errors. For
example, in code like this where the pointers added to the rb_tree are freed
later on:
Nico Weber [Tue, 27 Oct 2015 19:47:40 +0000 (19:47 +0000)]
Tweak how -Wunused-value interacts with macros
1. Make the warning more strict in C mode. r172696 added code to suppress
warnings from macro expansions in system headers, which checks
`SourceMgr.isMacroBodyExpansion(E->IgnoreParens()->getExprLoc())`. Consider
this snippet:
#define FOO(x) (x)
void f(int a) {
FOO(a);
}
In C, the line `FOO(a)` is an `ImplicitCastExpr(ParenExpr(DeclRefExpr))`,
while it's just a `ParenExpr(DeclRefExpr)` in C++. So in C++,
`E->IgnoreParens()` returns the `DeclRefExpr` and the check tests the
SourceLoc of `a`. In C, the `ImplicitCastExpr` has the effect of checking the
SourceLoc of `FOO`, which is a macro body expansion, which causes the
diagnostic to be skipped. It looks unintentional that clang does different
things for C and C++ here, so use `IgnoreParenImpCasts` instead of
`IgnoreParens` here. This has the effect of the warning firing more often
than previously in C code – it now fires as often as it fires in C++ code.
2. Suppress the warning if it would warn on `UNREFERENCED_PARAMETER`.
`UNREFERENCED_PARAMETER` is a commonly used macro on Windows and it happens
to uselessly trigger -Wunused-value. As discussed in the thread
"rfc: winnt.h's UNREFERENCED_PARAMETER() vs clang's -Wunused-value" on
cfe-dev, fix this by special-casing this specific macro. (This costs a string
comparison and some fast-path lexing per warning, but the warning is emitted
rarely. It fires once in Windows.h itself, so this code runs at least once
per TU including Windows.h, but it doesn't run hundreds of times.)
Artem Belevich [Tue, 27 Oct 2015 17:56:59 +0000 (17:56 +0000)]
Allow linking multiple bitcode files.
Linking options for particular file depend on the option that specifies the file.
Currently there are two:
* -mlink-bitcode-file links in complete content of the specified file.
* -mlink-cuda-bitcode links in only the symbols needed by current TU.
Linked symbols are internalized. This bitcode linking mode is used to
link device-specific bitcode provided by CUDA.
Files are linked in order they are specified on command line.
Daniel Jasper [Tue, 27 Oct 2015 13:42:08 +0000 (13:42 +0000)]
clang-format: Undo unwanted format change done in r251405.
Specifically, don't wrap between the {} of an empty constructor if the
"}" falls on column 81 and ConstructorInitializerAllOnOneLineOrOnePerLine
is set.
Daniel Jasper [Tue, 27 Oct 2015 12:38:37 +0000 (12:38 +0000)]
clang-format: Add an additional value to AlignAfterOpenBracket: AlwaysBreak.
Summary:
If this option is set, clang-format will always insert a line wrap, e.g.
before the first parameter of a function call unless all parameters fit
on the same line. This obviates the need to make a decision on the
alignment itself.
Use this style for Google's JavaScript style and add some minor tweaks
to correctly handle nested blocks etc. with it. Don't use this option
for for/while loops.
Create undef reference to profile hook symbol when
PGO instrumentation is turned on. This allows
LLVM to omit emission of hook variable use method
for every single module instrumented.
John McCall [Tue, 27 Oct 2015 04:54:50 +0000 (04:54 +0000)]
Be more conservative about diagnosing "incorrect" uses of __weak:
allow them to be written in certain kinds of user declaration and
diagnose on the use-site instead.
Also, improve and fix some diagnostics relating to __weak and
properties.
Ismail Pazarbasi [Mon, 26 Oct 2015 19:20:24 +0000 (19:20 +0000)]
MismatchingNewDeleteDetector uses incorrect field, and finds no initializer
Summary:
In `MismatchingNewDeleteDetector::analyzeInClassInitializer`, if
`Field`'s initializer expression is null, lookup the field in
implicit instantiation, and use found field's the initializer.
Devin Coughlin [Mon, 26 Oct 2015 17:19:51 +0000 (17:19 +0000)]
[analyzer] ccc-analyzer: Fix -isystem value passing.
The regex for -isystem matching is broken. -[D,I,Usystem] matches "-D", "-,",
"-I", "-U", "-s" "-y", etc. Besides that, "-isystem /foo" gets interpreted as
"-i" with a non-empty value "system" and thus the next "/foo" argument is not
read. This patch corrects the regex.
This fixes PR13237 <https://llvm.org/bugs/show_bug.cgi?id=13237>.
Devin Coughlin [Sun, 25 Oct 2015 01:30:18 +0000 (01:30 +0000)]
[analyzer] scan-build: Teach ccc-analyzer about -Xclang.
Update ccc-analyzer to forward both -Xclang and its following argument to the
the compiler driver. Previously we were dropping -Xclang and forwarding the
argument on its own if it matched other forwarding criteria. This caused the
argument to be interpreted as a driver rather than a frontend option.
Benjamin Kramer [Fri, 23 Oct 2015 09:04:55 +0000 (09:04 +0000)]
[AST] Re-add TypeLocs and NestedNameSpecifierLocs to the ParentMap.
This relands r250831 after some fixes to shrink the ParentMap overall
with one addtional tweak: nodes with pointer identity (e.g. Decl* and
friends) can be store more efficiently so I put them in a separate map.
All other nodes (so far only TypeLoc and NNSLoc) go in a different map
keyed on DynTypedNode. This further uglifies the code but significantly
reduces memory overhead.
Overall this change still make ParentMap significantly larger but it's
nowhere as bad as before. I see about 25 MB over baseline (pre-r251008)
on X86ISelLowering.cpp. If this becomes an issue we could consider
splitting the maps further as DynTypedNode is still larger (32 bytes)
than a single TypeLoc (16 bytes) but I didn't want to introduce even
more complexity now.
John McCall [Thu, 22 Oct 2015 18:38:17 +0000 (18:38 +0000)]
Define weak and __weak to mean ARC-style weak references, even in MRC.
Previously, __weak was silently accepted and ignored in MRC mode.
That makes this a potentially source-breaking change that we have to
roll out cautiously. Accordingly, for the time being, actual support
for __weak references in MRC is experimental, and the compiler will
reject attempts to actually form such references. The intent is to
eventually enable the feature by default in all non-GC modes.
(It is, of course, incompatible with ObjC GC's interpretation of
__weak.)
If you like, you can enable this feature with
-Xclang -fobjc-weak
but like any -Xclang option, this option may be removed at any point,
e.g. if/when it is eventually enabled by default.
This patch also enables the use of the ARC __unsafe_unretained qualifier
in MRC. Unlike __weak, this is being enabled immediately. Since
variables are essentially __unsafe_unretained by default in MRC,
the only practical uses are (1) communication and (2) changing the
default behavior of by-value block capture.
As an implementation matter, this means that the ObjC ownership
qualifiers may appear in any ObjC language mode, and so this patch
removes a number of checks for getLangOpts().ObjCAutoRefCount
that were guarding the processing of these qualifiers. I don't
expect this to be a significant drain on performance; it may even
be faster to just check for these qualifiers directly on a type
(since it's probably in a register anyway) than to do N dependent
loads to grab the LangOptions.
David Majnemer [Thu, 22 Oct 2015 18:04:22 +0000 (18:04 +0000)]
[MS ABI] Don't crash when inheriting from base with trailing empty array member
We got this right for Itanium but not MSVC because CGRecordLayoutBuilder
was checking if the base's size was zero when it should have been
checking the non-virtual size.
Benjamin Kramer [Thu, 22 Oct 2015 15:04:10 +0000 (15:04 +0000)]
[Tooling] Add a utility function to replace one nested name with another.
One problem in clang-tidy and other clang tools face is that there is no
way to lookup an arbitrary name in the AST, that's buried deep inside Sema
and might not even be what the user wants as the new name may be freshly
inserted and not available in the AST.
A common use case for lookups is replacing one nested name with another
while minimizing namespace qualifications, so replacing 'ns::foo' with
'ns::bar' will use just 'bar' if we happen to be inside the namespace 'ns'.
This adds a little helper utility for exactly that use case.
Gabor Horvath [Thu, 22 Oct 2015 11:53:04 +0000 (11:53 +0000)]
[analyzer] Bug identification
This patch adds hashes to the plist and html output to be able to identfy bugs
for suppressing false positives or diff results against a baseline. This hash
aims to be resilient for code evolution and is usable to identify bugs in two
different snapshots of the same software. One missing piece however is a
permanent unique identifier of the checker that produces the warning. Once that
issue is resolved, the hashes generated are going to change. Until that point
this feature is marked experimental, but it is suitable for early adoption.
Benjamin Kramer [Thu, 22 Oct 2015 11:21:40 +0000 (11:21 +0000)]
[AST] Store Decl* and Stmt* directly into the ParentMap.
These are by far the most common types to be parents in the AST so it makes
sense to optimize for them. Put them directly into the value of the map.
This currently saves 32 bytes per parent in the map and a pointer
indirection at the cost of some additional complexity in the code.
Sadly this means we cannot return an ArrayRef from getParents anymore, add
a proxy class that can own a single DynTypedNode and otherwise behaves
exactly the same as ArrayRef.
For example on a random large file (X86ISelLowering.cpp) this reduces the
size of the parent map by 24 MB.
In this patch, the file static method addProfileRT is
moved to be a virtual member function of base ToolChain class.
This allows derived toolchain to override the default behavior
easily and make it consistent with Darwin toolchain (a TODO was
added for this refactoring - now removed). A new helper method
is also introduced to test if instrumentation profile option
is turned on or not.
Richard Smith [Thu, 22 Oct 2015 03:52:15 +0000 (03:52 +0000)]
[coroutines] Add lexer support for co_await, co_yield, and co_return keywords.
Add -fcoroutines flag (just for -cc1 for now) to enable the feature. Early
indications are that this will be part of -std=c++1z.
Craig Topper [Thu, 22 Oct 2015 03:13:10 +0000 (03:13 +0000)]
Fix a couple places where InsertText was being called with a pointer and size when it really expects a StringRef and a normally optional bool argument.
The pointer was being implicitly converted to a StringRef and the size was being passed into the bool. Since the bool has a default value normally, no one noticed that the wrong number of arguments was given.
Craig Topper [Thu, 22 Oct 2015 01:56:18 +0000 (01:56 +0000)]
Change SortAndUniqueProtocols to operate directly on a SmallVector rather than taking a pointer and element count that it modifies. This paves the way to directly convert the small vector into an ArrayRef without needing to explicitly pass the modified size. No functional change intended.
While there also use a range-based for loop and use append instead of insert to copy elements into the empty SmallVector."