summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/LiveVariables.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-03-03 01:17:41 +0000
committerTed Kremenek <kremenek@apple.com>2010-03-03 01:17:41 +0000
commit0f0883b918260f5c7d1f191f58cd4f68f62f2b55 (patch)
tree16168cc092323fd1d1135568d62da4907e47872d /clang/lib/Analysis/LiveVariables.cpp
parent8cff305dff774d10d5ae895a26bb6fc3b7cd48d9 (diff)
downloadbcm5719-llvm-0f0883b918260f5c7d1f191f58cd4f68f62f2b55.tar.gz
bcm5719-llvm-0f0883b918260f5c7d1f191f58cd4f68f62f2b55.zip
Fix an algorithmic bug in LiveVariables pointed out by Zhongxing.
If an initializer in a DeclStmt references the declared variable, that extends the liveness of that variable. llvm-svn: 97624
Diffstat (limited to 'clang/lib/Analysis/LiveVariables.cpp')
-rw-r--r--clang/lib/Analysis/LiveVariables.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/clang/lib/Analysis/LiveVariables.cpp b/clang/lib/Analysis/LiveVariables.cpp
index c636a43bc50..01a36a1074e 100644
--- a/clang/lib/Analysis/LiveVariables.cpp
+++ b/clang/lib/Analysis/LiveVariables.cpp
@@ -280,9 +280,16 @@ void TransferFuncs::VisitDeclStmt(DeclStmt* DS) {
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.
+ // Update liveness information by killing the VarDecl.
+ unsigned bit = AD.getIdx(VD);
+ LiveState.getDeclBit(bit) = Dead | AD.AlwaysLive.getDeclBit(bit);
+
+ // The initializer is evaluated after the variable comes into scope, but
+ // before the DeclStmt (which binds the value to the variable).
// Since this is a reverse dataflow analysis, we must evaluate the
- // transfer function for this expression first.
+ // transfer function for this expression after the DeclStmt. If the
+ // initializer references the variable (which is bad) then we extend
+ // its liveness.
if (Expr* Init = VD->getInit())
Visit(Init);
@@ -292,10 +299,6 @@ void TransferFuncs::VisitDeclStmt(DeclStmt* DS) {
StmtIterator E;
for (; I != E; ++I) Visit(*I);
}
-
- // Update liveness information by killing the VarDecl.
- unsigned bit = AD.getIdx(VD);
- LiveState.getDeclBit(bit) = Dead | AD.AlwaysLive.getDeclBit(bit);
}
}
OpenPOWER on IntegriCloud