Граф коммитов

69 Коммитов

Автор SHA1 Сообщение Дата
Ted Kremenek d34066c224 Fixed bug in CFG construction when a CompoundStmt ended with a NullStmt.
This caused the whole body to get dropped from the CFG.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47579 91177308-0d34-0410-b5e6-96231b3b80d8
2008-02-26 00:22:58 +00:00
Ted Kremenek eef5a9ac59 When creating the CFGBlocks for a switch statement, we now have the "default"
branch ALWAYS be the last successor for a switch-terminated block. This allows
clients to distinguish cases like the following:

switch(...)
  case XXX:
    switch(...) {
      case YYY: ...
    }
    
  case ZZZ: ..
}

In this case, the block with "case ZZZ:" is the default block for the inner
switch statement, but that case is associated with the outer switch statement,
and not the inner one. Clients can test for this behavior by checking if a
successor block is the last one (and thus just assume that this is the "default"
case).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47088 91177308-0d34-0410-b5e6-96231b3b80d8
2008-02-13 22:05:39 +00:00
Ted Kremenek 295222c1f0 Fixed bug in CFG construction when processing switch statements that contain no
"default" case. In such cases, we now correctly add the CFGBlock representing
the code after the switch statement as a successor to the block terminated by
the switch statement.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47087 91177308-0d34-0410-b5e6-96231b3b80d8
2008-02-13 21:46:34 +00:00
Ted Kremenek a292585207 Added method "printTerminator" to CFGBlock so that external clients can
pretty-print a block's terminator.

