Commit Graph

2430 Commits

Author SHA1 Message Date
Ted Kremenek 990464cb30 Teach the static analyzer to not treat XPC types as CF types.
llvm-svn: 147506
2012-01-04 00:35:48 +00:00
DeLesley Hutchins 714296cb31 Support for thread safety attributes on functions
llvm-svn: 147331
2011-12-29 00:56:48 +00:00
Hans Wennborg e5f554ac48 Support the 'a' scanf length modifier as an extension in C++.
It should not be supported in C++11, since that uses the C99 standard
library, in which 'a' is a format specifier.

llvm-svn: 147310
2011-12-28 13:10:50 +00:00
Zhongxing Xu 86a68d078c Enable the user to control whether CXXConstructExpr will be added as a
block-level expr. Currently CXXConstructExpr is always added as a block-level
expr. This caused two problems for the analyzer (and potentially for the
CFG-based codegen).
1. We have no way to know whether a ctor call is base or complete.
2. We have no way to know the destination object being contructed.

llvm-svn: 147306
2011-12-28 04:38:46 +00:00
Ted Kremenek 72be32af88 Colorize and condense CFG pretty-printing.
llvm-svn: 147203
2011-12-22 23:33:52 +00:00
Ted Kremenek 299cfb7a02 Enhance AnalysisDeclContext::getReferencedBlockVars() to understand PseudoObjExprs. It turns out
that the information collected by this method is a super set of the captured variables in BlockDecl.

llvm-svn: 147122
2011-12-22 01:30:46 +00:00
Ted Kremenek c177d9faf5 Fix regression in LiveVariables when reasoning about variables captured by blocks.
llvm-svn: 147116
2011-12-22 00:46:32 +00:00
Ted Kremenek 1a7648b666 Improve CFG pretty-printing for CXXConstructExprs.
llvm-svn: 147068
2011-12-21 19:39:59 +00:00
Ted Kremenek 0ffba93e51 Improve CFG pretty-printing of CastExprs.
llvm-svn: 147066
2011-12-21 19:32:38 +00:00
Chandler Carruth 1c032e0dc0 Update the CMake build for r146959's new files.
llvm-svn: 146967
2011-12-20 08:42:15 +00:00
David Blaikie 68e081d606 Unweaken vtables as per http://llvm.org/docs/CodingStandards.html#ll_virtual_anch
llvm-svn: 146959
2011-12-20 02:48:34 +00:00
Douglas Gregor dc9166c8e1 Keep track of all declarations of an Objective-C class (both forward
declarations and definitions) as ObjCInterfaceDecls within the same
redeclaration chain. This new representation matches what we do for
C/C++ variables/functions/classes/templates/etc., and makes it
possible to answer the query "where are all of the declarations of
this class?"

llvm-svn: 146679
2011-12-15 20:29:51 +00:00
Hans Wennborg 23926bd2d7 Support the 'a' length modifier in scanf format strings as a C90
extension.

This fixes gcc.dg/format/c90-scanf-3.c and ext-4.c (test for excess
errors).

llvm-svn: 146649
2011-12-15 10:25:47 +00:00
Hans Wennborg b1a5e09f6f Check that arguments to a scanf call match the format specifier,
and offer fixits when there is a mismatch.

llvm-svn: 146326
2011-12-10 13:20:11 +00:00
Hans Wennborg 0c35326302 Remove unnecessary braces from my previous commit.
llvm-svn: 146259
2011-12-09 15:57:33 +00:00
Hans Wennborg a5b1aa99c7 Make printf warnings refer to wint_t and wchar_t by name
in addition to underlying type.

llvm-svn: 146254
2011-12-09 12:22:12 +00:00
Hans Wennborg a8b042d31a Move definition of ConversionSpecifier::toString() to FormatString.cpp
It's declared in FormatString.h, so it shouldn't be defined in
PrintfFormatString.cpp.

