Commit Graph

2397 Commits

Author SHA1 Message Date
Anna Zaks 44dc91b4df [analyzer] add LocationContext::inTopFrame() helper.
llvm-svn: 167351
2012-11-03 02:54:16 +00:00
Ted Kremenek b9f7aa46dd Fix potential null deference in CFG printer.
llvm-svn: 165836
2012-10-12 22:56:31 +00:00
Ted Kremenek 451c4d51ae Remove dead store.
llvm-svn: 165835
2012-10-12 22:56:26 +00:00
Ted Kremenek 6fdefb5495 Conditionally use an integral cast for BodyFarm support for OSAtomicCompareAndSwap if the return type is not a boolean.
llvm-svn: 165774
2012-10-12 00:18:19 +00:00
Ted Kremenek 089ffd0889 Switch over to BodyFarm implementation of OSAtomicCompareAndSwap and
objc_atomicCompareAndSwap.

llvm-svn: 165743
2012-10-11 20:58:18 +00:00
DeLesley Hutchins 1fe885614d Thread-safety analysis: allow attributes on constructors to refer to 'this'.
llvm-svn: 165339
2012-10-05 22:38:19 +00:00
Lang Hames 5de91cc35f Add FP_CONTRACT support for clang.
Clang will now honor the FP_CONTRACT pragma and emit LLVM
fmuladd intrinsics for expressions of the form A * B + C (when they occur in a
single statement).

llvm-svn: 164989
2012-10-02 04:45:10 +00:00
Benjamin Kramer 5721daae02 Avoid malloc thrashing in the uninitialized value analysis.
- The size of the packed vector is often small, save mallocs using SmallBitVector.
- Copying SmallBitVectors is also cheap, remove a level of indirection.

llvm-svn: 164827
2012-09-28 16:44:29 +00:00
Ted Kremenek 3d0ec38cb4 Add clarifying comment.
llvm-svn: 164557
2012-09-24 21:17:14 +00:00
Ted Kremenek e7ad535e66 Experiment in BodyFarm of structuring AST creation calls in a hierarchy,
so that they visually look like an AST dump.

llvm-svn: 164401
2012-09-21 18:33:56 +00:00
Ted Kremenek f465dc1553 Create helper method in BodyFarm for creating simple assignments.
llvm-svn: 164400
2012-09-21 18:33:54 +00:00
Ted Kremenek dff3553e3c Add helper method in BodyFarm to create unary dereferences.
llvm-svn: 164399
2012-09-21 18:33:52 +00:00
Ted Kremenek ca90ea5ed0 Add helper method to BodyFarm for creating lvalue-to-rvalue conversions.
llvm-svn: 164397
2012-09-21 18:13:27 +00:00
Ted Kremenek 69bcb82c59 Add helper method to BodyFarm for creatinging integral casts.
llvm-svn: 164396
2012-09-21 18:13:23 +00:00
DeLesley Hutchins 10958cae09 Thread-safety analysis: better handling of unreachable blocks. Fixes a bug
where a call to function marked 'noreturn' is followed by unreachable
implicit destructor calls.

llvm-svn: 164394
2012-09-21 17:57:00 +00:00
Ted Kremenek 7241813bd7 Use helper method to create DeclRefExprs in BodyFarm, hopefully allevating
them being correctly constructed.

llvm-svn: 164392
2012-09-21 17:54:35 +00:00
Ted Kremenek 2b5c83ca8f Add some structuring comments. No functionality change.
llvm-svn: 164391
2012-09-21 17:54:32 +00:00
Ted Kremenek d81a4a18b4 Add faux-body support for dispatch_once().
llvm-svn: 164348
2012-09-21 00:52:24 +00:00
Ted Kremenek 14f779c4d6 Implement faux-body-synthesis of well-known functions in the static analyzer when
their implementations are unavailable.  Start by simulating dispatch_sync().

This change is largely a bunch of plumbing around something very simple.  We
use AnalysisDeclContext to conjure up a fake function body (using the
current ASTContext) when one does not exist.  This is controlled
under the analyzer-config option "faux-bodies", which is off by default.

The plumbing in this patch is largely to pass the necessary machinery
around.  CallEvent needs the AnalysisDeclContextManager to get
the function definition, as one may get conjured up lazily.

BugReporter and PathDiagnosticLocation needed to be relaxed to handle
invalid locations, as the conjured body has no real source locations.
We do some primitive recovery in diagnostic generation to generate
some reasonable locations (for arrows and events), but it can be
improved.

llvm-svn: 164339
2012-09-21 00:09:11 +00:00
DeLesley Hutchins fcb0ffa622 Thread-safety analysis: fix bug where shared trylock was treated
as exclusive.

