[cfe-commits] r56645 - in /cfe/trunk: lib/Analysis/LiveVariables.cpp test/Analysis/dead-stores.c
Ted Kremenek
kremenek at apple.com
Thu Sep 25 22:52:45 PDT 2008
Author: kremenek
Date: Fri Sep 26 00:52:45 2008
New Revision: 56645
URL: http://llvm.org/viewvc/llvm-project?rev=56645&view=rev
Log:
Examine VLA size expressions when computing liveness information.
Fixes <rdar://problem/6248086>
Modified:
cfe/trunk/lib/Analysis/LiveVariables.cpp
cfe/trunk/test/Analysis/dead-stores.c
Modified: cfe/trunk/lib/Analysis/LiveVariables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/LiveVariables.cpp?rev=56645&r1=56644&r2=56645&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/LiveVariables.cpp (original)
+++ cfe/trunk/lib/Analysis/LiveVariables.cpp Fri Sep 26 00:52:45 2008
@@ -226,19 +226,41 @@
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());
+
}
}
Modified: cfe/trunk/test/Analysis/dead-stores.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dead-stores.c?rev=56645&r1=56644&r2=56645&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/dead-stores.c (original)
+++ cfe/trunk/test/Analysis/dead-stores.c Fri Sep 26 00:52:45 2008
@@ -100,7 +100,7 @@
}
// Filed with PR 2763.
-int f41(int count) {
+int f14(int count) {
int index, nextLineIndex;
for (index = 0; index < count; index = nextLineIndex+1) {
nextLineIndex = index+1; // no-warning
@@ -108,3 +108,10 @@
}
return index;
}
+
+// Test case for <rdar://problem/6248086>
+void f15(unsigned x, unsigned y) {
+ int count = x * y; // no-warning
+ int z[count];
+}
+
More information about the cfe-commits
mailing list