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
diff --git a/AST/CFG.cpp b/AST/CFG.cpp
index befd840..7a13ac1 100644
--- a/AST/CFG.cpp
+++ b/AST/CFG.cpp
@@ -988,7 +988,7 @@
//===----------------------------------------------------------------------===//
namespace {
- typedef llvm::DenseMap<const Expr*,unsigned> BlkExprMapTy;
+ typedef llvm::DenseMap<const Stmt*,unsigned> BlkExprMapTy;
}
static BlkExprMapTy* PopulateBlkExprMap(CFG& cfg) {
@@ -999,23 +999,27 @@
if (const Expr* E = dyn_cast<Expr>(*BI)) {
unsigned x = M->size();
(*M)[E] = x;
+
+ // Special handling for statement expressions. The last statement
+ // in the statement expression is also a block-level expr.
+ if (const StmtExpr* S = dyn_cast<StmtExpr>(E)) {
+ const CompoundStmt* C = S->getSubStmt();
+ if (!C->body_empty()) {
+ x = M->size();
+ (*M)[C->body_back()] = x;
+ }
+ }
}
-
+
return M;
}
-bool CFG::isBlkExpr(const Stmt* S) {
- assert (S != NULL);
- if (const Expr* E = dyn_cast<Expr>(S)) return getBlkExprNum(E);
- else return true; // Statements are by default "block-level expressions."
-}
-
-CFG::BlkExprNumTy CFG::getBlkExprNum(const Expr* E) {
- assert(E != NULL);
+CFG::BlkExprNumTy CFG::getBlkExprNum(const Stmt* S) {
+ assert(S != NULL);
if (!BlkExprMap) { BlkExprMap = (void*) PopulateBlkExprMap(*this); }
BlkExprMapTy* M = reinterpret_cast<BlkExprMapTy*>(BlkExprMap);
- BlkExprMapTy::iterator I = M->find(E);
+ BlkExprMapTy::iterator I = M->find(S);
if (I == M->end()) return CFG::BlkExprNumTy();
else return CFG::BlkExprNumTy(I->second);