llvm-svn: 164332
2012-09-20 23:14:43 +00:00
DeLesley Hutchins b78aeed26e Thread safety analysis: properly canonicalize calls to virtual methods within
lock expressions.

llvm-svn: 164324
2012-09-20 22:18:02 +00:00
DeLesley Hutchins 132f8f6959 Thread-safety analysis: Fix warning when EXCLUSIVE_LOCKS_REQUIRED
is placed on a function that has no path to the exit block.

llvm-svn: 164244
2012-09-19 19:49:40 +00:00
DeLesley Hutchins a15e1b4f63 Thread-safety analysis: fix ICE when EXCLUSIVE_LOCKS_REQUIRED or
LOCKS_EXCLUDED is used on a method with a name that is is not a simple
identifier.

llvm-svn: 164242
2012-09-19 19:18:29 +00:00
NAKAMURA Takumi 72f05bccc9 clang/lib/Analysis/ObjCNoReturn.cpp: Fix [-Wnewline-eof]
llvm-svn: 163775
2012-09-13 05:53:17 +00:00
Jordan Rose 4c266aa371 Format strings: offer a fixit for Darwin's %D/%U/%O to ISO %d/%u/%o.
<rdar://problem/12061922>

llvm-svn: 163772
2012-09-13 02:11:15 +00:00
Jordan Rose 510260c2bf Format strings: %D, %U, and %O are valid on Darwin (same as %d, %u, %o).
These will warn under -Wformat-non-iso, and will still be rejected
outright on other platforms.

<rdar://problem/12061922>

llvm-svn: 163771
2012-09-13 02:11:03 +00:00
Ted Kremenek edf22edca0 Teach -Wuninitialized to recognize common "noreturn" idioms in
Objective-C related to NSException.

Fixes <rdar://problem/12287498>

I debated whether or not this logic should be sunk into the CFG
itself.  It's not clear if we should, as different analyses may
wish to have different policies.  We can re-evaluate this in the
future.

llvm-svn: 163760
2012-09-13 00:21:35 +00:00
Ted Kremenek 8b3f938697 Refactor logic in ExprEngine for detecting 'noreturn' methods
in NSException to a helper object in libAnalysis that can also
be used by Sema.  Not sure if the predicate name 'isImplicitNoReturn'
is the best one, but we can massage that later.

No functionality change.

llvm-svn: 163759
2012-09-13 00:21:31 +00:00
Ted Kremenek 7979ccf35a Teach -Wuninitialized to recognize __attribute__((analyzer_noreturn))
for halting the propagation of uninitialized value tracking along
a path.  Unlike __attribute__((noreturn)), this attribute (which
is used by clients of the static analyzer) can be used to annotate
functions that essentially never return, but in rare cares may be
allowed to return for (special) debugging purposes.  This attribute
has been shown in reducing false positives in the static analyzer
by pruning false postives, and is equally applicable here.

Handling this attribute in the CFG itself is another option, but
this is not something all clients (e.g., possibly -Wunreachable-code)
would want to see.

Addresses <rdar://problem/12281583>.

llvm-svn: 163681
2012-09-12 05:53:43 +00:00
DeLesley Hutchins 138568b60a Thread-safety analysis: fix bug in expression matching code.
llvm-svn: 163656
2012-09-11 23:04:49 +00:00
Dmitri Gribenko 76bb5cabfa Remove redundant semicolons which are null statements.
llvm-svn: 163546
2012-09-10 21:20:09 +00:00
DeLesley Hutchins 5ff1644e62 Thread-safety analysis: differentiate between two forms of analysis; a precise
analysis that may give false positives because it is confused by aliasing, and
a less precise analysis that has fewer false positives, but may have false
negatives.  The more precise warnings are enabled by -Wthread-safety-precise.
An additional note clarify the warnings in the precise case.

llvm-svn: 163537
2012-09-10 19:58:23 +00:00
Jordan Rose 2f9cc04251 Format strings: suggest %lld instead of %qd and %Ld with -Wformat-non-iso.
As a corollary to the previous commit, even when an extension is
available, we can still offer a fixit to the standard modifier.

llvm-svn: 163453
2012-09-08 04:00:12 +00:00
Jordan Rose 92303592c3 Format strings: %Ld isn't available on Darwin or Windows.
This seems to be a GNU libc extension; we offer a fixit to %lld on
these platforms.

<rdar://problem/11518237>

