[cfe-commits] r97624 - /cfe/trunk/lib/Analysis/LiveVariables.cpp
Ted Kremenek
kremenek at apple.com
Tue Mar 2 17:17:42 PST 2010
Author: kremenek
Date: Tue Mar 2 19:17:41 2010
New Revision: 97624
URL: http://llvm.org/viewvc/llvm-project?rev=97624&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Analysis/LiveVariables.cpp
Modified: cfe/trunk/lib/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/LiveVariables.cpp?rev=97624&r1=97623&r2=97624&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Tue Mar 2 19:17:41 2010
@@ -280,9 +280,16 @@
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 @@
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);
}
}
More information about the cfe-commits
mailing list