Jordan Rose [Fri, 26 Apr 2013 21:43:01 +0000 (21:43 +0000)]
[analyzer] An ObjC for-in loop runs 0 times if the collection is nil.
In an Objective-C for-in loop "for (id element in collection) {}", the loop
will run 0 times if the collection is nil. This is because the for-in loop
is implemented using a protocol method that returns 0 when there are no
elements to iterate, and messages to nil will result in a 0 return value.
At some point we may want to actually model this message send, but for now
we may as well get the nil case correct, and avoid the false positives that
would come with this case.
Jordan Rose [Fri, 26 Apr 2013 21:42:55 +0000 (21:42 +0000)]
[analyzer] Model casts to bool differently from other numbers.
Casts to bool (and _Bool) are equivalent to checks against zero,
not truncations to 1 bit or 8 bits.
This improved reasoning does cause a change in the behavior of the alpha
BoolAssignment checker. Previously, this checker complained about statements
like "bool x = y" if 'y' was known not to be 0 or 1. Now it does not, since
that conversion is well-defined. It's hard to say what the "best" behavior
here is: this conversion is safe, but might be better written as an explicit
comparison against zero.
More usefully, besides improving our model of booleans, this fixes spurious
warnings when returning the address of a local variable cast to bool.
[Modules] Fix an issue where the reconstructed redeclaration chain was incomplete, missing the definition from a module.
-Make sure that a deserialized external decl gets added to the TU scope.
-When associating an identifier with a set of decls, use the most recent local ones,
if they exist, otherwise associating decls from modules (that came after a local one)
will lead to an incomplete reconstructed re-declaration chain.
document parsing. When a sub-class (c++ Objective-C) missing
a comment, grab the first comment found in its class
heirarchy. Also, when a category is mossing a comment,
grab comment of its primary class. // rdar://13647476
Chad Rosier [Fri, 26 Apr 2013 20:49:50 +0000 (20:49 +0000)]
[driver] Implement the -fdebug-compilation-dir in a way that is compatible with
gcc. No test case included as I'm having problems finding a test case where
the inode/dev don't match.
Objective-C: This is a small modification to my
patch -n r180198.
When reporting on missing property accessor implementation in
categories, do not report when they are declared in primary class,
class's protocol, or one of it super classes or in of the other
categories. // rdar://13713098
Rafael Espindola [Thu, 25 Apr 2013 20:12:36 +0000 (20:12 +0000)]
Put friend decls in the correct context.
When we find a friend declaration we have to skip transparent contexts for doing
lookups, but we should not skip them when inserting the new decl if the lookup
found nothing.
This includes the following fixes:
- Implement 4 subtly different variants of qualifier mangling and use them
in what I believe are the right places.
- Fix handling of array types. Previously we were always decaying them,
which is wrong if the type appears as a template argument, pointee,
referent etc.
Fixes PR13182.
Anna Zaks [Thu, 25 Apr 2013 00:41:32 +0000 (00:41 +0000)]
[analyzer] Fix a crash in RetainCountChecker - we should not rely on CallEnter::getCallExpr to return non-NULL
We get a CallEnter with a null expression, when processing a destructor. All other users of
CallEnter::getCallExpr work fine with null as return value.
(Addresses PR15832, Thanks to Jordan for reducing the test case!)
Objective-C parsing [qoi]: Recover gracefully with good diagnostic
when class implementation declaration adds protocol qualifier
list. // rdar://12233858
Objective-C arc: Improve disgnostics when 'weak'
property cannot be synthesized because its backing
ivar does not support weak references.
// rdar://13676793
Chad Rosier [Wed, 24 Apr 2013 18:09:54 +0000 (18:09 +0000)]
[driver] Improve the implementation of the -Ofast option.
Specifically, allow the flags that fall under this umbrella (i.e., -O3,
-ffast-math, and -fstrict-aliasing) to be overridden/disabled with the
individual -O[0|1|2|s|z]/-fno- flags.
This also fixes the handling of various floating point optimization
flags that are modified by -ffast-math (and thus -Ofast as well).
Part of rdar://13622687
Objective-C: When reporting on missing property accessor implementation in
categories, do not report when they are declared in primary class,
class's protocol, or one of it super classes. This is because,
its class is going to implement them. // rdar://13713098
Summary:
Added support for multiple input files, that can be used both with and
without in-place edit (-i) option. Added checks for -offset and -length options:
don't allow them on multiple files, check that they don't fall outside input
file, made both options unsigned, so that there's no need to check for negative
values. Removed "-1 can be used for end-of-file" from -length description.
Anna Zaks [Wed, 24 Apr 2013 02:49:16 +0000 (02:49 +0000)]
[analyzer] IvarInvalidation: correctly handle cases where only partial invalidators exist
- If only partial invalidators exist and there are no full invalidators in @implementation, report every ivar that has
not been invalidated. (Previously, we reported the first Ivar in the list, which could actually have been invalidated
by a partial invalidator. The code assumed you cannot have only partial invalidators.)
- Do not report missing invalidation method declaration if a partial invalidation method declaration exists.
Anna Zaks [Tue, 23 Apr 2013 23:57:50 +0000 (23:57 +0000)]
[analyzer] Set the allocation site to be the uniqueing location for retain count checker leaks.
The uniqueing location is the location which is part of the hash used to determine if two reports are
the same. This is used by the CmpRuns.py script to compare two analyzer runs and determine which
warnings are new.
Anna Zaks [Tue, 23 Apr 2013 23:57:43 +0000 (23:57 +0000)]
[analyzer] Refactor BugReport::getLocation and PathDiagnosticLocation::createEndOfPath for greater code reuse
The 2 functions were computing the same location using different logic (each one had edge case bugs that the other
one did not). Refactor them to rely on the same logic.
The location of the warning reported in text/command line output format will now match that of the plist file.
There is one change in the plist output as well. When reporting an error on a BinaryOperator, we use the location of the
operator instead of the beginning of the BinaryOperator expression. This matches our output on command line and
looks better in most cases.
Jordan Rose [Mon, 22 Apr 2013 21:36:49 +0000 (21:36 +0000)]
[analyzer] Treat reinterpret_cast like a base cast in certain cases.
The analyzer represents all pointer-to-pointer bitcasts the same way, but
this can be problematic if an implicit base cast gets layered on top of a
manual base cast (performed with reinterpret_cast instead of static_cast).
Fix this (and avoid a valid assertion) by looking through cast regions.
Using reinterpret_cast this way is only valid if the base class is at the
same offset as the derived class; this is checked by -Wreinterpret-base-class.
In the interest of performance, the analyzer doesn't repeat this check
anywhere; it will just silently do the wrong thing (use the wrong offsets
for fields of the base class) if the user code is wrong.
Simon Atanasyan [Mon, 22 Apr 2013 20:26:27 +0000 (20:26 +0000)]
[Mips] Remove "REQUIRES: mips-registered-target" from some MIPS-related
driver tests. These tests check the driver only and do not require mips
target.
TBAA: make sure zero-length bitfield works for tbaa.struct and path-aware tbaa
For ms structs, zero-length bitfields following non-bitfield members are
completely ignored, we should not increase the field index.
Before the fix, we will have an assertion failure.
Richard Smith [Mon, 22 Apr 2013 15:31:51 +0000 (15:31 +0000)]
C++1y constexpr extensions, round 1: Allow most forms of declaration and
statement in constexpr functions. Everything which doesn't require variable
mutation is also allowed as an extension in C++11. 'void' becomes a literal
type to support constexpr functions which return 'void'.
Richard Smith [Mon, 22 Apr 2013 14:51:21 +0000 (14:51 +0000)]
cmake: Only add -pedantic if LLVM didn't add it. Don't unconditionally add
-Wall -W, since it's already provided by LLVM's cmake config, and that
overrides fixes (such as -Wno-uninitialized) which LLVM's cmake setup may have
provided.
Richard Smith [Mon, 22 Apr 2013 14:44:29 +0000 (14:44 +0000)]
Fix array constant expression evaluation bug: we can have different values for
different array elements, even if they're all constructed using the same
default constructor.
Daniel Jasper [Mon, 22 Apr 2013 07:59:53 +0000 (07:59 +0000)]
Fix bin-packing behavior of constructor initialziers.
In Google style, constructor initializers need to be all on one line or
one initializer per line if that does not fit. Without this patch, this
non-bin-packing-behavior incorrectly extends to the parameters of the
initializers.
Richard Smith [Sun, 21 Apr 2013 01:08:50 +0000 (01:08 +0000)]
The 'constexpr implies const' rule for non-static member functions is gone in
C++1y, so stop adding the 'const' there. Provide a compatibility warning for
code relying on this in C++11, with a fix-it hint. Update our lazily-written
tests to add the const, except for those ones which were testing our
implementation of this rule.
Richard Smith [Sat, 20 Apr 2013 23:28:26 +0000 (23:28 +0000)]
Disable VLA diagnostic in C++1y mode, and add some tests.
Still to do here:
- we have a collection of syntactic accepts-invalids to diagnose
- support non-PODs in VLAs, including dynamic initialization /
destruction
- runtime checks (and throw std::bad_array_length) for bad bound
- support VLA capture by reference in lambdas
- properly support VLAs in range-based for (don't recompute bound)
Richard Smith [Sat, 20 Apr 2013 22:23:05 +0000 (22:23 +0000)]
C++1y: Allow aggregates to have default initializers.
Add a CXXDefaultInitExpr, analogous to CXXDefaultArgExpr, and use it both in
CXXCtorInitializers and in InitListExprs to represent a default initializer.
There's an additional complication here: because the default initializer can
refer to the initialized object via its 'this' pointer, we need to make sure
that 'this' points to the right thing within the evaluation.
Richard Smith [Sat, 20 Apr 2013 12:57:49 +0000 (12:57 +0000)]
Clarifying memory allocation: approved for C++14. Move from N/A to no, since we currently relax 'operator new' calls which didn't come from new-expressions.