When building CFGs, for IfStmts ('if'), we no longer add the ParenExpr
that is the subexpression of the IfStmt to the CFG; instead we add its
first descendant subexpression that is not a ParenExpr.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46580 91177308-0d34-0410-b5e6-96231b3b80d8
2008-01-30 23:02:42 +00:00
Ted Kremenek 33d4aab80f Added back logic in patch r46361 (http://llvm.org/viewvc/llvm-project?rev=46361&view=rev) with the addition of
some previously missing NULL pointer checks.

Modified the UninitializedValues analysis to not expect that every Expr* at the
block-level is a block-level expression (we probably need to change the name of
such expressions to something truer to their meaning).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46380 91177308-0d34-0410-b5e6-96231b3b80d8
2008-01-26 00:03:27 +00:00
Ted Kremenek e2dcd783a0 Reverting r46361 (http://llvm.org/viewvc/llvm-project?rev=46361&view=rev) until
I diagnose the source of the failures it causes in the test suite.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46376 91177308-0d34-0410-b5e6-96231b3b80d8
2008-01-25 23:22:27 +00:00
Ted Kremenek 7accba0fa9 When adding assignment expressions to the set of block-level expressions, only
include the assignment expressions whose result (as in the value of the
expression) is used by other expressions.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46361 91177308-0d34-0410-b5e6-96231b3b80d8
2008-01-25 18:28:28 +00:00
Ted Kremenek 8694674522 Modified the notion of "Block-level expressions" in CFGs to include Stmt*. This
is because GNU-style Statement-expressions cause the last statement in the
statement-expression to act like an expression.

We now have two notions: block-level statements and block-level expressions.

The former are all Stmt* that appear in the list of statements in CFGBlocks. The
latter is the subset of the former; these block-level statements are used as
subexpressions somewhere in the AST. CFG::isBlockExpr() returns true for the
latter, not the former (previously isBlockExpr() always returned true for
non-Expr Stmt*).

Modified the LiveVariables analysis to also track liveness state for block-level
expressions (using the updated definition of block-level expressions).

Modified the dataflow solver so that when it records values for block-level
statements, it records the dataflow value *before* the transfer function for a
Stmt* is evaluated (not after). This is more in sync in what clients will want.

Modified CFGStmtVisitor to record the current block-level statement.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46143 91177308-0d34-0410-b5e6-96231b3b80d8
2008-01-17 20:48:37 +00:00
Ted Kremenek 83c01da96f Renamed ProgramEdge to ProgramPoint and changed subclasses of ProgramEdge
to have a much simpler, cleaner interpretation of what is a "location"
in a function (as encoded by a CFG).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45846 91177308-0d34-0410-b5e6-96231b3b80d8
2008-01-11 00:40:29 +00:00
Ted Kremenek 6fa9b88e2c Added VISIBILITY_HIDDEN to classes/structs in anonymous namespace.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45749 91177308-0d34-0410-b5e6-96231b3b80d8
2008-01-08 18:15:10 +00:00
Chris Lattner 0bc735ffcf Don't attribute in file headers anymore. See llvmdev for the
discussion of this change.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45410 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-29 19:59:25 +00:00
Ted Kremenek afe54333a7 Fixed successor order for CFG basic blocks when handling: x && y. The bug
is best explained by illustration:

[ B2 ]
     1: x
     T: [B2.1] && ...
   Predecessors (1): B4
   Successors (2): B3 B1

Block "B3" should be the block where we evaluate "y" when "x" evaluates to
true. Previously we had the successor list reversed. Now this behavior matches
with how we handle other conditional branches.

Thanks to Nuno Lopes for reporting this problem.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45288 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-21 19:49:00 +00:00
Ted Kremenek 7e3a89db59 Removed CFG.cpp's dependence on #including iostream.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45116 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-17 19:35:20 +00:00
Ted Kremenek a651e0e9e0 CFG bug fix: for sizeof(expressions), don't expand the control-flow
of "expressions", since they are not really evaluated.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@45015 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-13 22:44:18 +00:00
Ted Kremenek 9a8385d665 Fixed bug in CFG::PopulateBlkExprMap where the ordering
between fetching the size of the expression map (for use as
the next integer id for an Expr*) and the creation of the
entry in the map could be non-deterministic.  This could
cause the size of the map to be incremented prior to the
index being determine.

On Linux the map entry would be created first, causing the
map to the "size" to be incremented prior to it being
queried. On Mac OS X we had the reverse behavior. Now the
size is always queried prior to the new id being inserted
into the map.

This was the real cause of the bit-overrun triggered in
PR 1847:

  http://llvm.org/bugs/show_bug.cgi?id=1847
  
Also reverted the change in patch 44813, which was a bogus
fix to this problem:

  http://llvm.org/viewvc/llvm-project?rev=44813&view=rev


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44822 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-10 23:58:39 +00:00
Ted Kremenek ecc04c9254 Fixed bug in CFG construction where we did not properly handle the GCC
extension "?:" for the ternary operator, e.g.: x ?: y; This expression is
represented in the clang ASTs as a ConditionalOperator whose LHS expression is
NULL. Now we handle this special case, causing the block containing the
condition to be a predecessor to the block that "merges" the values of the
ternary operator.

Thanks to Nuno Lopes for identifying and diagnosing this bug!


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44327 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-26 18:20:26 +00:00
Ted Kremenek d660322ccf Fixed bug in WalkaST_VisitDeclSubExprs where we failed to properly check if
the StmtIterator referring to the initializers of a chain of Decls was equal
to the "end" iterator. The particular bug manifested when an iterator was
created on a chain of decls with no initializers.

Thanks to Nuno Lopes for reporting this bug and providing a patch.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44220 91177308-0d34-0410-b5e6-96231b3b80d8
2007-11-18 20:06:01 +00:00
Ted Kremenek 8f54c1faaa Refactored CFG construction code that processes DeclStmts to use StmtIterator.
Now CFG construction transparently supports Variable Length Array declarations
with expressions for their sizes, and typedefs that include VLAs.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43520 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-30 21:48:34 +00:00
Ted Kremenek 7a9d9d71fa Modified CFG pretty-printing to directly use the (reverse) body
iterator of a CompountStmt instead of relying on StmtIterators.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43469 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-29 20:41:04 +00:00
Chris Lattner c266acd6d7 remove dead #include
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43149 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-18 21:23:00 +00:00
Ted Kremenek 11e7218db5 Migrated LiveVariables and UninitializedVariables to now use the
tracked BlkExpr information now maintained by the CFG class.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42498 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-01 20:33:52 +00:00
Ted Kremenek 63f5887f31 CFG objects now internally store a (lazily created) map from block-level
expressions to IDs.  This is used by various dataflow analyses, but is
also useful for anyone querying a CFG to determine where an expression
is evaluated.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42495 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-01 19:33:33 +00:00
Ted Kremenek d48ade633d Removed "hasImplicitControlFlow" from class CFG, and moved it to class Stmt
as a member function.  This function is no longer needed within the CFG
class, and logically belongs to the Stmt class as a predicate for a
Stmt instance.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42489 91177308-0d34-0410-b5e6-96231b3b80d8
2007-10-01 16:34:52 +00:00
Chris Lattner 271f1a6373 Fix some use of uninit variables issues, reported by Anton.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42396 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-27 15:15:46 +00:00
Ted Kremenek 322f58d383 Fixed two bugs in CFG construction:
BUG 1) 

CFG failed to build for empty functions, or functions containing only
NullStmts or empty compound statements.

We now handle such cases, although now we cannot test for CFG
construction failure by asserting that the last block constructed is
not NULL (since it now may be).

BUG 2)

