Daniel Jasper [Fri, 15 Feb 2013 20:33:06 +0000 (20:33 +0000)]
Recognize < and > as binary expressions in builder-type calls.
The current heuristic assumes that there can't be binary operators in
builder-type calls (excluding assigments). However, it also excluded
< and > in general, which is wrong. Now they are only excluded if they
are template parameters.
When a statement is dropped from the AST because it was invalid, make sure
we don't do the scope checks otherwise we are going to hit assertion checks
since a label may not have been actually added.
This got lost and was untested as the same effect is achieved by
avoiding bin packing, which is active in Google style by default.
However, moving forward, we want more control over the bin packing
option(s) and thus, this flag should work as expected.
Jordan Rose [Fri, 15 Feb 2013 01:23:24 +0000 (01:23 +0000)]
[analyzer] Don't assert when mixing reinterpret_cast and derived-to-base casts.
This just adds a very simple check that if a DerivedToBase CastExpr is
operating on a value with known C++ object type, and that type is not the
base type specified in the AST, then the cast is invalid and we should
return UnknownVal.
In the future, perhaps we can have a checker that specifies that this is
illegal, but we still shouldn't assert even if the user turns that checker
off.
Jordan Rose [Fri, 15 Feb 2013 00:32:15 +0000 (00:32 +0000)]
Re-apply "[analyzer] Model trivial copy/move ctors with an aggregate bind."
...after a host of optimizations related to the use of LazyCompoundVals
(our implementation of aggregate binds).
Originally applied in r173951.
Reverted in r174069 because it was causing hangs.
Re-applied in r174212.
Reverted in r174265 because it was /still/ causing hangs.
If this needs to be reverted again it will be punted to far in the future.
Jordan Rose [Fri, 15 Feb 2013 00:32:10 +0000 (00:32 +0000)]
[analyzer] Scan the correct store when finding symbols in a LazyCompoundVal.
Previously, we were scanning the current store. Now, we properly scan the
store that the LazyCompoundVal came from, which may have very different
live symbols.
Jordan Rose [Fri, 15 Feb 2013 00:32:06 +0000 (00:32 +0000)]
[analyzer] Use collectSubRegionKeys to make removeDeadBindings faster.
Previously, whenever we had a LazyCompoundVal, we crawled through the
entire store snapshot looking for bindings within the LCV's region. Now, we
just ask for the subregion bindings of the lazy region and only visit those.
This is an optimization (so no test case), but it may allow us to clean up
more dead bindings than we were previously.
This is going to be used in the next commit.
While I'm here, tighten up assumptions about symbolic offset
BindingKeys, and make offset calculation explicitly handle all
MemRegion kinds.
objective-C: synthesize properties in order of their
declarations to synthesize their ivars in similar
determinstic order so they are laid out in
a determinstic order. // rdar://13192366
objective-C: When implementing custom accessor method for
a property, the -Wdirect-ivar-access should not warn when
accessing the property's synthesized instance variable.
// rdar://13142820
Jordan Rose [Thu, 14 Feb 2013 19:06:11 +0000 (19:06 +0000)]
[analyzer] Try constant-evaluation for all variables, not just globals.
In C++, constants captured by lambdas (and blocks) are not actually stored
in the closure object, since they can be expanded at compile time. In this
case, they will have no binding when we go to look them up. Previously,
RegionStore thought they were uninitialized stack variables; now, it checks
to see if they are a constant we know how to evaluate, using the same logic
as r175026.
This particular code path is only for scalar variables. Constant arrays and
structs are still unfortunately unhandled; we'll need a stronger solution
for those.
This may have a small performance impact, but only for truly-undefined
local variables, captures in a non-inlined block, and non-constant globals.
Even then, in the non-constant case we're only doing a quick type check.
Daniel Jasper [Thu, 14 Feb 2013 09:58:41 +0000 (09:58 +0000)]
Remove the trailing whitespace of formatted lines.
So far, clang-format has always assumed the whitespace belonging to the
subsequent token. This has the negative side-effect that when
clang-format formats a line, it does not remove its trailing whitespace,
as it belongs to the next token.
Thus, this patch fixes most of llvm.org/PR15062.
We are not zapping a file's trailing whitespace so far, as this does not
belong to any token we see during formatting. We need to fix this in a
subsequent patch.
Rafael Espindola [Thu, 14 Feb 2013 01:47:04 +0000 (01:47 +0000)]
merge hasCLanguageLinkage and isExternC. Keep the shorter name.
I added hasCLanguageLinkage while fixing some language linkage bugs some
time ago so that I wouldn't have to check all users of isExternC. It turned
out to be a much longer detour than expected, but this patch finally
merges the two again. The isExternC function now implements just the
standard notion of having C language linkage.
Rafael Espindola [Thu, 14 Feb 2013 01:18:37 +0000 (01:18 +0000)]
Add a getLanguageLinkage method to VarDecls and FunctionDecls. Use it to fix
some cases where functions with no language linkage were being treated as having
C language linkage. In particular, don't warn in
extern "C" {
static NonPod foo();
}
Since getLanguageLinkage checks the language linkage, the linkage computation
cannot use the language linkage. Break the loop by checking just the context
in the linkage computation.
Nick Lewycky [Thu, 14 Feb 2013 00:55:17 +0000 (00:55 +0000)]
When marking derived classes' virtual methods ODR-used in order to trigger
instantiation in order to permit devirtualization later in codegen, skip over
pure functions since those can't be devirtualization targets.
objective-C: Make order of ivars which are synthesized
in the course of property synthesis deterministic (ordered
by their type size), instead of having hashtable order
(as it is currently). // rdar://13192366
Richard Smith [Wed, 13 Feb 2013 21:18:23 +0000 (21:18 +0000)]
ubsan: Add checking for invalid downcasts. Per [expr.static.cast]p2 and p11,
base-to-derived casts have undefined behavior if the object is not actually an
instance of the derived type.
Manuel Klimek [Wed, 13 Feb 2013 10:46:36 +0000 (10:46 +0000)]
An attempt to make the search algorithm easier to understand.
- clear ownership: the SpecificBumpPtrAllocator owns all StateNodes
- this allows us to simplify the memoization data structure into a
std::set (FIXME: figure out whether we want to use a hash based
data structure).
- introduces StateNode as recursive data structure, instead of using
Edge and the Seen-map combined to drill through the graph
- using a count to stabilize the penalty instead of relying on the
container
- pulled out a method to forward-apply states in the end
This leads to a ~40% runtime decrease on Nico's benchmark.
Main FiXME is that the parameter lists of some function get too long.
I'd vote for either pulling the Queue etc into the Formatter proper,
or creating an inner class just for the search algorithm.
Jordan Rose [Wed, 13 Feb 2013 03:11:06 +0000 (03:11 +0000)]
[analyzer] Use Clang's evaluation for global constants and default arguments.
Previously, we were handling only simple integer constants for globals and
the smattering of implicitly-valued expressions handled by Environment for
default arguments. Now, we can use any integer constant expression that
Clang can evaluate, in addition to everything we handled before.
Dmitri Gribenko [Tue, 12 Feb 2013 17:27:41 +0000 (17:27 +0000)]
Accept over-qualified constructor in MSVC emulation mode
MSVC accepts this:
class A {
A::A();
};
Clang accepts regular member functions with extra qualification as an MS
extension, but not constructors. This changes the parser to defer rejecting
qualified constructors so that the same Sema logic can apply to constructors as
regular member functions. This also improves the error message when MS
extensions are disabled (in my opinion). Before it was:
/Users/jason/Desktop/test.cpp:2:8: error: expected member name or ';' after declaration specifiers
A::A();
~~~~ ^
1 error generated.
After:
/Users/jason/Desktop/test.cpp:2:6: error: extra qualification on member 'A'
A::A();
~~~^
1 error generated.
Nico Weber [Tue, 12 Feb 2013 16:17:07 +0000 (16:17 +0000)]
Formatter: Correctly format stars in `sizeof(int**)` and similar places.
This redoes how '*' and '&' are classified as pointer / reference markers when
followed by ')', '>', or ','.
Previously, determineStarAmpUsage() marked a single '*' and '&' followed by
')', '>', or ',' as pointer or reference marker. Now, all '*'s and '&'s
preceding ')', '>', or ',' are marked as pointer / reference markers. Fixes
PR14884.
Since only the last '*' in 'int ***' was marked as pointer before (the rest
were unary operators, which don't reach spaceRequiredBetween()),
spaceRequiredBetween() now had to be thought about handing multiple '*'s in
sequence.
Nick Lewycky [Tue, 12 Feb 2013 08:08:54 +0000 (08:08 +0000)]
The meat of this patch is in BuildCXXMemberCalLExpr where we make it use
MarkMemberReferenced instead of marking functions referenced directly. An audit
of callers to MarkFunctionReferenced and DiagnoseUseOfDecl also caused a few
other changes:
* don't mark functions odr-used when considering them for an initialization
sequence. Do mark them referenced though.
* the function nominated by the cleanup attribute should be diagnosed.
* operator new/delete should be diagnosed when building a 'new' expression.
Richard Smith [Tue, 12 Feb 2013 05:48:23 +0000 (05:48 +0000)]
Fix a bug reduced from a crash when trying to use modules with libc++. We check
the linkage of functions and variables while merging declarations from modules,
and we don't necessarily have enough of the rest of the AST loaded at that
point to allow us to compute linkage, so serialize it instead.
Richard Smith [Tue, 12 Feb 2013 02:32:35 +0000 (02:32 +0000)]
Remove an assert which triggers when a decl context in a module hits the 'has
lexical storage but not visible storage' case in C++. It's unclear whether we
even need the special-case handling for C++, since it seems to be working
around our not serializing a lookup table for the TU in C. But in any case,
the assertion is incorrect.
Lang Hames [Mon, 11 Feb 2013 23:44:11 +0000 (23:44 +0000)]
When generating IR for default copy-constructors, copy-assignment operators,
move-constructors and move-assignment operators, use memcpy to copy adjacent
POD members.
Previously, classes with one or more Non-POD members would fall back on
element-wise copies for all members, including POD members. This often
generated a lot of IR. Without padding metadata, it wasn't often possible
for the LLVM optimizers to turn the element-wise copies into a memcpy.
This code hasn't yet received any serious tuning. I didn't see any serious
regressions on a self-hosted clang build, or any of the nightly tests, but
I think it's important to get this out in the wild to get more testing.
Insights, feedback and comments welcome.
Many thanks to David Blaikie, Richard Smith, and especially John McCall for
their help and feedback on this work.
Richard Smith [Mon, 11 Feb 2013 22:02:16 +0000 (22:02 +0000)]
Don't bother reconciling external visible decls against our current set of
declarations if we didn't have a lookup map when the external decls were added.