llvm-svn: 146253
2011-12-09 11:11:07 +00:00
Hans Wennborg 2027de3be9 fix format specifier fixit for printf("%ld", "foo");
It should reset the length modifier (unless it's a wchar_t string).

llvm-svn: 146252
2011-12-09 10:51:29 +00:00
DeLesley Hutchins f7faa6a69b This patch extends thread safety analysis with support for the scoped_lockable attribute.
llvm-svn: 146174
2011-12-08 20:23:06 +00:00
Hans Wennborg 772e9270f6 Make printf warnings refer to intmax_t et al. by name
in addition to underlying type.

For example, the warning for printf("%zu", 42.0);
changes from "conversion specifies type 'unsigned long'" to "conversion
specifies type 'size_t' (aka 'unsigned long')"

(This is a second attempt after r145697, which got reverted.)

llvm-svn: 146032
2011-12-07 10:33:11 +00:00
Anna Zaks 02a1fc1da6 [analyzer] Rely on LLVM Dominators in Clang dominator computation.
(Previously, Clang used it's implementation of dominators.)

The patch is contributed by Guoping Long!

llvm-svn: 145858
2011-12-05 21:33:11 +00:00
Nick Lewycky 45ccba64ab Revert r145697 and dependent patch r145702. It added a dependency from
lib/Analysis to lib/Sema which is cyclical.

llvm-svn: 145724
2011-12-02 23:21:43 +00:00
Hans Wennborg 4d99c7a6dd Make r145697 actually work.
Use the canonical type of the typedef to compare with the underlying type.

llvm-svn: 145702
2011-12-02 20:32:01 +00:00
Hans Wennborg 70f7213d2c Make conversion specifier warning refer to typedef if possible.
For example, the warning for printf("%zu", 42.0);
changes from "conversion specifies type 'unsigned long'" to "conversion
specifies type 'size_t' (aka 'unsigned long')"

llvm-svn: 145697
2011-12-02 19:22:15 +00:00
Douglas Gregor 6c8f07ff46 Teach the CFG builder how to properly destroy temporaries who
lifetimes have been extended via reference binding. The type of the
reference and the type of the temporary are not necessarily the same,
which could cause a crash. Fixes <rdar://problem/10398199>.

llvm-svn: 144646
2011-11-15 15:29:30 +00:00
Ted Kremenek b39fcfaa19 [analyzer] teach AnalysisDeclContext::getSelfDecl() about blocks that capture the 'self' variable of the enclosing ObjC method decl. Fixes <rdar://problem/10380300>.
llvm-svn: 144556
2011-11-14 19:36:08 +00:00
John McCall 29928fc563 We don't add ExprWithCleanups to the CFG, and getSVal looks
through it, so we should look through it for the live-values
analysis as well.

llvm-svn: 144190
2011-11-09 17:10:36 +00:00
John McCall fe96e0b6be Change the AST representation of operations on Objective-C
property references to use a new PseudoObjectExpr
expression which pairs a syntactic form of the expression
with a set of semantic expressions implementing it.
This should significantly reduce the complexity required
elsewhere in the compiler to deal with these kinds of
expressions (e.g. IR generation's special l-value kind,
the static analyzer's Message abstraction), at the lower
cost of specifically dealing with the odd AST structure
of these expressions.  It should also greatly simplify
efforts to implement similar language features in the
future, most notably Managed C++'s properties and indexed
properties.

Most of the effort here is in dealing with the various
clients of the AST.  I've gone ahead and simplified the
ObjC rewriter's use of properties;  other clients, like
IR-gen and the static analyzer, have all the old
complexity *and* all the new complexity, at least
temporarily.  Many thanks to Ted for writing and advising
on the necessary changes to the static analyzer.

I've xfailed a small diagnostics regression in the static
analyzer at Ted's request.

llvm-svn: 143867
2011-11-06 09:01:30 +00:00
Ted Kremenek 977e30d1c4 Tweak LookThroughStmt() in LiveVariables to properly look through alternativing ParenExprs and OpaqueValueExprs. Thanks to Anna and Argiris for iterating on this function. My original patch embarssingly didn't even pass the Clang tests.
llvm-svn: 143797
2011-11-05 07:34:28 +00:00
Argyrios Kyrtzidis c843fd2afb LookThroughStmt GM release.
llvm-svn: 143796
2011-11-05 07:09:40 +00:00
Argyrios Kyrtzidis e2cbe86dc4 LookThroughStmt v4.6.3
llvm-svn: 143795
2011-11-05 07:06:54 +00:00
Argyrios Kyrtzidis 6b4fa1b4d6 Simplify LookThroughStmt in LiveVariables.cpp
llvm-svn: 143794
2011-11-05 07:03:54 +00:00
Anna Zaks 04994959a3 Another correction to the LiveVariables commit (r143767, r143780).
Make test/Analysis/misc-ps.c test pass.

llvm-svn: 143790
2011-11-05 05:20:59 +00:00
Argyrios Kyrtzidis 3c89fdae03 Fix infinite loop in LiveVariables due to a misplaced 'break' (it would break out of
switch statement, not the while loop).

llvm-svn: 143780
2011-11-05 04:03:43 +00:00
Ted Kremenek 5717049d8e Teach LiveVariables to look through OpaqueValueExprs for extending Stmt liveness.
llvm-svn: 143767
2011-11-05 00:26:53 +00:00
Ted Kremenek 04268232df Per discussion with John McCall, don't add OpaqueValueExprs to the CFG.
llvm-svn: 143766
2011-11-05 00:10:15 +00:00
Richard Smith 7b553f1b19 Rename Expr::Evaluate to Expr::EvaluateAsRValue to make it clear that it will
implicitly perform an lvalue-to-rvalue conversion if used on an lvalue
expression. Also improve the documentation of Expr::Evaluate* to indicate which
of them will accept expressions with side-effects.

llvm-svn: 143263
2011-10-29 00:50:52 +00:00
Hans Wennborg 27541dbe1a Teach format string analysis that "%zu" means size_t.
The code had it backwards, thinking size_t was signed, and using that for "%zd".

Also let the analysis get the types for (u)intmax_t while we are at it.

llvm-svn: 143099
2011-10-27 08:29:09 +00:00
Ted Kremenek 74e82bd190 Tweak printf format string parsing to accept 'hh' conversion specifier to accept any char, not just signed char. Fixes <rdar://problem/10303638>.
llvm-svn: 142908
2011-10-25 04:20:41 +00:00
Ted Kremenek 0062e74961 Add source-level dominators analysis. Patch by Guoping Long!
llvm-svn: 142885
2011-10-25 00:25:24 +00:00
Chandler Carruth 6f2e6522d9 Actually rename the file AnalysisContext.cpp -> AnalysisDeclContext.cpp
to match the CMakeLists.txt change in r142782; this should fix the CMake
build.

llvm-svn: 142784
2011-10-24 01:47:37 +00:00
Ted Kremenek 81ce1c8a99 Rename AnalysisContext to AnalysisDeclContext. Not only is this name more accurate, but it frees up the name AnalysisContext for other uses.
llvm-svn: 142782
2011-10-24 01:32:45 +00:00
Ted Kremenek 142adc492b [analyzer] Remove LocationContext creation methods from AnalysisManager, and change clients to use AnalysisContext instead.
WIP to remove/reduce ExprEngine's usage of AnalysisManager.

llvm-svn: 142739
2011-10-23 02:31:52 +00:00
Ted Kremenek 4b4c51c323 Refactor ThreadSafety to use PostOrderCFGView instead of its own copy (of TopologicallySortedCFG).
llvm-svn: 142714
2011-10-22 02:14:27 +00:00
Ted Kremenek 5abde7cd5e Pull TopologicallySortedCFG out of LiveVariables into its own analysis: PostOrderCFGView.
llvm-svn: 142713
2011-10-22 02:14:23 +00:00
DeLesley Hutchins f893e8ab87 Added support for thread safety attributes on destructors.
llvm-svn: 142685
2011-10-21 20:51:27 +00:00
DeLesley Hutchins c20905110a Thread safety analysis refactoring: invalid lock expressions.
llvm-svn: 142666
2011-10-21 18:10:14 +00:00
DeLesley Hutchins db917bdea2 Thread safety analysis: add support for attributes on constructors.
llvm-svn: 142665
2011-10-21 18:06:53 +00:00
DeLesley Hutchins 3d312b175a Refactoring and code cleanup.
llvm-svn: 142654
2011-10-21 16:14:33 +00:00
John McCall 59207978e6 More metaprogramming with builtin types.
llvm-svn: 142433
2011-10-18 22:28:37 +00:00
Hans Wennborg f99d04f841 Suggest %zu for size_t args to printf.
For PR11152. Make PrintSpecifier::fixType() suggest "%zu" for size_t, etc.
rather than looking at the underlying type and suggesting "%llu" or other
platform-specific length modifiers. Applies to C99 and C++11.

llvm-svn: 142342
2011-10-18 08:10:06 +00:00
DeLesley Hutchins 30abeb1680 Substitute for arguments in method calls -- functionality
llvm-svn: 142267
2011-10-17 21:38:02 +00:00
DeLesley Hutchins a088f67bee Substitute for arguments in method calls -- refactoring
llvm-svn: 142260
2011-10-17 21:33:35 +00:00
John McCall 8a6b59ad97 Add a new placeholder type to represent "unbridged"
casts in ARC.

No semantic analysis yet.

llvm-svn: 142208
2011-10-17 18:09:15 +00:00
Anton Korobeynikov f0c267e6e0 Provide half floating point support as a storage only type.
Lack of half FP was a regression compared to llvm-gcc.

llvm-svn: 142016
2011-10-14 23:23:15 +00:00
Richard Smith faa32a9b83 Refactor static analyzer to use simpler interface to constant expression evaluation.
llvm-svn: 141983
2011-10-14 20:22:00 +00:00
Ted Kremenek 596fa16dd3 Tweak -Wuninitialized's handling of 'int x = x' to report that as the root cause of an uninitialized variable IFF there are other uses of that uninitialized variable. Fixes <rdar://problem/9259237>.
llvm-svn: 141881
2011-10-13 18:50:06 +00:00
Ted Kremenek dccc2b2277 Remove AnalysisContext::getLiveVariables(), and introduce a templatized mechanism to lazily create analyses that are attached to AnalysisContext objects.
llvm-svn: 141425
2011-10-07 22:21:02 +00:00
Anna Zaks 8de8cfdd21 ProgramPoint cleanup after the previous commit r141408 (remove the copy constructor, mark withTag const).
Move getProgramPoint() utility from CoreEngine.cpp into ProgramPoint.

llvm-svn: 141414
2011-10-07 21:01:38 +00:00
Ted Kremenek f8fd4d4962 Fix infinite loop in -Wuninitialized reported in PR 11069.
llvm-svn: 141345
2011-10-07 00:42:48 +00:00
Ted Kremenek b7531d622d [static analyzer] Fix crash in LiveVariables and Environment::getSVal() when analyzing C++ pointer-to-member calls. Fixes <rdar://problem/10243398>.
llvm-svn: 141312
2011-10-06 20:53:28 +00:00
Ted Kremenek c8f008ac31 Fix another major performance regression in LiveVariables by not canonicalizing the underlying ImmutableSets on every analyzed statement (just at merges). Fixes <rdar://problem/10087538>.
llvm-svn: 140958
2011-10-02 01:45:37 +00:00
Ted Kremenek 2a14c695eb Fix LiveVariables analysis bug with MaterializeTemporaryExpr and fix handling in ExprEngine. Fixes <rdar://problem/10201666>.
llvm-svn: 140956
2011-10-02 00:54:48 +00:00
John McCall 525f05597f Tweak the interface for analyzing the CF conventions for a name
to take a FunctionDecl* instead of an llvm::StringRef.  Eventually
we might push more logic in there, like using slightly different
conventions for C++ methods.

Also, fix a bug where 'copy' and 'create' were being caught in 
non-camel-cased strings.  We want copyFoo and CopyFoo and XCopy
but not Xcopy or xcopy.

llvm-svn: 140911
2011-10-01 00:48:56 +00:00
David Blaikie aa347f9392 Removing a bunch of dead returns/breaks after llvm_unreachables.
llvm-svn: 140407
2011-09-23 20:26:49 +00:00
David Blaikie 83d382b1ca Switch assert(0/false) llvm_unreachable.
llvm-svn: 140367
2011-09-23 05:06:16 +00:00
DeLesley Hutchins 08e094aee3 Test commit
llvm-svn: 140149
2011-09-20 17:25:59 +00:00
Anna Zaks c2b3c1f14b [analyzer] Constify a method.
llvm-svn: 140091
2011-09-19 23:17:48 +00:00
Ted Kremenek 459597a6eb Fix massive LiveVariables regression (due to LiveVariables rewrite) by addressing two performance problems:
- Speed of "merge()", which merged data flow facts.  This was doing a set canonicalization on every insertion, which was super slow.
  To fix this, we use ImmutableSetRef.

- Visit CFGBlocks in reverse postorder.  This is a huge speedup, as on some test cases the algorithm would take many iterations
  to converge.

This contains a bunch of copy-paste from UninitializedValues.cpp and ThreadSafety.cpp.  The idea
was to get something working first, and then refactor the common logic for all three files into
a separate analysis/library entry point.

llvm-svn: 139968
2011-09-16 23:01:39 +00:00
Caitlin Sadowski 086fb95da5 Thread safety: Adding FIXMEs and a couple cleanups
llvm-svn: 139894
2011-09-16 00:35:54 +00:00
Caitlin Sadowski 6525fb25cb Thread safety: completeing the implementation of shared/exclusive locks required attributes
llvm-svn: 139804
2011-09-15 17:43:08 +00:00
Caitlin Sadowski af9b7c5f8b Thread safety: refactoring various out of scope warnings to use the same inteface. This eliminates a lot of unnecessary duplicated code.
llvm-svn: 139801
2011-09-15 17:25:19 +00:00
Caitlin Sadowski 5b34a2fd6e Thread safety: adding additional documentation to the main thread safety interface, and making the destructor for the thread safety handler pure virtual
llvm-svn: 139722
2011-09-14 20:05:09 +00:00
Caitlin Sadowski 787c2a1b09 Thread safety: adding test cases for unparseable lock expressions and expanding the handling of these expressions
llvm-svn: 139720
2011-09-14 20:00:24 +00:00
Chandler Carruth 75d78232fd Add a bit to the CFGBlock to track when it contains a no-return
CFGElement. This will allow greatly simplifying the logic in
-Wreturn-type.

llvm-svn: 139593
2011-09-13 09:53:55 +00:00
Chandler Carruth a70991bb3f Consolidate the logic for building a no-return CFG block into a single
location with a single comment rather than scattering it in three
places.

llvm-svn: 139592
2011-09-13 09:13:49 +00:00
Chandler Carruth ad74725ab5 Enhance the CFG construction to detect no-return destructors for
temporary objects and local variables. When detected, these split the
block, marking the new one as having only the exit block as a successor.
This prevents a large number of false positives in warnings sensitive to
no-return constructs such as -Wreturn-type, and fixes the remainder of
PR10063 along with several variations of this bug that had not been
reported. The test cases are extended across the board to cover these
patterns.

This also checks in a stress test for these types of CFGs. The stress
test declares some 32k variables, a mixture of no-return and normal
destructors. Previously, this resulted in roughly 2500 CFG blocks, but
didn't model any of the no-return destructors. With this patch, it
results in over 33k blocks, many of them now unreachable.

The nice thing about how the analyzer is set up? This causes *no*
regression in performance of building the CFG. It actually in some cases
makes it faster, as best I can benchmark. The analysis for -Wreturn-type
(and any other that cares about no-return code paths) is technically
slower now as it has to look at many more candidate blocks, but it
computes the correct answer. I have more test cases to follow, I think
they all work now. Also I have further work that should dramatically
simplify analyses in the presence of no-return.

llvm-svn: 139586
2011-09-13 06:09:01 +00:00
Caitlin Sadowski eecd273951 Thread safety: small formatting change
llvm-svn: 139548
2011-09-12 22:28:41 +00:00
Benjamin Kramer 8a8051f2cd Silence "end of non-void function" warnings with llvm_unreachable and add an assert.
llvm-svn: 139474
2011-09-10 21:52:04 +00:00
Chandler Carruth a626d645d5 Extend the Stmt AST to make it easier to look through label, default,
and case statements. Use this to make the logic in the CFG builder more
robust at finding the actual statements within a compound statement,
even when there are many layers of labels obscuring it.

Also extend the test cases for a large chunk of PR10063. Still more work
to do here though.

llvm-svn: 139437
2011-09-10 00:02:34 +00:00
Caitlin Sadowski 82e2de512e Thread safety: removing unnecessary import and reordering import list
llvm-svn: 139426
2011-09-09 23:00:59 +00:00
Caitlin Sadowski 0bef2279fb Thread safety: removing unnecessary import
llvm-svn: 139425
2011-09-09 22:49:12 +00:00
Caitlin Sadowski ff2f3f8105 Thread safety: This patch deals with previously unhandled cases when building lock expressions. We now resolve this expressions, avoid crashing when encountering cast expressions, and have a diagnostic for unresolved lock expressions
llvm-svn: 139370
2011-09-09 16:21:55 +00:00
Caitlin Sadowski 33208340bd Thread Safety: Moving the analysis to a new file
llvm-svn: 139369
2011-09-09 16:11:56 +00:00
Ted Kremenek aed4677a1c -Wuninitialized: fix insidious bug resulting from interplay of blocks and dead code. Fixes <rdar://problem/10060250>.
llvm-svn: 139027
2011-09-02 19:39:26 +00:00
Nico Weber 1fb82667dd Warn on missing [super finalize] calls.
This matches gcc's logic. Second half of PR10661.

llvm-svn: 138730
2011-08-28 22:35:17 +00:00
Ted Kremenek 1b7f49c2d6 Teach -Wunreachable-code about dead code caused by macro expansions. This should suppress false positives resulting from 'assert' and friends.
llvm-svn: 138576
2011-08-25 19:28:55 +00:00
Ted Kremenek bd91371381 Start reworking -Wunreachable-code. The original analysis had serious flaws with how it
handled SCC's of dead code, or simply having false negatives by overly suppressing warnings.

WIP.

llvm-svn: 138410
2011-08-23 23:05:11 +00:00
Ted Kremenek 6b9964d237 CFG: record set of C++ 'try' dispatch blocks, which could be of interest to various analyses (e.g., reachability).
llvm-svn: 138409
2011-08-23 23:05:07 +00:00
Ted Kremenek adfb445466 Constify the result of CFGStmt::getStmt().
llvm-svn: 138408
2011-08-23 23:05:04 +00:00
Ted Kremenek ee9848e20d Fix regression in -Wuninitialized involving VLAs. It turns out that we were modeling sizeof(VLAs)
incorrectly in the CFG, and also the static analyzer.  This patch regresses the analyzer a bit, but
that needs to be followed up with a better solution.

Fixes <rdar://problem/10008112>.

llvm-svn: 138372
2011-08-23 20:30:50 +00:00
Ted Kremenek 417d566775 Remove dead code.
llvm-svn: 138183
2011-08-20 01:15:28 +00:00
Chad Rosier 6fdf38bfbd Fix else style. No functionality change intended.
llvm-svn: 137896
2011-08-17 23:08:45 +00:00
Ted Kremenek c14efa7122 Fix a handful of dead stores found by Clang's static analyzer. There's a bunch of others I haven't touched.
llvm-svn: 137867
2011-08-17 21:04:19 +00:00
Ted Kremenek 5ef32dbf2a Cleanup various declarations of 'Stmt*' to be 'Stmt *', etc. in libAnalyzer and libStaticAnalyzer[*]. It was highly inconsistent, and very ugly to look at.
llvm-svn: 137537
2011-08-12 23:37:29 +00:00
Ted Kremenek e8f7316fee [analyzer] change "tag" in ProgramPoint from "void*" to a ProgramPointTag*.
Having a notion of an actual ProgramPointTag will aid in introspection of the analyzer's behavior.
For example, the GraphViz output of the analyzer will pretty-print the tags in a useful manner.

llvm-svn: 137529
2011-08-12 23:04:46 +00:00
Ted Kremenek 50aa2d480c Revert "Fix crash in CFGBuilder involving implicit destructor calls and gotos jumping after an object was declared. Fixes PR 10620."
llvm-svn: 137459
2011-08-12 14:41:23 +00:00
Ted Kremenek 06b8cd7324 Fix crash in CFGBuilder involving implicit destructor calls and gotos jumping after an object was declared. Fixes PR 10620.
llvm-svn: 137426
2011-08-12 04:09:00 +00:00
Ted Kremenek a0cdf58b0c Fix another -Wuninitialized assertion failure (this one involving bit casts) resulting from the recent -Wuninitialized changes.
llvm-svn: 137068
2011-08-08 21:43:08 +00:00
Ted Kremenek 84a1ca5280 [analyzer] Simplify logic for ExprEngine::VisitUnaryExprOrTypeTraitExpr to avoid recursion to subexpression.
This exposed bugs in the live variables analysis, and a latent analyzer bug in the SymbolReaper.

llvm-svn: 137006
2011-08-06 00:30:00 +00:00
Ted Kremenek 75842e4946 Fix assertion failure in -Wuninitialized involving no-op casts. Fixes PR 10577.
llvm-svn: 136939
2011-08-04 22:40:57 +00:00
Benjamin Kramer 3c05b7c161 Make helper functions static.
llvm-svn: 136679
2011-08-02 04:50:49 +00:00
Ted Kremenek e9fda1e48a [analyzer] Overhaul how the static analyzer expects CFGs by forcing CFGs to be linearized only when used by the static analyzer. This required a rewrite of LiveVariables, and exposed a ton of subtle bugs.
The motivation of this large change is to drastically simplify the logic in ExprEngine going forward.

Some fallout is that the output of some BugReporterVisitors is not as accurate as before; those will
need to be fixed over time.  There is also some possible performance regression as RemoveDeadBindings
will be called frequently; this can also be improved over time.

llvm-svn: 136419
2011-07-28 23:07:59 +00:00
Chris Lattner 0e62c1cc0b remove unneeded llvm:: namespace qualifiers on some core types now that LLVM.h imports
them into the clang namespace.

llvm-svn: 135852
2011-07-23 10:55:15 +00:00
Chandler Carruth 4dd6c043ae Move duplicate uninitialized warning suppression into the
AnalysisBasedWarnings Sema layer and out of the Analysis library itself.
This returns the uninitialized values analysis to a more pure form,
allowing its original logic to correctly detect some categories of
definitely uninitialized values. Fixes PR10358 (again).

Thanks to Ted for reviewing and updating this patch after his rewrite of
several portions of this analysis.

llvm-svn: 135748
2011-07-22 05:27:52 +00:00
Ted Kremenek 189ecec4db Simplify passing of CFGBuildOptions around for AnalysisContext. No functionality change.
llvm-svn: 135666
2011-07-21 05:22:47 +00:00
Ted Kremenek 81383c20e4 Fix -Wuninitialized regression involving functions invalidating parameters passed by reference.
llvm-svn: 135610
2011-07-20 19:49:47 +00:00
Ted Kremenek 65b3e0649c Fix false negative in -Wuninitialized involving a () wrapping an lvalue-to-rvalue conversion in a DeclStmt.
llvm-svn: 135525
2011-07-19 21:41:51 +00:00
Ted Kremenek 5d855bf7f2 Fix assertion failure in UninitializedValues.cpp where an lvalue to rvalue conversion is wrapped in a parenthesis.
llvm-svn: 135519
2011-07-19 20:33:49 +00:00
Ted Kremenek 9e100ea1a8 Reduce -Wuninitialized time by 22% (on sqlite) by removing the recursive AST crawl.
This is accomplished by forcing the needed expressions for -Wuninitialized to always be CFGElements in the CFG.
This allows us to remove a fair amount of the code for -Wuninitialized.

Some fallout:
- AnalysisBasedWarnings.cpp now specifically toggles the CFGBuilder to create a CFG that is suitable for -Wuninitialized.  This
is a layering violation, since the logic for -Wuninitialized is in libAnalysis.  This can be fixed with the proper refactoring.
- Some of the source locations for -Wunreachable-code warnings have shifted.  While not ideal, this is okay because that analysis
already needs some serious reworking.

llvm-svn: 135480
2011-07-19 14:18:48 +00:00
Ted Kremenek 8b46c00b5f Add hooks into the CFG builder to force that specific expressions are always CFGElements.
llvm-svn: 135479
2011-07-19 14:18:43 +00:00
Chandler Carruth 7cf5a37605 Revert r135217, which wasn't the correct fix for PR10358. With this
patch, we actually move the state-machine for the value set backwards
one step. This can pretty easily lead to infinite loops where we
continually try to propagate a bit, succeed for one iteration, but then
back up because we find an uninitialized use.

A reduced test case from PR10379 is included.

llvm-svn: 135359
2011-07-16 22:27:02 +00:00
Ted Kremenek 6dcbbe8547 [analyzer] Per discussions with the Cocoa team, extend CF naming conventions to extend to camel case functions instead of just title case functions. Fixes <rdar://problem/9732321>.
llvm-svn: 135350
2011-07-16 19:50:36 +00:00
Ted Kremenek c85964ed90 [analyzer] Place checking for Core Foundation "Create" rule into a proper API. No functionality change.
llvm-svn: 135349
2011-07-16 19:50:32 +00:00
Ted Kremenek f0b28d7fe5 Fix false negative reported in PR 10358 by using 'Unknown' in -Wuninitialized to avoid cascading warnings. Patch by Kaelyn Uhrain.
llvm-svn: 135217
2011-07-14 23:43:06 +00:00
Ted Kremenek d0c2afd2c3 Revert r135147 and r135075. The consensus was that this wasn't the right thing to do.
llvm-svn: 135152
2011-07-14 17:05:32 +00:00
Ted Kremenek 2df6485d51 Add extra sanity checking in FormatString::matchesType() that we are comparing integers to integers. This happens not to be an issue now, but the extra check helps future proof in case of future refactorings.
llvm-svn: 135147
2011-07-14 15:43:21 +00:00
Ted Kremenek ba84cf53bc Reapply r135075, but modify format-strings.c and format-strings-fixit.c test cases to be more portable with an explicit target triple.
llvm-svn: 135134
2011-07-14 06:49:52 +00:00
NAKAMURA Takumi 91d831bc2d Revert r135075, "format string checking: long and int have the same widths on 32-bit, so we shouldn't warn about using"
It fails on freebsd, mingw and msvc10.

llvm-svn: 135129
2011-07-14 05:16:18 +00:00
Ted Kremenek 60654d697a format string checking: long and int have the same widths on 32-bit, so we shouldn't warn about using
an "int" format specifier with a "long" type in 32-bit.

llvm-svn: 135075
2011-07-13 20:20:58 +00:00
Ted Kremenek cc47e0fad1 Re-relax conversion specifier checking for printf format strings and conversion specifiers. My recent change was a mistake.
llvm-svn: 135048
2011-07-13 17:35:14 +00:00
Ted Kremenek 1d3fb8af68 Fix inversion in argument type checking for format strings with conversion specifiers for character types.
llvm-svn: 135046
2011-07-13 17:25:47 +00:00
Chandler Carruth a532863131 Make the worklist in the uninitialized values checker actually a queue.
Previously, despite the names 'enqueue' and 'dequeue', it behaved as
a stack and visited blocks in a LIFO fashion. This interacts badly with
extremely broad CFGs *inside* of a loop (such as a large switch inside
a state machine) where every block updates a different variable.

When encountering such a CFG, the checker visited blocks in essentially
a "depth first" order due to the stack-like behavior of the work list.
Combined with each block updating a different variable, the saturation
logic of the checker caused it to re-traverse blocks [1,N-1] of the
broad CFG inside the loop after traversing block N. These re-traversals
were to propagate the variable values derived from block N. Assuming
approximately the same number of variables as inner blocks exist, the
end result is O(N^2) updates. By making this a queue, we also make the
traversal essentially "breadth-first" across each of the N inner blocks
of the loop. Then all of this state is propagated around to all N inner
blocks of the loop. The result is O(N) updates.

The truth is in the numbers:
Before, gcc.c:   96409 block visits  (max: 61546,   avg: 591)
After,  gcc.c:   69958 block visits  (max: 33090,   avg: 429)
Before, PR10183: 2540494 block vists (max: 2536495, avg: 37360)
After,  PR10183: 137803 block visits (max: 134406,  avg: 2026)

The nearly 20x reduction in work for PR10183 corresponds to a roughly
100x speedup in compile time.

I've tested it on all the code I can get my hands on, and I've seen no
slowdowns due to this change. Where I've collected stats, the ammount of
work done is on average less. I'll also commit shortly some synthetic
test cases useful in analyzing the performance of CFG-based warnings.

Submitting this based on Doug's feedback that post-commit review should
be good. Ted, please review! Hopefully this helps compile times until
then.

llvm-svn: 134697
2011-07-08 11:19:06 +00:00
Chandler Carruth b4836ea7a8 Build up statistics about the work done for analysis based warnings.
Special detail is added for uninitialized variable analysis as this has
serious performance problems than need to be tracked.

Computing some of this data is expensive, for example walking the CFG to
determine its size. To avoid doing that unless the stats data is going
to be used, we thread a bit into the Sema object to track whether
detailed stats should be collected or not. This bit is used to avoid
computations whereever the computations are likely to be more expensive
than checking the state of the flag. Thus, counters are in some cases
unconditionally updated, but the more expensive (and less frequent)
aggregation steps are skipped.

With this patch, we're able to see that for 'gcc.c':
*** Analysis Based Warnings Stats:
232 functions analyzed (0 w/o CFGs).
  7151 CFG blocks built.
  30 average CFG blocks per function.
  1167 max CFG blocks per function.
163 functions analyzed for uninitialiazed variables
  640 variables analyzed.
  3 average variables per function.
  94 max variables per function.
  96409 block visits.
  591 average block visits per function.
  61546 max block visits per function.

And for the reduced testcase in PR10183:
*** Analysis Based Warnings Stats:
98 functions analyzed (0 w/o CFGs).
  8526 CFG blocks built.
  87 average CFG blocks per function.
  7277 max CFG blocks per function.
68 functions analyzed for uninitialiazed variables
  1359 variables analyzed.
  19 average variables per function.
  1196 max variables per function.
  2540494 block visits.
  37360 average block visits per function.
  2536495 max block visits per function.

That last number is the somewhat scary one that indicates the problem in
PR10183.

llvm-svn: 134494
2011-07-06 16:21:37 +00:00
Douglas Gregor 5c70b06feb Teach the static analyzer's interpretation of Cocoa conventions to
obey the objc_method_family attribute when provided. Fixes
<rdar://problem/9726279>.

llvm-svn: 134493
2011-07-06 16:00:34 +00:00
Fariborz Jahanian 76b9d4da16 Added a missing case label.
llvm-svn: 134454
2011-07-06 00:29:51 +00:00
Daniel Dunbar 421bb42c9f Revert r133024, "[format strings] correctly suggest correct type for '%@'
specifiers.  Fixes <rdar://problem/9607158>." because it causes false positives
on some code that uses CF toll free bridging.
 - I'll let Doug or Ted figure out the right fix here, possibly just to accept
   any pointer type.

llvm-svn: 134041
2011-06-28 23:33:55 +00:00
Douglas Gregor fe31481f68 Introduce a new AST node describing reference binding to temporaries.
MaterializeTemporaryExpr captures a reference binding to a temporary
value, making explicit that the temporary value (a prvalue) needs to
be materialized into memory so that its address can be used. The
intended AST invariant here is that a reference will always bind to a
glvalue, and MaterializeTemporaryExpr will be used to convert prvalues
into glvalues for that binding to happen. For example, given

  const int& r = 1.0;

The initializer of "r" will be a MaterializeTemporaryExpr whose
subexpression is an implicit conversion from the double literal "1.0"
to an integer value. 

IR generation benefits most from this new node, since it was
previously guessing (badly) when to materialize temporaries for the
purposes of reference binding. There are likely more refactoring and
cleanups we could perform there, but the introduction of
MaterializeTemporaryExpr fixes PR9565, a case where IR generation
would effectively bind a const reference directly to a bitfield in a
struct. Addresses <rdar://problem/9552231>.

llvm-svn: 133521
2011-06-21 17:03:29 +00:00
Francois Pichet ea22bab7a5 Finish 2 sentences.
llvm-svn: 133214
2011-06-16 23:19:36 +00:00
John McCall 31168b077c Automatic Reference Counting.
Language-design credit goes to a lot of people, but I particularly want
to single out Blaine Garst and Patrick Beard for their contributions.

Compiler implementation credit goes to Argyrios, Doug, Fariborz, and myself,
in no particular order.

llvm-svn: 133103
2011-06-15 23:02:42 +00:00
Ted Kremenek 192ed0b7ee [format strings] correctly suggest correct type for '%@' specifiers. Fixes <rdar://problem/9607158>.
llvm-svn: 133024
2011-06-14 22:56:51 +00:00
Douglas Gregor 33823727c8 Implement Objective-C Related Result Type semantics.
Related result types apply Cocoa conventions to the type of message
sends and property accesses to Objective-C methods that are known to
always return objects whose type is the same as the type of the
receiving class (or a subclass thereof), such as +alloc and
-init. This tightens up static type safety for Objective-C, so that we
now diagnose mistakes like this:

t.m:4:10: warning: incompatible pointer types initializing 'NSSet *'
with an
      expression of type 'NSArray *' [-Wincompatible-pointer-types]
  NSSet *array = [[NSArray alloc] init];
         ^       ~~~~~~~~~~~~~~~~~~~~~~
/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:72:1:
note: 
      instance method 'init' is assumed to return an instance of its
      receiver
      type ('NSArray *')
- (id)init;
^

It also means that we get decent type inference when writing code in
Objective-C++0x:

  auto array = [[NSMutableArray alloc] initWithObjects:@"one",  @"two",nil];
  //    ^ now infers NSMutableArray* rather than id

llvm-svn: 132868
2011-06-11 01:09:30 +00:00
Jordy Rose 1734737d9f [analyzer] PR8962 again. Ban ParenExprs (and friends) from block-level expressions (by calling IgnoreParens before adding expressions to blocks). Undo 132769 (LiveVariables' local IgnoreParens), since it's no longer necessary.
Also, have Environment stop looking through NoOp casts; it didn't match the behavior of LiveVariables. And once that's gone, the whole cast block of that switch is unnecessary.

llvm-svn: 132840
2011-06-10 08:49:37 +00:00
Jordy Rose 891d613289 [analyzer] Ignore parentheses around block-level expressions when computing liveness. Fixes the other half of PR8962.
llvm-svn: 132769
2011-06-09 05:44:04 +00:00
Argyrios Kyrtzidis b3483b3d91 Utilize PackedVector, introduced with llvm commit r132325.
llvm-svn: 132326
2011-05-31 03:56:09 +00:00
Ted Kremenek 3a60114085 Add explicit CFG support for ignoring static_asserts.
llvm-svn: 132001
2011-05-24 20:41:31 +00:00
Peter Collingbourne e92006860d Refactoring of constant expression evaluator
This introduces a generic base class for the expression evaluator
classes, which handles a few common expression types which were
previously handled separately in each class.  Also, the expression
evaluator now uses ConstStmtVisitor.

llvm-svn: 131281
2011-05-13 03:29:01 +00:00
John McCall c67067f43e Teach CFG building how to deal with CXXMemberCallExprs and BoundMemberTy,
then teach -Wreturn-type to handle the same.  Net effect:  we now correctly
handle noreturn attributes on member calls in the CFG.

llvm-svn: 131178
2011-05-11 07:19:11 +00:00
Ted Kremenek efdb7fe53b Fix crash in -Wuninitialized when using switch statments whose condition is a logical operation.
llvm-svn: 131158
2011-05-10 22:10:35 +00:00
Ted Kremenek 6878c36328 Elide __label__ declarations from the CFG. This resolves a crash in CFGRecStmtDeclVisitor (crash in static analyzer).
llvm-svn: 131141
2011-05-10 18:42:15 +00:00
Chandler Carruth 6e1f9babcd Silence more -Wnon-pod-memset given its current implementation. I may be
able to revert these based on a patch I'm working on, but no reason for
people to be spammed with warnings in the interim.

llvm-svn: 130394
2011-04-28 08:19:45 +00:00
Ted Kremenek f8ac5288a3 Remove unused method CFGBlock::hasBinaryBranchTerminator().
llvm-svn: 130336
2011-04-27 22:16:58 +00:00
Eli Friedman 7ec652a7a2 Don't print fixits for format specifiers in cases where the fixit does not actually fix the warning. PR8781.
I'm not sure what the preferred way to write a test for whether a fixit is emitted.

llvm-svn: 130335
2011-04-27 22:06:20 +00:00
Ted Kremenek 8dcc466886 When generating printf fixits, preserve the original formating for unsigned integers (e.g., 'x', 'o').
llvm-svn: 130164
2011-04-25 22:32:59 +00:00
Richard Smith 0c502d2a62 Fix PR9741. The implicit declarations created for range-based for loops weren't being added to the DeclContext (nor were they being marked as implicit). Also, the declarations were being emitted in the wrong order when building the CFG.
llvm-svn: 129700
2011-04-18 15:49:25 +00:00
Chris Lattner 57540c5be0 fix a bunch of comment typos found by codespell. Patch by
Luis Felipe Strano Moraes!

llvm-svn: 129559
2011-04-15 05:22:18 +00:00
Douglas Gregor 40965fa78a When we transform a C++ exception declaration (e.g., for template
instantiation), be sure to add the transformed declaration into the
current DeclContext. Also, remove the -Wuninitialized hack that works
around this bug. Fixes <rdar://problem/9200676>.

llvm-svn: 129544
2011-04-14 22:32:28 +00:00
Richard Smith 02e85f3bc5 Add support for C++0x's range-based for loops, as specified by the C++11 draft standard (N3291).
llvm-svn: 129541
2011-04-14 22:09:26 +00:00
Ted Kremenek 9eb0b7d2f1 Return the correct lastly populated block from CFGBuilder::VisitUnaryExprOrTypeTraitExpr().
llvm-svn: 129499
2011-04-14 01:50:50 +00:00
Chandler Carruth 0a7aa3b60b Teach -Wuninitialized about C++'s typeid expression, including both the
evaluated and unevaluated contexts. Add some testing of sizeof and
typeid.

Both of the typeid tests added here were triggering warnings previously.
Now the one false positive is suppressed without suppressing the warning
on actually buggy code.

llvm-svn: 129431
2011-04-13 08:18:42 +00:00
Ted Kremenek 97c393807b Teach -Wuninitialized to not warn about variables declared in C++ catch statements.
llvm-svn: 129102
2011-04-07 20:02:56 +00:00
Chandler Carruth 78c7e34485 Commit a bit of a hack to fully handle the situation where variables are
marked explicitly as uninitialized through direct self initialization:

  int x = x;

With r128894 we prevented warnings about this code, and this patch
teaches the analysis engine to continue analyzing subsequent uses of
'x'. This should wrap up PR9624.

There is still an open question of whether we should suppress the
maybe-uninitialized warnings resulting from variables initialized in
this fashion. The definitely-uninitialized uses should always be warned.

llvm-svn: 128932
2011-04-05 21:36:30 +00:00
Ted Kremenek 378819342e Fix PR 9626 (duplicated self-init warnings under -Wuninitialized) with numerous CFG and UninitializedValues analysis changes:
1) Change the CFG to include the DeclStmt for conditional variables, instead of using the condition itself as a faux DeclStmt.
2) Update ExprEngine (the static analyzer) to understand (1), so not to regress.
3) Update UninitializedValues.cpp to initialize all tracked variables to Uninitialized at the start of the function/method.
4) Only use the SelfReferenceChecker (SemaDecl.cpp) on global variables, leaving the dataflow analysis to handle other cases.

