diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-09-26 05:52:45 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-09-26 05:52:45 +0000 |
commit | 2ece64bbc48e07ba25609ff3cc0232b1be6692dd (patch) | |
tree | 2250ca89c082f3e5edb11861f1330f150644c08c /clang/lib/Analysis/LiveVariables.cpp | |
parent | 08971bf2c43bbf0aa3a403dc6b12cdf36633e2d6 (diff) | |
download | bcm5719-llvm-2ece64bbc48e07ba25609ff3cc0232b1be6692dd.tar.gz bcm5719-llvm-2ece64bbc48e07ba25609ff3cc0232b1be6692dd.zip |
Examine VLA size expressions when computing liveness information.
Fixes <rdar://problem/6248086>
llvm-svn: 56645
Diffstat (limited to 'clang/lib/Analysis/LiveVariables.cpp')
-rw-r--r-- | clang/lib/Analysis/LiveVariables.cpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/clang/lib/Analysis/LiveVariables.cpp b/clang/lib/Analysis/LiveVariables.cpp index f5a7fb40c77..e82c1e0bc01 100644 --- a/clang/lib/Analysis/LiveVariables.cpp +++ b/clang/lib/Analysis/LiveVariables.cpp @@ -226,19 +226,41 @@ void TransferFuncs::VisitAssign(BinaryOperator* B) { 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. for (DeclStmt::decl_iterator DI=DS->decl_begin(), DE = DS->decl_end(); DI != DE; ++DI) if (VarDecl* VD = dyn_cast<VarDecl>(*DI)) { + // The initializer is evaluated after the variable comes into scope. + // Since this is a reverse dataflow analysis, we must evaluate the + // transfer function for this expression first. + if (Expr* Init = VD->getInit()) + Visit(Init); - // Update liveness information. + // Update liveness information by killing the VarDecl. unsigned bit = AD.getIdx(VD); LiveState.getDeclBit(bit) = Dead | AD.AlwaysLive.getDeclBit(bit); - - if (Expr* Init = VD->getInit()) - Visit(Init); + + // 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()); + } } |