Commit Graph

560 Commits

Author SHA1 Message Date
Chris Lattner 8488c8297c This reworks some of the Diagnostic interfaces a bit to change how diagnostics
are formed.  In particular, a diagnostic with all its strings and ranges is now
packaged up and sent to DiagnosticClients as a DiagnosticInfo instead of as a 
ton of random stuff.  This has the benefit of simplifying the interface, making
it more extensible, and allowing us to do more checking for things like access
past the end of the various arrays passed in.

In addition to introducing DiagnosticInfo, this also substantially changes how 
Diagnostic::Report works.  Instead of being passed in all of the info required
to issue a diagnostic, Report now takes only the required info (a location and 
ID) and returns a fresh DiagnosticInfo *by value*.  The caller is then free to
stuff strings and ranges into the DiagnosticInfo with the << operator.  When
the dtor runs on the DiagnosticInfo object (which should happen at the end of
the statement), the diagnostic is actually emitted with all of the accumulated
information.  This is a somewhat tricky dance, but it means that the 
accumulated DiagnosticInfo is allowed to keep pointers to other expression 
temporaries without those pointers getting invalidated.

This is just the minimal change to get this stuff working, but this will allow
us to eliminate the zillions of variant "Diag" methods scattered throughout
(e.g.) sema.  For example, instead of calling:

  Diag(BuiltinLoc, diag::err_overload_no_match, typeNames,
       SourceRange(BuiltinLoc, RParenLoc));

We will soon be able to just do:

  Diag(BuiltinLoc, diag::err_overload_no_match)
      << typeNames << SourceRange(BuiltinLoc, RParenLoc));

This scales better to support arbitrary types being passed in (not just 
strings) in a type-safe way.  Go operator overloading?!

llvm-svn: 59502
2008-11-18 07:04:44 +00:00
Chris Lattner 3de58149bd eliminate dependence of strange "Diagnostic::Report" method,
delete huge trailing whitespace to fit in 80 cols.

llvm-svn: 59497
2008-11-18 06:07:40 +00:00
Chris Lattner 16ba91396a Change the diagnostics interface to take an array of pointers to
strings instead of array of strings.  This reduces string copying
in some not-very-important cases, but paves the way for future 
improvements.

llvm-svn: 59494
2008-11-18 04:56:44 +00:00
Chris Lattner 53f5d4c1b5 cleanups and simplifications.
llvm-svn: 59491
2008-11-18 04:44:58 +00:00
Ted Kremenek c775712192 Fold assertion into second valid else branch. This removes a compiler warning
where the control reaches the end of a non-void function and also allows the
compiler to generate better code.  When this assertion is false we can easily
add more else cases.

llvm-svn: 59468
2008-11-17 22:55:12 +00:00
Zhongxing Xu 99a96d6ef3 Enhance modularization: return a <state,loc> pair to let GRExprEngine modify the
environment.

llvm-svn: 59407
2008-11-16 07:06:26 +00:00
Zhongxing Xu ceca80619f Enhances SCA to process untyped region to typed region conversion.
- RegionView and RegionViewMap is introduced to assist back-mapping from
   super region to subregions.
 - GDM is used to carry RegionView information.
 - AnonTypedRegion is added to represent a typed region introduced by pointer
   casting. Later AnonTypedRegion can be used in other similar cases, e.g.,
   malloc()'ed region.
 - The specific conversion is delegated to store manager.

llvm-svn: 59382
2008-11-16 04:07:26 +00:00
Zhongxing Xu 461b4f4276 Use the allocator of ExplodedGraph. The whole static analysis module uses it.
llvm-svn: 59359
2008-11-15 08:19:58 +00:00
Zhongxing Xu 6a276cf5b7 Improve zero value generation.
llvm-svn: 59356
2008-11-15 05:18:50 +00:00
Ted Kremenek 1b2dace792 Reduce permissiveness of assertion.
llvm-svn: 59354
2008-11-15 05:00:27 +00:00
Ted Kremenek 4413714946 Reverted part of r59335: http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20081110/009243.html
In that patch I added a bogus type promotion for unary '!'.

The real bug was more fallout from edges cases with compound assignments and conjured symbolic values.  Now the conjured value has the type of the LHS expression, and we do a promotion to the computation type.  We also now correctly do a conversion from the computation type back to the LHS type.