The combination of (1) and (3) allows the dataflow-based -Wuninitialized to find self-init problems when the initializer
contained control-flow.

llvm-svn: 128858
2011-04-04 23:29:12 +00:00
Ted Kremenek 352a7081a8 -Wuninitialized: don't warn about uninitialized variables in unreachable code.
llvm-svn: 128840
2011-04-04 20:30:58 +00:00
Nico Weber cc2b8717c5 Make -Wheader-hygiene not complain about USING_NAMESPACE_THROUGH_MACRO in a non-header file.
llvm-svn: 128780
2011-04-02 19:45:15 +00:00
Ted Kremenek 77361761fb -Wuninitialized should not warn about variables captured by blocks as byref.
Note this can potentially be enhanced to detect if the __block variable
is actually written by the block, or only when the block "escapes" or
is actually used, but that requires more analysis than it is probably worth
for this simple check.

llvm-svn: 128681
2011-03-31 22:32:41 +00:00
Ted Kremenek 03325c4be9 Add workaround for Sema issue found in <rdar://problem/9188004>, which leads to an assertion failure in the uninitialized variables analysis. The problem is that Sema isn't properly registering a variable in a DeclContext (which -Wuninitialized relies on), but
my expertise on the template instantiation logic isn't good enough to fix this problem for real.  This patch worksaround the
problem in -Wuninitialized, but we should fix it for real later.