llvm-svn: 163452
2012-09-08 04:00:03 +00:00
Chad Rosier 37a8563f36 Ampersand goes with identifier.
llvm-svn: 163410
2012-09-07 19:49:55 +00:00
Chad Rosier 78af00f675 Bring buildbots back. Fix scoping issue and coding style from r163397.
llvm-svn: 163403
2012-09-07 18:44:15 +00:00
DeLesley Hutchins a5a00e830a Thread-safety analysis: Add support for selectively turning off warnings
within part of a particular method.

llvm-svn: 163397
2012-09-07 17:34:53 +00:00
Roman Divacky e637711ae0 Dont cast away const needlessly. Found by gcc48 -Wcast-qual.
llvm-svn: 163325
2012-09-06 15:59:27 +00:00
Jordan Rose 6d671cc34a [analyzer] Always include destructors in the analysis CFG.
While destructors will continue to not be inlined (unless the analyzer
config option 'c++-inlining' is set to 'destructors'), leaving them out
of the CFG is an incomplete model of the behavior of an object, and
can cause false positive warnings (like PR13751, now working).

Destructors for temporaries are still not on by default, since
(a) we haven't actually checked this code to be sure it's fully correct
    (in particular, we probably need to be very careful with regard to
    lifetime-extension when a temporary is bound to a reference,
    C++11 [class.temporary]p5), and
(b) ExprEngine doesn't actually do anything when it sees a temporary
    destructor in the CFG -- not even invalidate the object region.

To enable temporary destructors, set the 'cfg-temporary-dtors' analyzer
config option to '1'. The old -cfg-add-implicit-dtors cc1 option, which
controlled all implicit destructors, has been removed.

llvm-svn: 163264
2012-09-05 22:55:23 +00:00
DeLesley Hutchins 93b1b031c1 Thread-safety analysis: bugfix for case where a trylock occurs in an
expression involving temporaries.

llvm-svn: 163237
2012-09-05 20:01:16 +00:00
DeLesley Hutchins f5cf7903d9 Thread-safety analysis: fix handling of LOCK_RETURNED attribute so that the
latest definition of a function is always used when computing lock expressions.

llvm-svn: 163028
2012-08-31 22:09:53 +00:00
DeLesley Hutchins 3c3d57bc16 Thread-safety analysis: fix handling of string constants in mutex
expressions, which should be ignored right now.

llvm-svn: 163026
2012-08-31 21:57:32 +00:00
Ted Kremenek 64fea5fc8f Teach CFG that 'if (x & 0)' and 'if (x * 0)' is an unfeasible branch.
Fixes <rdar://problem/11005770>.

llvm-svn: 162545
2012-08-24 07:42:09 +00:00
Jordan Rose e5d5393efc [analyzer] Support C++ default arguments if they are literal values.
A CXXDefaultArgExpr wraps an Expr owned by a ParmVarDecl belonging to the
called function. In general, ExprEngine and Environment ought to treat this
like a ParenExpr or other transparent wrapper expression, with the inside
expression evaluated first.

However, if we call the same function twice, we'd produce a CFG that contains
the same wrapped expression twice, and we're not set up to handle that. I've
added a FIXME to the CFG builder to come back to that, but meanwhile we can
at least handle expressions that don't need to be explicitly evaluated:
literals. This probably handles many common uses of default parameters:
true/false, null, etc.

Part of PR13385 / <rdar://problem/12156507>

llvm-svn: 162453
2012-08-23 18:10:53 +00:00
Ted Kremenek 78094caa56 Fix an assortment of doxygen comment issues found by -Wdocumentation.
llvm-svn: 162412
2012-08-22 23:50:41 +00:00
Ted Kremenek d94854a42e Rename 'currentX' to 'currX' throughout analyzer and libAnalysis.
Also rename 'getCurrentBlockCounter()' to 'blockCount()'.

This ripples a bunch of code simplifications; mostly aesthetic,
but makes the code a bit tighter.

llvm-svn: 162349
2012-08-22 06:26:15 +00:00
Anna Zaks 23665a1bcf [analyzer] Teach live variable analyzes that super uses self pointer.
llvm-svn: 161822
2012-08-14 00:36:20 +00:00
DeLesley Hutchins 0c90c2bc4b Thread-safety-analysis: adds existential quantification over lock
expressions.  The syntax &MyClass::mutex is interpreted as a
pattern that matches m->mutex for any object m of type MyClass.

llvm-svn: 161691
2012-08-10 20:29:46 +00:00
DeLesley Hutchins 9b1d72f3e3 Thread safety analysis: refactor to support more sophisticated handling
of expressions, and better error messages.

llvm-svn: 161690
2012-08-10 20:19:55 +00:00
DeLesley Hutchins c9776faa4f Refactor thread safety analysis to use a different data structure
to track locksets.  This is in preparation for further changes.

llvm-svn: 161680
2012-08-10 18:39:05 +00:00