[cfe-commits] r41617 - /cfe/trunk/AST/CFG.cpp
Ted Kremenek
kremenek at apple.com
Thu Aug 30 11:13:31 PDT 2007
Author: kremenek
Date: Thu Aug 30 13:13:31 2007
New Revision: 41617
URL: http://llvm.org/viewvc/llvm-project?rev=41617&view=rev
Log:
Fixed bug where the CFG would fail to build when an 'if' statement had
an empty then or else block (or contained only ';' statements).
For example, we now handle the following:
int empty_else() { if (0) { int a; } else ; }
int empty_then() { if (0) ; else { int a; } }
Thanks to Nico Weber for spotting this problem.
Modified:
cfe/trunk/AST/CFG.cpp
Modified: cfe/trunk/AST/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/CFG.cpp?rev=41617&r1=41616&r2=41617&view=diff
==============================================================================
--- cfe/trunk/AST/CFG.cpp (original)
+++ cfe/trunk/AST/CFG.cpp Thu Aug 30 13:13:31 2007
@@ -34,7 +34,8 @@
struct SaveAndRestore {
SaveAndRestore(T& x) : X(x), old_value(x) {}
~SaveAndRestore() { X = old_value; }
-
+ T get() { return old_value; }
+
T& X;
T old_value;
};
@@ -396,9 +397,12 @@
// NULL out Block so that the recursive call to Visit will
// create a new basic block.
Block = NULL;
- ElseBlock = Visit(Else);
- if (!ElseBlock) return NULL;
- if (Block) FinishBlock(ElseBlock);
+ ElseBlock = Visit(Else);
+
+ if (!ElseBlock) // Can occur when the Else body has all NullStmts.
+ ElseBlock = sv.get();
+ else if (Block)
+ FinishBlock(ElseBlock);
}
// Process the true branch. NULL out Block so that the recursive
@@ -410,9 +414,12 @@
assert (Then);
SaveAndRestore<CFGBlock*> sv(Succ);
Block = NULL;
- ThenBlock = Visit(Then);
- if (!ThenBlock) return NULL;
- if (Block) FinishBlock(ThenBlock);
+ ThenBlock = Visit(Then);
+
+ if (!ThenBlock) // Can occur when the Then body has all NullStmts.
+ ThenBlock = sv.get();
+ else if (Block)
+ FinishBlock(ThenBlock);
}
// Now create a new block containing the if statement.
More information about the cfe-commits
mailing list