llvm-svn: 128443
2011-03-29 01:40:00 +00:00
Benjamin Kramer 8aef596dec Make helpers static.
llvm-svn: 128339
2011-03-26 12:38:21 +00:00
Ted Kremenek dcc4c38970 Fix CFG-construction bug when run from AnalysisBasedWarnings::IssueWarnings() where block-level expressions that need
to be recorded in the Stmt*->CFGBlock* map were not always done so.  Fixes <rdar://problem/9171946>.

llvm-svn: 128170
2011-03-23 21:33:21 +00:00
Ted Kremenek ddc06d0bd0 Rename class 'CFGReachabilityAnalysis' to 'CFGReverseBlockReachabilityAnalysis'.
This rename serves two purposes:

- It reflects the actual functionality of this analysis.
- We will have more than one reachability analysis.

llvm-svn: 127930
2011-03-19 01:00:33 +00:00
Ted Kremenek c15a4e4b37 Extend -Wuninitialized to support vector types.
llvm-svn: 127794
2011-03-17 03:06:11 +00:00
Ted Kremenek 35c70f64db Teach CFGBuilder that the 'default' branch of a switch statement is dead if all enum values in a switch conditioned are handled.
llvm-svn: 127727
2011-03-16 04:32:01 +00:00
Ted Kremenek e3ae0a4c47 Appease GCC. I'm surprised Clang accepted this.
llvm-svn: 127672
2011-03-15 05:30:12 +00:00
Ted Kremenek 1a47f366b7 Split warnings from -Wuninitialized-experimental into "must-be-initialized" and "may-be-initialized" warnings, each controlled by different flags.
llvm-svn: 127669
2011-03-15 05:22:28 +00:00
Ted Kremenek c8c4e5f371 Split warnings from -Wuninitialized-experimental into "must-be-initialized" and "may-be-initialized" warnings, each controlled by different flags.
llvm-svn: 127666
2011-03-15 04:57:38 +00:00
Ted Kremenek 9b15c962a9 UninitializedValues: introduce ValueVector:reference class to forward to llvm::BitVector. No real functionality change, but this is a stepping stone to moving to tri-state logic.
llvm-svn: 127665
2011-03-15 04:57:32 +00:00
Ted Kremenek d3def3841f UninitializedValues: wrap BitVector references in a new class ValueVector. No functionality change. This defines the minimum interface that ValueVector needs to support when we no longer base it strictly on a direct interpretation of BitVector.
llvm-svn: 127664
2011-03-15 04:57:29 +00:00
Ted Kremenek a895fe999d Substitue term "BitVector" with "ValueVector" to prep for further revisions. No functionality change.
llvm-svn: 127663
2011-03-15 04:57:27 +00:00
Ted Kremenek a0a5ca14d0 Rename UninitializedValuesV2 to UninitializedValues.
llvm-svn: 127657
2011-03-15 03:17:07 +00:00
Ted Kremenek 792798549f Remove old UninitializedValues analysis.
llvm-svn: 127656
2011-03-15 03:17:01 +00:00
Sebastian Redl 31ad754c96 Instead of storing an ASTContext* in FunctionProtoTypes with computed noexcept specifiers, unique FunctionProtoTypes with a ContextualFoldingSet, as suggested by John McCall.
llvm-svn: 127568
2011-03-13 17:09:40 +00:00
Ted Kremenek 53e6538fa8 Fix CFG assertion failure reported in PR 9467. This was due to recent changes in optimizing CFGs for switch statements.
llvm-svn: 127563
2011-03-13 03:48:04 +00:00
Sebastian Redl fa453cfdc3 Propagate the new exception information to FunctionProtoType.
Change the interface to expose the new information and deal with the enormous fallout.
Introduce the new ExceptionSpecificationType value EST_DynamicNone to more easily deal with empty throw specifications.
Update the tests for noexcept and fix the various bugs uncovered, such as lack of tentative parsing support.

