[cfe-commits] r132840 - in /cfe/trunk: lib/Analysis/AnalysisContext.cpp lib/Analysis/CFG.cpp lib/Analysis/LiveVariables.cpp lib/StaticAnalyzer/Core/Environment.cpp test/Analysis/misc-ps.c
Jordy Rose
jediknil at belkadan.com
Fri Jun 10 01:49:37 PDT 2011
Author: jrose
Date: Fri Jun 10 03:49:37 2011
New Revision: 132840
URL: http://llvm.org/viewvc/llvm-project?rev=132840&view=rev
Log:
[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.
Modified:
cfe/trunk/lib/Analysis/AnalysisContext.cpp
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/lib/Analysis/LiveVariables.cpp
cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
cfe/trunk/test/Analysis/misc-ps.c
Modified: cfe/trunk/lib/Analysis/AnalysisContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisContext.cpp?rev=132840&r1=132839&r2=132840&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/AnalysisContext.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisContext.cpp Fri Jun 10 03:49:37 2011
@@ -78,16 +78,16 @@
if (!forcedBlkExprs)
forcedBlkExprs = new CFG::BuildOptions::ForcedBlkExprs();
// Default construct an entry for 'stmt'.
- if (const ParenExpr *pe = dyn_cast<ParenExpr>(stmt))
- stmt = pe->IgnoreParens();
+ if (const Expr *e = dyn_cast<Expr>(stmt))
+ stmt = e->IgnoreParens();
(void) (*forcedBlkExprs)[stmt];
}
const CFGBlock *
AnalysisContext::getBlockForRegisteredExpression(const Stmt *stmt) {
assert(forcedBlkExprs);
- if (const ParenExpr *pe = dyn_cast<ParenExpr>(stmt))
- stmt = pe->IgnoreParens();
+ if (const Expr *e = dyn_cast<Expr>(stmt))
+ stmt = e->IgnoreParens();
CFG::BuildOptions::ForcedBlkExprs::const_iterator itr =
forcedBlkExprs->find(stmt);
assert(itr != forcedBlkExprs->end());
Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=132840&r1=132839&r2=132840&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Fri Jun 10 03:49:37 2011
@@ -397,6 +397,8 @@
if (alwaysAdd(S))
cachedEntry->second = B;
+ // All block-level expressions should have already been IgnoreParens()ed.
+ assert(!isa<Expr>(S) || cast<Expr>(S)->IgnoreParens() == S);
B->appendStmt(const_cast<Stmt*>(S), cfg->getBumpVectorContext());
}
void appendInitializer(CFGBlock *B, CXXCtorInitializer *I) {
@@ -841,11 +843,14 @@
/// blocks for ternary operators, &&, and ||. We also process "," and
/// DeclStmts (which may contain nested control-flow).
CFGBlock* CFGBuilder::Visit(Stmt * S, AddStmtChoice asc) {
-tryAgain:
if (!S) {
badCFG = true;
return 0;
}
+
+ if (Expr *E = dyn_cast<Expr>(S))
+ S = E->IgnoreParens();
+
switch (S->getStmtClass()) {
default:
return VisitStmt(S, asc);
@@ -957,10 +962,6 @@
case Stmt::ObjCForCollectionStmtClass:
return VisitObjCForCollectionStmt(cast<ObjCForCollectionStmt>(S));
- case Stmt::ParenExprClass:
- S = cast<ParenExpr>(S)->getSubExpr();
- goto tryAgain;
-
case Stmt::NullStmtClass:
return Block;
@@ -3049,6 +3050,7 @@
if (!CS)
continue;
if (Expr* Exp = dyn_cast<Expr>(CS->getStmt())) {
+ assert((Exp->IgnoreParens() == Exp) && "No parens on block-level exps");
if (BinaryOperator* B = dyn_cast<BinaryOperator>(Exp)) {
// Assignment expressions that are not nested within another
@@ -3056,13 +3058,16 @@
// another expression.
if (B->isAssignmentOp() && !SubExprAssignments.count(Exp))
continue;
- } else if (const StmtExpr* Terminator = dyn_cast<StmtExpr>(Exp)) {
+ } else if (const StmtExpr* SE = dyn_cast<StmtExpr>(Exp)) {
// Special handling for statement expressions. The last statement in
// the statement expression is also a block-level expr.
- const CompoundStmt* C = Terminator->getSubStmt();
+ const CompoundStmt* C = SE->getSubStmt();
if (!C->body_empty()) {
+ const Stmt *Last = C->body_back();
+ if (const Expr *LastEx = dyn_cast<Expr>(Last))
+ Last = LastEx->IgnoreParens();
unsigned x = M->size();
- (*M)[C->body_back()] = x;
+ (*M)[Last] = x;
}
}
@@ -3076,8 +3081,8 @@
Stmt* S = (*I)->getTerminatorCondition();
if (S && M->find(S) == M->end()) {
- unsigned x = M->size();
- (*M)[S] = x;
+ unsigned x = M->size();
+ (*M)[S] = x;
}
}
Modified: cfe/trunk/lib/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/LiveVariables.cpp?rev=132840&r1=132839&r2=132840&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Fri Jun 10 03:49:37 2011
@@ -142,12 +142,8 @@
if (AD.Observer)
AD.Observer->ObserveStmt(S, currentBlock, AD, LiveState);
- if (getCFG().isBlkExpr(S)) {
- if (Expr *E = dyn_cast<Expr>(S))
- LiveState(E->IgnoreParens(), AD) = Dead;
- else
- LiveState(S, AD) = Dead;
- }
+ if (getCFG().isBlkExpr(S))
+ LiveState(S, AD) = Dead;
StmtVisitor<TransferFuncs,void>::Visit(S);
}
@@ -161,10 +157,7 @@
}
else {
// For block-level expressions, mark that they are live.
- if (Expr *E = dyn_cast<Expr>(S))
- LiveState(E->IgnoreParens(), AD) = Alive;
- else
- LiveState(S, AD) = Alive;
+ LiveState(S, AD) = Alive;
}
}
@@ -181,9 +174,6 @@
return;
assert (getCFG().isBlkExpr(E));
-
- if (const Expr *Ex = dyn_cast<Expr>(E))
- E = Ex->IgnoreParens();
LiveState(E, AD) = Alive;
}
Modified: cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp?rev=132840&r1=132839&r2=132840&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp Fri Jun 10 03:49:37 2011
@@ -77,21 +77,6 @@
// For special C0xx nullptr case, make a null pointer SVal.
case Stmt::CXXNullPtrLiteralExprClass:
return svalBuilder.makeNull();
- case Stmt::ImplicitCastExprClass:
- case Stmt::CXXFunctionalCastExprClass:
- case Stmt::CStyleCastExprClass: {
- // We blast through no-op casts to get the descendant
- // subexpression that has a value.
- const CastExpr* C = cast<CastExpr>(E);
- QualType CT = C->getType();
- if (CT->isVoidType())
- return UnknownVal();
- if (C->getCastKind() == CK_NoOp) {
- E = C->getSubExpr();
- continue;
- }
- break;
- }
case Stmt::ExprWithCleanupsClass:
E = cast<ExprWithCleanups>(E)->getSubExpr();
continue;
Modified: cfe/trunk/test/Analysis/misc-ps.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/misc-ps.c?rev=132840&r1=132839&r2=132840&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/misc-ps.c (original)
+++ cfe/trunk/test/Analysis/misc-ps.c Fri Jun 10 03:49:37 2011
@@ -62,3 +62,22 @@
return *t; // no-warning
}
+int PR8962_e (int *t) {
+ // Redundant casts can mess things up!
+ // Environment used to skip through NoOp casts, but LiveVariables didn't!
+ if (({ (t ? (int)(int)0L : (int)(int)1L); })) return 0;
+ return *t; // no-warning
+}
+
+int PR8962_f (int *t) {
+ // The StmtExpr isn't a block-level expression here,
+ // the __extension__ is. But the value should be attached to the StmtExpr
+ // anyway. Make sure the block-level check is /before/ IgnoreParens.
+ if ( __extension__({
+ _Bool r;
+ if (t) r = 0;
+ else r = 1;
+ r;
+ }) ) return 0;
+ return *t; // no-warning
+}
More information about the cfe-commits
mailing list