CFG construction segfaulted on some cases when walking the AST and not
taking into account that some children of a statement may be NULL.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42370 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-26 21:23:31 +00:00
Ted Kremenek 94b3316ee3 When building CFGs we now (unconditionally) add an empty CFGBlock to the CFG
to serve as the entry block.  An empty entry block (just as with an
empty exit block, which we already have) simplifies building analyses on top
of CFGs with very little extra overhead.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42031 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-17 16:18:02 +00:00
Hartmut Kaiser 3860c11a3f Fixed unterminated string issue.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42022 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-17 12:29:55 +00:00
Chris Lattner 0012351e82 make var in anon namespace static. Use \n instead of std::endl.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42020 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-17 06:16:32 +00:00
Chris Lattner f874c13463 fix warning.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@42006 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-16 19:11:53 +00:00
Hartmut Kaiser 6bfce24b79 Fixed a problem VC++ revealed in release mode. Please verify.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41996 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-16 00:31:07 +00:00
Hartmut Kaiser bd250b44d6 Fixed two problems VC++ revealed in release mode. Please verify.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41995 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-16 00:28:28 +00:00
Ted Kremenek 155383b0fc Added static method "CFG::hasImplicitControlFlow".
This method is used to determine if an expression contains implicit
control-flow, and thus appears in a distinct statement slot in the CFG.

For example:

  (1) x = ... ? ... ? ...

  logically becomes:

  (1) ... ? ... : ...  (a unique statement slot for the ternary ?)
  (2) x = [E1]         (where E1 is actually the ConditionalOperator*)

A client of the CFG, when walking the statement at (2), will encounter
E1.  In this case, hasImplicitControlFlow(E1) == true, and the client
will know that the expression E1 is explicitly placed into its own statement
slot to capture the implicit control-flow it has.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41868 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-11 22:08:24 +00:00
Ted Kremenek f50ec1026d Fixed bug where ternary expressions and GCC-style conditional expressions
where not reversing the order of their subexpression blocks.

Added feature where CallExprs are placed in their own statement slot in
a CFGBlock.  Thus we have a designated "return site" within a CFGBlock when
reasoning about function calls.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41866 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-11 21:29:43 +00:00
Ted Kremenek 9438252ad2 Moved tracking of CFG block IDs into the CFG class.
Added CFG::getNumBlockIDs() to query the number of distinct block ids created.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41724 91177308-0d34-0410-b5e6-96231b3b80d8
2007-09-05 20:02:05 +00:00
Ted Kremenek 60266e8a9a Fixed missing '(' and ')' characters in (CFG) pretty-printing of
statement expressions.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41659 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-31 22:47:06 +00:00
Ted Kremenek aeddbf689e Added better pretty printing in CFGs for __builtin_choose_expr
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41658 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-31 22:29:13 +00:00
Ted Kremenek 1c29bba6da Further cleanups in CFG printing for comma expressions, statement expressions, and indirect gotos.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41657 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-31 22:26:13 +00:00
Ted Kremenek 805e9a8300 Cleanups for printing the terminators of CFGBlocks for "?", "||", and "&&" operators.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41654 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-31 21:49:40 +00:00
Ted Kremenek 42a509f6a4 Added "PrinterHelper" interface (include/AST/PrinterHelper) that can
be passed as an (optional) argument to StmtPrinter to customize
printing of AST nodes.