llvm-svn: 127537
2011-03-12 11:50:43 +00:00
Peter Collingbourne e190dee7a5 Add support for the OpenCL vec_step operator, by generalising and
extending the existing support for sizeof and alignof.  Original
patch by Guy Benyei.

llvm-svn: 127475
2011-03-11 19:24:49 +00:00
Ted Kremenek a099c595bf When doing reachability analysis for warnings issued under DiagRuntimeBehavior, don't construct a ParentMap or CFGStmtMap.
Instead, create a small set of Stmt* -> CFGBlock* mappings during CFG construction for only the statements we care about
relating to the diagnostics we want to check for reachability.

llvm-svn: 127396
2011-03-10 03:50:34 +00:00
Ted Kremenek 7c58d35240 Require AddStmtChoice::alwaysAdd() to take a CFGBuilder& and Stmt*. Prep for functionality changes.
llvm-svn: 127387
2011-03-10 01:14:11 +00:00
Ted Kremenek 2866bab5fa Remove unused 'AddStmtChoice' argument to CFGBuilder::appendStmt().
llvm-svn: 127386
2011-03-10 01:14:08 +00:00
Ted Kremenek f9d8290af1 Rework interaction between AnalysisContext and CFG::BuildOptions to keep a BuildOptions object around instead of keeping a copy of the flags.
Moreover, change AnalysisContext to use an OwningPtr for created analysis objects instead
of directly managing them.

