[cfe-commits] r56655 - in /cfe/trunk/lib: AST/CFG.cpp Analysis/LiveVariables.cpp
Ted Kremenek
kremenek at apple.com
Fri Sep 26 09:26:37 PDT 2008
Author: kremenek
Date: Fri Sep 26 11:26:36 2008
New Revision: 56655
URL: http://llvm.org/viewvc/llvm-project?rev=56655&view=rev
Log:
Move VLA processing logic from LiveVariables to CFG construction. This way all dataflow analyses "see" the VLA size expressions.
Modified:
cfe/trunk/lib/AST/CFG.cpp
cfe/trunk/lib/Analysis/LiveVariables.cpp
Modified: cfe/trunk/lib/AST/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CFG.cpp?rev=56655&r1=56654&r2=56655&view=diff
==============================================================================
--- cfe/trunk/lib/AST/CFG.cpp (original)
+++ cfe/trunk/lib/AST/CFG.cpp Fri Sep 26 11:26:36 2008
@@ -467,6 +467,18 @@
return WalkAST_VisitChildren(Terminator);
}
+static VariableArrayType* FindVA(Type* t) {
+ while (ArrayType* vt = dyn_cast<ArrayType>(t)) {
+ if (VariableArrayType* vat = dyn_cast<VariableArrayType>(vt))
+ if (vat->getSizeExpr())
+ return vat;
+
+ t = vt->getElementType().getTypePtr();
+ }
+
+ return 0;
+}
+
/// WalkAST_VisitDeclSubExpr - Utility method to add block-level expressions
/// for initializers in Decls.
CFGBlock* CFGBuilder::WalkAST_VisitDeclSubExpr(ScopedDecl* D) {
@@ -477,18 +489,22 @@
Expr* Init = VD->getInit();
- if (!Init)
- return Block;
-
- // Optimization: Don't create separate block-level statements for literals.
- switch (Init->getStmtClass()) {
- case Stmt::IntegerLiteralClass:
- case Stmt::CharacterLiteralClass:
- case Stmt::StringLiteralClass:
- break;
- default:
- Block = addStmt(Init);
+ if (Init) {
+ // Optimization: Don't create separate block-level statements for literals.
+ switch (Init->getStmtClass()) {
+ case Stmt::IntegerLiteralClass:
+ case Stmt::CharacterLiteralClass:
+ case Stmt::StringLiteralClass:
+ break;
+ default:
+ Block = addStmt(Init);
+ }
}
+
+ // If the type of VD is a VLA, then we must process its size expressions.
+ for (VariableArrayType* VA = FindVA(VD->getType().getTypePtr()); VA != 0;
+ VA = FindVA(VA->getElementType().getTypePtr()))
+ Block = addStmt(VA->getSizeExpr());
return Block;
}
Modified: cfe/trunk/lib/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/LiveVariables.cpp?rev=56655&r1=56654&r2=56655&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Fri Sep 26 11:26:36 2008
@@ -226,18 +226,6 @@
Visit(B->getRHS());
}
-static VariableArrayType* FindVA(Type* t) {
- while (ArrayType* vt = dyn_cast<ArrayType>(t)) {
- if (VariableArrayType* vat = dyn_cast<VariableArrayType>(vt))
- if (vat->getSizeExpr())
- return vat;
-
- t = vt->getElementType().getTypePtr();
- }
-
- return NULL;
-}
-
void TransferFuncs::VisitDeclStmt(DeclStmt* DS) {
// Declarations effectively "kill" a variable since they cannot
// possibly be live before they are declared.
@@ -253,14 +241,6 @@
// Update liveness information by killing the VarDecl.
unsigned bit = AD.getIdx(VD);
LiveState.getDeclBit(bit) = Dead | AD.AlwaysLive.getDeclBit(bit);
-
- // If the type of VD is a VLA, then we must process its size expressions.
- // These expressions are evaluated before the variable comes into scope,
- // so in a reverse dataflow analysis we evaluate them last.
- for (VariableArrayType* VA = FindVA(VD->getType().getTypePtr()); VA != 0;
- VA = FindVA(VA->getElementType().getTypePtr()))
- Visit(VA->getSizeExpr());
-
}
}
More information about the cfe-commits
mailing list