llvm-svn: 59349
2008-11-15 04:01:56 +00:00
Ted Kremenek ac172fc574 Re-enable an assertion that I mistakenly removed.
llvm-svn: 59348
2008-11-15 02:35:08 +00:00
Ted Kremenek 519a223056 Use the correct QualType when creating the '0' constant.
llvm-svn: 59343
2008-11-15 00:40:08 +00:00
Ted Kremenek 1ca3346b19 Implement FIXME in GRExprEngine::VisitUnaryOperator() to handle implicit conversions caused by the '!' operator. This required adding some logic to GRSimpleVals to reason about nonloc::LocAsInteger SVals. This code appears to work fine, but it should eventually be cleaned up.
llvm-svn: 59335
2008-11-15 00:20:05 +00:00
Ted Kremenek 7eee049eea Flush llvm::errs() when printing out SVals.
llvm-svn: 59334
2008-11-15 00:16:53 +00:00
Ted Kremenek fc419a035f Minor tweaks to liveness analysis:
- Block-expression for 'ObjCForCollectionStmt' is not alive before it occurs
- Recursively visit 'element' expression for ObjCForCollectionStmt to get liveness for referenced block-level expressions and variables.

llvm-svn: 59316
2008-11-14 21:07:14 +00:00
Ted Kremenek 537f6387a2 Second attempt at implementation transfer function support for ObjCForCollectionStmt. We now assume that the 'element' expression can be any lvalue.
llvm-svn: 59313
2008-11-14 19:47:18 +00:00
Ted Kremenek 8959a1a69a Flow-sensitive uninitialized values analysis: properly handle the 'element' expression of ObjCForCollectionStmt (can be anything).
llvm-svn: 59312
2008-11-14 18:21:25 +00:00
Douglas Gregor 993603d80d Add a new expression node, CXXOperatorCallExpr, which expresses a
function call created in response to the use of operator syntax that
resolves to an overloaded operator in C++, e.g., "str1 +
str2" that resolves to std::operator+(str1, str2)". We now build a
CXXOperatorCallExpr in C++ when we pick an overloaded operator. (But
only for binary operators, where we actually implement overloading)

I decided *not* to refactor the current CallExpr to make it abstract
(with FunctionCallExpr and CXXOperatorCallExpr as derived
classes). Doing so would allow us to make CXXOperatorCallExpr a little
bit smaller, at the cost of making the argument and callee accessors
virtual. We won't know if this is going to be a win until we can parse
lots of C++ code to determine how much memory we'll save by making
this change vs. the performance penalty due to the extra virtual
calls.

llvm-svn: 59306
2008-11-14 16:09:21 +00:00
Zhongxing Xu c967d03528 Improve comments.
llvm-svn: 59294
2008-11-14 09:23:38 +00:00
Ted Kremenek 99d4ff3c7a Handle the case where 'element' in ObjCforCollectionstmt is not a DeclStmt or DeclRefExpr.
llvm-svn: 59290
2008-11-14 01:58:12 +00:00
Ted Kremenek a9d3e6c087 Rename header file.
Update include files.

llvm-svn: 59284
2008-11-14 01:14:18 +00:00
Ted Kremenek 7d5389e4b3 - Revert r59229 and r59232: AllocRegion should be immutable.
- Temporarily disabled test Analysis/array-struct.c for region store.

llvm-svn: 59245
2008-11-13 15:42:31 +00:00
Zhongxing Xu d4e72fca45 Process array base expression of any type.
llvm-svn: 59240
2008-11-13 09:48:44 +00:00
Zhongxing Xu 189a30796a Array index might be unsigned. We have to generate a temporary signed value for
it to be evaluated by APSInt::operators.

llvm-svn: 59238
2008-11-13 09:15:14 +00:00
Zhongxing Xu 29188c2948 Incomplete struct pointer can be used as a function argument.
llvm-svn: 59235
2008-11-13 08:41:36 +00:00
Zhongxing Xu 0dbeeaa886 Lift the pointer to alloca'ed region to the pointer to its first element.
This is required by some operations, e.g., *p = 1; p[0] = 1;.
Also set the AllocaRegion's type during the cast.

llvm-svn: 59232
2008-11-13 07:58:20 +00:00
Zhongxing Xu a70987eb82 Change AllocaRegion to subclass TypedRegion. We need to know ElementRegion's
type when assigning to it.

llvm-svn: 59229
2008-11-13 07:30:58 +00:00
Ted Kremenek 16866d6fd8 GRExprEngine/CFRefCount/GRSimpleVals: We don't do any special handling (yet) of vector types. Add explicit checks that when we process integers that they really are scalars.
llvm-svn: 59225
2008-11-13 06:10:40 +00:00
Ted Kremenek 75db6d7529 Fix uninitialized variable.
llvm-svn: 59222
2008-11-13 05:26:15 +00:00
Ted Kremenek 45698bf05f GRExprEngine::VisitInitListExpr:
- Don't crash on vector types.
- Handle typedefs.