Finally, add a 'forcedBlkExprs' entry to CFG::BuildOptions that will be used by the
CFGBuilder to force specific expressions to be block-level expressions.

llvm-svn: 127385
2011-03-10 01:14:05 +00:00
Ted Kremenek 897947434e Fix null dereference in CFGBlock::FilterEdge that was reported in PR 9412.
llvm-svn: 127176
2011-03-07 22:04:39 +00:00
Ted Kremenek be52871b1a Correctly handle nested switch statements in CFGBuilder when on switch statement has a condition that evaluates to a constant.
llvm-svn: 126977
2011-03-04 01:03:41 +00:00
Ted Kremenek 8cfe207861 Teach CFGImplicitDtor::getDestructorDecl() about arrays of objects with destructors.
llvm-svn: 126910
2011-03-03 01:21:32 +00:00
Ted Kremenek 1676a042e3 Teach CFGImplicitDtor::getDestructorDecl() about reference types.
llvm-svn: 126909
2011-03-03 01:01:03 +00:00
Matt Beaumont-Gay 86b900baca Let's go with John and Ted's preferred fix.
llvm-svn: 126907
2011-03-03 00:48:05 +00:00
Matt Beaumont-Gay 0532897f37 Keep GCC from complaining about falling off the end of the function.
llvm-svn: 126897
2011-03-02 23:25:06 +00:00
Ted Kremenek e06a55c6b9 Introduce CFGImplicitDtor::isNoReturn() to query whether a destructor actually returns. Use this for -Wreturn-type to prune false positives reported in PR 6884.
llvm-svn: 126875
2011-03-02 20:32:29 +00:00
John McCall b4526252db Move some of the logic about classifying Objective-C methods into
conventional categories into Basic and AST.  Update the self-init checker
to use this logic;  CFRefCountChecker is complicated enough that I didn't
want to touch it.

