Fix horrible CFG bug caused by a series of NullStmts appearing at the beginning of a do...while loop. This would cause

the body of the DoStmt to be disconnected from the preceding code.

llvm-svn: 111283
This commit is contained in:
Ted Kremenek 2010-08-17 21:00:06 +00:00
parent 110974dfa4
commit 4f2ab5a549
2 changed files with 28 additions and 1 deletions

View File

@ -702,7 +702,10 @@ CFGBlock* CFGBuilder::VisitCompoundStmt(CompoundStmt* C) {
for (CompoundStmt::reverse_body_iterator I=C->body_rbegin(), E=C->body_rend();
I != E; ++I ) {
LastBlock = addStmt(*I);
// If we hit a segment of code just containing ';' (NullStmts), we can
// get a null block back. In such cases, just use the LastBlock
if (CFGBlock *newBlock = addStmt(*I))
LastBlock = newBlock;
if (badCFG)
return NULL;

View File

@ -462,3 +462,27 @@ void rdar8014335() {
}
}
// <rdar://problem/8320674> NullStmts followed by do...while() can lead to disconnected CFG
//
// This previously caused bogus dead-stores warnings because the body of the first do...while was
// disconnected from the entry of the function.
typedef struct { float r; float i; } s_rdar8320674;
typedef struct { s_rdar8320674 x[1]; } s2_rdar8320674;
void rdar8320674(s_rdar8320674 *z, unsigned y, s2_rdar8320674 *st, int m)
{
s_rdar8320674 * z2;
s_rdar8320674 * tw1 = st->x;
s_rdar8320674 t;
z2 = z + m;
do{
; ;
do{ (t).r = (*z2).r*(*tw1).r - (*z2).i*(*tw1).i; (t).i = (*z2).r*(*tw1).i + (*z2).i*(*tw1).r; }while(0);
tw1 += y;
do { (*z2).r=(*z).r-(t).r; (*z2).i=(*z).i-(t).i; }while(0);
do { (*z).r += (t).r; (*z).i += (t).i; }while(0);
++z2;
++z;
}while (--m);
}