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.

llvm-svn: 41617
This commit is contained in:
Ted Kremenek 2007-08-30 18:13:31 +00:00
parent 90dfdd5774
commit bbad8ce2e7
1 changed files with 14 additions and 7 deletions

View File

@ -34,6 +34,7 @@ template<typename T>
struct SaveAndRestore {
SaveAndRestore(T& x) : X(x), old_value(x) {}
~SaveAndRestore() { X = old_value; }
T get() { return old_value; }
T& X;
T old_value;
@ -397,8 +398,11 @@ CFGBlock* CFGBuilder::VisitIfStmt(IfStmt* I) {
// create a new basic block.
Block = NULL;
ElseBlock = Visit(Else);
if (!ElseBlock) return NULL;
if (Block) FinishBlock(ElseBlock);
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
@ -411,8 +415,11 @@ CFGBlock* CFGBuilder::VisitIfStmt(IfStmt* I) {
SaveAndRestore<CFGBlock*> sv(Succ);
Block = NULL;
ThenBlock = Visit(Then);
if (!ThenBlock) return NULL;
if (Block) FinishBlock(ThenBlock);
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.