llvm-svn: 126817
2011-03-02 01:50:55 +00:00
Ted Kremenek eff9a7ff91 Teach CFGBuilder to prune trivially unreachable case statements.
llvm-svn: 126797
2011-03-01 23:12:55 +00:00
Ted Kremenek 96a7a59119 In preparation for fixing PR 6884, rework CFGElement to have getAs<> return pointers instead of fresh CFGElements.
- Also, consoldiate getDtorKind() and getKind() into one "kind".
- Add empty getDestructorDecl() method to CFGImplicitDtor.

llvm-svn: 126738
2011-03-01 03:15:10 +00:00
Anders Carlsson 6dc07d4e56 Get rid of the areExceptionsEnabled() getter from LangOptions.
llvm-svn: 126598
2011-02-28 00:33:03 +00:00
Ted Kremenek d813801384 Fix tiny error in CFG construction for BinaryConditionalOperators, making sure the branch always has two successors. Also teach Environment::getSVal() about OpaqueValueExprs.
This fixes a crash reported in PR9287, and also fixes a false positive involving the value of such ternary
expressions not properly getting propagated.

llvm-svn: 126362
2011-02-24 03:09:15 +00:00
Ted Kremenek 1a241d1619 Teach CFGBuilder about null pointer constants in conditionals, and how they can be used to prune branches. Fixes false null pointer dereference warning in PR 8183.
llvm-svn: 126305
2011-02-23 05:11:46 +00:00
Ted Kremenek 80861ca9b5 Migrate CFGReachabilityAnalysis out of the IdempotentOperationsChecker and into its own analysis file.
llvm-svn: 126289
2011-02-23 01:51:59 +00:00
Ted Kremenek cc7f1f8c2e Have IdempotentOperationsChecker pull its CFGStmtMap from AnalysisContext.
llvm-svn: 126288
2011-02-23 01:51:53 +00:00
Ted Kremenek 828f631af1 Fix a CFGBuilder bug exposed on convoluted control-flow in the Linux kernel.
llvm-svn: 126149
2011-02-21 22:11:26 +00:00
Anders Carlsson 08ce5ed1b1 Add a LangOptions::areExceptionsEnabled and start using it.
llvm-svn: 126062
2011-02-20 00:20:27 +00:00
John McCall 68cc3350a8 Fix a -Wuninitialized warning; it's actually a false positive,
but it's not reasonable for the diagnostic to figure that out.
Pointed out by Benjamin Kramer.

Also clarify the logic here.

llvm-svn: 126017
2011-02-19 03:13:26 +00:00
John McCall c07a0c7e48 Change the representation of GNU ?: expressions to use a different expression
class and to bind the shared value using OpaqueValueExpr.  This fixes an
unnoticed problem with deserialization of these expressions where the
deserialized form would lose the vital pointer-equality trait;  or rather,
it fixes it because this patch also does the right thing for deserializing
OVEs.

Change OVEs to not be a "temporary object" in the sense that copy elision is
permitted.

This new representation is not totally unawkward to work with, but I think
that's really part and parcel with the semantics we're modelling here.  In
particular, it's much easier to fix things like the copy elision bug and to
make the CFG look right.

I've tried to update the analyzer to deal with this in at least some          
obvious cases, and I think we get a much better CFG out, but the printing
of OpaqueValueExprs probably needs some work.

llvm-svn: 125744
2011-02-17 10:25:35 +00:00
Chris Lattner c8e630e4db Step #1/N of implementing support for __label__: split labels into
LabelDecl and LabelStmt.  There is a 1-1 correspondence between the
two, but this simplifies a bunch of code by itself.  This is because
labels are the only place where we previously had references to random
other statements, causing grief for AST serialization and other stuff.

This does cause one regression (attr(unused) doesn't silence unused
label warnings) which I'll address next.

This does fix some minor bugs:
1. "The only valid attribute " diagnostic was capitalized.
2. Various diagnostics printed as ''labelname'' instead of 'labelname'
3. This reduces duplication of label checking between functions and blocks.

Review appreciated, particularly for the cindex and template bits.

llvm-svn: 125733
2011-02-17 07:39:24 +00:00
Ted Kremenek c7bfdcd4f5 Fix memory leak in CFGBuilder resulting from tracking scope information using SmallVectors.
llvm-svn: 125550
2011-02-15 02:47:45 +00:00
John McCall 8322c3a197 Give some convenient idiomatic accessors to Stmt::child_range and
Stmt::const_child_range, then make a bunch of places use them instead
of the individual iterator accessors.

llvm-svn: 125450
2011-02-13 04:07:26 +00:00
Ted Kremenek 9865d7f0e6 Don't report dead stores on unreachable code paths. Fixes <rdar://problem/8405222>.
llvm-svn: 125415
2011-02-11 23:24:26 +00:00
NAKAMURA Takumi 98dd73d66c CMake: LLVM_NO_RTTI must be obsolete now!
llvm-svn: 125275
2011-02-10 09:15:32 +00:00
Ted Kremenek ba357296e7 Enhance -Wuninitialized to better reason about || and &&, tracking dual dataflow facts and properly merging them.
Fixes PR 9076.

llvm-svn: 124666
2011-02-01 17:43:18 +00:00
Ted Kremenek 1be4a59a11 Teach -Wuninitialized about indirect goto. Fixes PR 9071.
llvm-svn: 124394
2011-01-27 18:51:39 +00:00
NAKAMURA Takumi f9cbcc4cc2 Fix whitespace.
llvm-svn: 124364
2011-01-27 07:10:08 +00:00
NAKAMURA Takumi 7c2888689d 7bit-ize.
llvm-svn: 124363
2011-01-27 07:09:49 +00:00
Ted Kremenek 93a313869f Teach -Wuninitialized not to assert when analyzing
blocks that reference captured variables.

llvm-svn: 124348
2011-01-27 02:29:34 +00:00
Ted Kremenek 4058d87ad5 Teach -Wuninitialized about ObjC fast enumeration loops.
llvm-svn: 124347
2011-01-27 02:01:31 +00:00
Ted Kremenek 33ddd9692d Tweak -Wuninitialized-experimental to not emit
a warning for uses of an uninitialized variable
when the use is a void cast, e.g. (void) x.

llvm-svn: 124278
2011-01-26 04:49:43 +00:00
Ted Kremenek bcf848f70a Teach -Wuninitialized-experimental to also warn
about uninitialized variables captured by blocks.

llvm-svn: 124213
2011-01-25 19:13:48 +00:00
Ted Kremenek 8f01420d9d Teach -Wuninitialized-experimental about sizeof().
llvm-svn: 124076
2011-01-23 17:53:04 +00:00
Ted Kremenek 14cf0aba4d Removing debug printing logic from UninitializedValuesV2.
llvm-svn: 123944
2011-01-20 21:25:34 +00:00
Ted Kremenek cdca8fa97d Relax CFG assertions in UninitializedValuesV2 when
handling pseudo-path sensitivity, and instead
use those assertion conditions as dynamic checks.
These assertions would be violated when analyzing
a CFG where some branches where optimized away
during CFG construction because their branch
conditions could be trivially determined.

llvm-svn: 123943
2011-01-20 21:25:31 +00:00
Ted Kremenek b82ddd6ada Add rudimentary path-sensitivity to UnintializedValuesV2
analysis for short-circuited operations.  For branch written like "if (x && y)",
we maintain two sets of dataflow values for the outgoing
branches.  This suppresses some common false positives
for -Wuninitialized-experimental.

This change introduces some assertion failures
when running on the LLVM codebase.  WIP.

llvm-svn: 123923
2011-01-20 17:37:17 +00:00
John McCall 424cec97bd Change QualType::getTypePtr() to return a const pointer, then change a
thousand other things which were (generally inadvertantly) relying on that.

llvm-svn: 123814
2011-01-19 06:33:43 +00:00
Ted Kremenek b63931eef6 Teach UninitializedValuesV2 to implicitly reason about C++
references by monitoring whether an access to
a variable is solely to compute it's lvalue or
to do an lvalue-to-rvalue conversion (i.e., a load).

llvm-svn: 123777
2011-01-18 21:18:58 +00:00
Ted Kremenek c8d55da05a Correctly enable test/Sema/unit-variables.c,
thus identifying a minor logical flaw in
UninitializedValuesV2.cpp.

llvm-svn: 123734
2011-01-18 05:00:42 +00:00
Ted Kremenek cab479f0ee Teach UninitializedValuesV2 about "int x = x" and
also properly handle confluence of loops.

llvm-svn: 123733
2011-01-18 04:53:25 +00:00
Anders Carlsson 36ecb1f208 Add AnalysisContext::dumpCFG.
llvm-svn: 123602
2011-01-16 22:05:23 +00:00
Francois Pichet 07a2e14f44 Unbreak the MSVC build again: replace bzero by memset.
llvm-svn: 123538
2011-01-15 13:27:47 +00:00
Ted Kremenek b749a6d62a Add initial prototype for implementation of
-Wuninitialized based on CFG dataflow analysis.  WIP.