llvm-svn: 59220
2008-11-13 05:05:34 +00:00
Ted Kremenek 65dd30fdea Update CFGStmtVisitor to recognize that ObjCForCollectionStmts are special block-level "expressions".
llvm-svn: 59176
2008-11-12 21:58:46 +00:00
Ted Kremenek df31792a66 Shore up transfer function for ObjCForCollectionStmt.
llvm-svn: 59162
2008-11-12 21:12:46 +00:00
Ted Kremenek 97450fe0a1 Use Stmt* instead of Expr* for block-level expression.
llvm-svn: 59161
2008-11-12 21:12:18 +00:00
Ted Kremenek 1781080c34 Add (preliminary) transfer function support for ObjCForCollectionStmt. Still need to flesh out some logic.
When processing DeclStmt, use the new interface to StateManager::BindDecl.  Conjuring of symbols is now done in VisitDeclStmt.

llvm-svn: 59155
2008-11-12 19:24:17 +00:00
Ted Kremenek 9999d72fe2 Conjured symbols now bind to Stmt* instead of Expr*.
llvm-svn: 59154
2008-11-12 19:22:47 +00:00
Ted Kremenek 60d46414f4 Update method names involving GRStateRef. No functionality change.
llvm-svn: 59153
2008-11-12 19:22:09 +00:00
Ted Kremenek b94d72a0e3 GRStateRef:
- Rename SetSVal to BindLoc
- Add BindDecl
- Add BindExpr

GRState:
- Environment now binds to Stmt* instead of Expr*.  This is needed for processing ObjCForCollectionStmt (essentially the declaration of the the 'element' variable can have an SVal attached to it).
- BindDecl no longer accepts Expr* for the initialization value; use SVal* instead.

llvm-svn: 59152
2008-11-12 19:21:30 +00:00
Ted Kremenek cd639218e4 StoreManager::BindDecl now takes an SVal* for the initialization value instead of an Expr* (which can be null). Lazy symbolication of conjured symbols is now the sole responsibility of GRExprEngine.
llvm-svn: 59151
2008-11-12 19:18:35 +00:00
Ted Kremenek 7a18858bcf Flow-sensitive uninitialized values analysis:
- Added support for ObjCForCollectionStmt
- Fixed bug where expression values would be always set to uninitialized when loops were involved

llvm-svn: 59076
2008-11-11 19:41:42 +00:00
Ted Kremenek 3b4e1d5cc6 Accesses to a collection within a fast enumeration 'for' statement constitute a 'use'.
llvm-svn: 59075
2008-11-11 19:40:47 +00:00
Sebastian Redl 6f28289aca Introduce a single AST node SizeOfAlignOfExpr for all sizeof and alignof expressions, both of values and types.
llvm-svn: 59057
2008-11-11 17:56:53 +00:00
Ted Kremenek fbd2f4006b Add transfer function support for ObjCForCollectionStmt to LiveVariables.
llvm-svn: 59053
2008-11-11 17:42:10 +00:00
Zhongxing Xu deb7cac332 Fix StringLiteral print bug.
llvm-svn: 59015
2008-11-11 01:36:32 +00:00
Zhongxing Xu bba5c7c629 Add pretty printing to StringRegion.
llvm-svn: 58985
2008-11-10 13:05:26 +00:00
Zhongxing Xu 18d6fd45de Implement RegionStoreManager::RemoveDeadBindings(). This prunes several false warning caused by removal of symbolic constraints. Currently we just mark all symbols live. Further optimization for dead binding removal needed.
llvm-svn: 58982
2008-11-10 09:39:04 +00:00
Zhongxing Xu 1c31dbe417 Print integer value instead of raw pointer. This is a hack to be fixed by migrating the output in analyzer to llvm::raw_ostream.
llvm-svn: 58965
2008-11-10 05:00:06 +00:00
Chris Lattner 231f7bbdbe silence a warning from gcc.
llvm-svn: 58956
2008-11-10 03:00:37 +00:00
Zhongxing Xu 3d43015bc7 Add a boilerplate for out-of-bound array checking. This has no real function currently.
llvm-svn: 58886
2008-11-08 03:45:42 +00:00
Zhongxing Xu 2c677c34d5 Finish the implementation of VisitCompoundLiteralExpr. As VisitInitListExpr is
available, things get much simplified.

One addition is that CompoundLiteralExpr can appear both in rvalue and lvalue
context.

llvm-svn: 58837
2008-11-07 10:38:33 +00:00