Used new PrinterHelper interface to enhance printing and visualization
of CFGs.  The CFGs now illustrate the semantic connectives between
statements and terminators, wheras in the previous printing certain
expressions would (visible) be printed multiple times to reflect which
expressions used the results of other expressions.

The end result is that the CFG is easier to read for flow of
expression values (following principles similar to the LLVM IR).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41651 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-31 21:30:12 +00:00
Ted Kremenek 49a436de36 Added support for __builtin_choose_expr (ChooseExpr) in CFGs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41646 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-31 17:03:41 +00:00
Ted Kremenek 535bb20b6e Minor cleanups to pretty-printing for loops in CFGs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41623 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-30 21:28:02 +00:00
Ted Kremenek 29ccaa186a Fixed a bug in constructing CFG blocks for case statement fall-through
introduced by moving "CaseStmt" pointers out of the list of statements
and into the explicit "label" associated with a CFGBlock.  --This
line, and those below, will be ignored--

M    AST/CFG.cpp


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41622 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-30 18:48:11 +00:00
Ted Kremenek af603f7424 Fixed bug in CFG construction where we failed to handle loop bodies with
no statements (or just full of ';' statements).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41620 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-30 18:39:40 +00:00
Ted Kremenek 16e4dc8073 Fixed bug in CFG construction involving use of labels and "empty"
blocks involving only ';' statements.  We now correctly handle the following:

void empty_label() { l1: ; }


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41619 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-30 18:20:57 +00:00
Ted Kremenek b6f7b72047 Fixed bug where the CFG would fail to build when an 'if' statement had
an empty then or else block (or contained only ';' statements).

For example, we now handle the following:

int empty_else() { if (0) { int a; } else ; }
int empty_then() { if (0) ; else { int a; } }

Thanks to Nico Weber for spotting this problem.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41617 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-30 18:13:31 +00:00
Ted Kremenek 9cffe7366e Added an (optional) explicit "Label" statement to CFGBlock. If a
block begins with a label or case statement, CFGBlock::getLabel() will
return the corresponding LabelStmt/CaseStmt/DefaultStmt.

LabelStmts and SwitchCases no longer appear within the "executable"
statements of a CFGBlock.

More cleanups on visualization/pretty-printing of CFGs (less verbose).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41585 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-29 23:20:49 +00:00
Ted Kremenek 7dba8607e5 Added GraphTraits to source-level CFGs (CFG and CFGBlock) to allow
(LLVM-provided) graph algorithms such as DFS and graph visualization
to work effortless on source-level CFGs.

Further cleanup on pretty printing of CFGs.  CFGBlock::dump and
CFGBlock::print now take the parent CFG as an argument.  This allows
CFGBlocks to print their own appropriate label indicating whether or
not they are the Entry/Exit/IndirectGotoBlock without the CFG::print
routine doing it instead.

Added Graphviz visualization for CFGs: CFG::viewCFG.  This employs the
GraphTraits just implemented.

Added "-view-cfg" mode the to clang driver.  This is identical to
"-dump-cfg" except that it calls Graphviz to visualize the CFGs
instead of dumping them to the terminal.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41580 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-29 21:56:09 +00:00
Ted Kremenek 19bb356317 Added support for indirect-gotos (GCC extension) in source-level CFGs.
This involves the construction of a specialized "dispatch" block that
all basic blocks containing indirect gotos unconditionally transfer
control-flow to.  The successors of the dispatch block has as its successors
all of the blocks containing labels whose address was taken somewhere in
the function.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41554 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-28 19:26:49 +00:00
Ted Kremenek 15c27a84e5 Added support for GCC-style statement expressions in source-level CFGs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41549 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-28 18:30:10 +00:00
Ted Kremenek b49e1aa3ef Added support for comma expressions and DeclStmts which may have
arbitrarily complex control-flow in their subexpressions.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41547 91177308-0d34-0410-b5e6-96231b3b80d8
2007-08-28 18:14:37 +00:00