llvm-svn: 123512
2011-01-15 02:58:47 +00:00
Argyrios Kyrtzidis 52f04650ae [analyzer] Add 'bool ignorePrefix' parameter to cocoa::deriveNamingConvention to control whether
the prefix should be ignored.

E.g. if ignorePrefix is true, "_init" and "init" selectors will both be result in InitRule, but if
ignorePrefix is false, only "init" will return InitRule.

llvm-svn: 123262
2011-01-11 19:45:16 +00:00
Alexis Hunt 1d7926502f Renamed CXXBaseOrMemberInitializer to CXXCtorInitializer. This is both shorter,
more accurate, and makes it make sense for it to hold a delegating constructor
call.

llvm-svn: 123084
2011-01-08 20:30:50 +00:00
Chandler Carruth b35635e942 Remove a kludge from analysis based warnings that used to detect
temporaries with no-return destructors. The CFG now properly supports
temporaries and implicit destructors which both makes this kludge no
longer work, and conveniently removes the need for it.

Turn on CFG handling of implicit destructors and initializers. Several
ad-hoc benchmarks don't indicate any measurable performance impact from
growing the CFG, and it fixes real correctness problems with warnings.

As a result of turning on these CFG elements, we started to tickle an
inf-loop in the unreachable code logic used for warnings. The fix is
trivial.

llvm-svn: 123056
2011-01-08 06:54:40 +00:00
Ted Kremenek bf4832cda8 Add semantic checking that the "thousands grouping"
prefix in a printf format string is matched
with the appropriate conversion specifier.

llvm-svn: 123055
2011-01-08 05:28:46 +00:00
Ted Kremenek a322cae011 Add printf format string parsing support for '
prefix to format conversions (POSIX extension).

llvm-svn: 123054
2011-01-08 05:28:38 +00:00
Ted Kremenek ef81e9e243 Fix crash in CFGBuilder on invalid code. We still need
to reject this code, but at least clang doesn't
crash anymore.

Crash reported in PR 8880.

llvm-svn: 123017
2011-01-07 19:37:16 +00:00
Chris Lattner ad3467ee89 The -fshort-wchar option causes wchar_t to become unsigned, in addition to being
16-bits in size.  Implement this by splitting WChar into two enums, like we have
for char.  This fixes a miscompmilation of XULRunner, PR8856.

llvm-svn: 122558
2010-12-25 23:25:43 +00:00
Ted Kremenek 98857c9860 Rename static analyzer namespace 'GR' to 'ento'.
llvm-svn: 122492
2010-12-23 07:20:52 +00:00
Argyrios Kyrtzidis ca08fba414 [analyzer] Refactoring: Move stuff into namespace 'GR'.
llvm-svn: 122423
2010-12-22 18:53:20 +00:00
Ted Kremenek b44f0f9abe Fix assertion failure in cocoa::deriveNamingConvention()
when the selector is the string 'mutable'.

llvm-svn: 122046
2010-12-17 07:11:57 +00:00
Ted Kremenek 853da96736 Move CocoaConventions.[h,cpp] from libChecker
to libAnalysis.  Similar to Format (format string checking), 
CocoaConventions has the
potential to serve clients other than the
static analyzer.

llvm-svn: 122040
2010-12-17 05:21:58 +00:00
Ted Kremenek 3a9a2a551c Rename several methods/functions in the analyzer
to start with lowercase characters.  No
functionality change.

llvm-svn: 122035
2010-12-17 04:44:39 +00:00
Ted Kremenek 8219b82125 Start migration of static analyzer to using the
implicit lvalue-to-rvalue casts that John McCall
recently introduced.  This causes a whole bunch
of logic in the analyzer for handling lvalues
to vanish.  It does, however, raise a few issues
in the analyzer w.r.t to modeling various constructs
(e.g., field accesses to compound literals).

The .c/.m analysis test cases that fail are
due to a missing lvalue-to-rvalue cast that
will get introduced into the AST.  The .cpp
failures were more than I could investigate in
one go, and the patch was already getting huge.
I have XFAILED some of these tests, and they
should obviously be further investigated.

Some highlights of this patch include:

- CFG no longer requires an lvalue bit for
  CFGElements
- StackFrameContext doesn't need an 'asLValue'
  flag
- The "VisitLValue" path from GRExprEngine has
  been eliminated.

Besides the test case failures (XFAILed), there
are surely other bugs that are fallout from
this change.

llvm-svn: 121960
2010-12-16 07:46:53 +00:00
John McCall 5d41378146 Rename CXXExprWithTemporaries -> ExprWithCleanups; there's no theoretical
reason this is limited to C++, and it's certainly not limited to temporaries.

llvm-svn: 120996
2010-12-06 08:20:24 +00:00
Francois Pichet d583da04d0 More anonymous struct/union redesign. This one deals with anonymous field used in a constructor initializer list:
struct X {
  X() : au_i1(123) {}
  union {
    int au_i1;
    float au_f1;
  };
};

clang will now deal with au_i1 explicitly as an IndirectFieldDecl.

llvm-svn: 120900
2010-12-04 09:14:42 +00:00
John McCall 34376a68c4 Although we currently have explicit lvalue-to-rvalue conversions, they're
not actually frequently used, because ImpCastExprToType only creates a node
if the types differ.  So explicitly create an ICE in the lvalue-to-rvalue
conversion code in DefaultFunctionArrayLvalueConversion() as well as several
other new places, and consistently deal with the consequences throughout the
compiler.

In addition, introduce a new cast kind for loading an ObjCProperty l-value,
and make sure we emit those nodes whenever an ObjCProperty l-value appears
that's not on the LHS of an assignment operator.

This breaks a couple of rewriter tests, which I've x-failed until future
development occurs on the rewriter.

Ted Kremenek kindly contributed the analyzer workarounds in this patch.

llvm-svn: 120890
2010-12-04 03:47:34 +00:00
Ted Kremenek 9e618ed1c9 Fix range in printf warnings for invalid conversion specifiers.
llvm-svn: 120735
2010-12-02 20:57:51 +00:00
Zhongxing Xu a1a9ba11b7 Let StackFrameContext represent if the call expr is evaluated as lvalue.
This is required for supporting const reference to temporary objects.

llvm-svn: 120093
2010-11-24 13:08:51 +00:00
Zhongxing Xu 9b6e6b087f print asLValue attribute of CFGStmt.
llvm-svn: 120086
2010-11-24 06:33:02 +00:00
Zhanyong Wan b5d11c127a Refactor AddStmtChoice to make it easier to use; also add comments on how the class works. Reviewed by kremenek.
llvm-svn: 120080
2010-11-24 03:28:53 +00:00
Zhanyong Wan 59f09c7483 Stylistic changes to CFG.cpp:
1. "no 'else' after 'return'" -- this is for conformance with the
coding standards.

2. move 'else' to the line of the previous '}' -- this is for consistency.

Reviewed by kremenek.

llvm-svn: 119983
2010-11-22 19:32:14 +00:00
Zhanyong Wan 6dace61730 Fix PR8419. Reviewed by kremenek and xuzhongxing.
llvm-svn: 119960
2010-11-22 08:45:56 +00:00
Anders Carlsson a369f8dc3a The 'X' printf type has a valid alternative form. Fixes PR8641.
llvm-svn: 119946
2010-11-21 18:34:21 +00:00
Ted Kremenek 18fb1665bf Remove invalid assertion from CFG builder. When building the CFG pieces for a ternary '?' expression,
it is possible for the confluence block to only have a single predecessor due to calls to 'noreturn'
functions.  Fixes assertion failure reported in PR 8619.

llvm-svn: 119284
2010-11-15 22:59:22 +00:00
Zhongxing Xu fee455fcf5 Revert r118991.
Elidable CXXConstructExpr should inhibit calling destructor for temporary 
that is copied, not the one created. This is because eliding copy constructor 
means that the object that was to be copied will be constructed directly in 
memory the copy would be constructed in.

llvm-svn: 119044
2010-11-14 15:23:50 +00:00
Zhongxing Xu 1b038fa00f Do not add implicit dtors for CXXBindTemporaryExpr with elidable
CXXConstructExpr.

llvm-svn: 118991
2010-11-13 07:30:59 +00:00
Anders Carlsson 3fd50319d3 Don't warn when matching %p to nullptr.
llvm-svn: 118344
2010-11-06 14:58:53 +00:00
Zhongxing Xu fb2f8164ae Do not add elidable CXXConstructExpr as block-level expr.
llvm-svn: 118165
2010-11-03 11:14:06 +00:00
Marcin Swiderski 3ab17ad8ec Added generating destructors for temporary objects. Two cases I know of, that are not handled properly:
1. For statement: const C& c = C(0) ?: C(1) destructors generated for condition will not differ from those generated for case without prolonged lifetime of temporary,
2. There will be no destructor for constant reference member bound to temporary at the exit from constructor.

llvm-svn: 118158
2010-11-03 06:19:35 +00:00