forked from OSchip/llvm-project
Detect when the current generation point is unreachable after emitting
expressions. - This generally catches the important case of noreturn functions. - With the last two changes, we are down to 152 unreachable blocks emitted on 403.gcc, vs the 1805 we started with. llvm-svn: 76364
This commit is contained in:
parent
68602758e4
commit
c3ab4c6c98
|
@ -68,10 +68,19 @@ void CodeGenFunction::EmitStmt(const Stmt *S) {
|
||||||
default:
|
default:
|
||||||
// Must be an expression in a stmt context. Emit the value (to get
|
// Must be an expression in a stmt context. Emit the value (to get
|
||||||
// side-effects) and ignore the result.
|
// side-effects) and ignore the result.
|
||||||
if (const Expr *E = dyn_cast<Expr>(S)) {
|
if (!isa<Expr>(S))
|
||||||
EmitAnyExpr(E, 0, false, true);
|
|
||||||
} else {
|
|
||||||
ErrorUnsupported(S, "statement");
|
ErrorUnsupported(S, "statement");
|
||||||
|
|
||||||
|
EmitAnyExpr(cast<Expr>(S), 0, false, true);
|
||||||
|
|
||||||
|
// Expression emitters don't handle unreachable blocks yet, so look for one
|
||||||
|
// explicitly here. This handles the common case of a call to a noreturn
|
||||||
|
// function.
|
||||||
|
if (llvm::BasicBlock *CurBB = Builder.GetInsertBlock()) {
|
||||||
|
if (CurBB->empty() && CurBB->use_empty()) {
|
||||||
|
CurBB->eraseFromParent();
|
||||||
|
Builder.ClearInsertionPoint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Stmt::IndirectGotoStmtClass:
|
case Stmt::IndirectGotoStmtClass:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// RUN: clang-cc -emit-llvm -o %t %s &&
|
// RUN: clang-cc -emit-llvm -o %t %s &&
|
||||||
// RUN: grep '@unreachable' %t | count 0
|
// RUN: grep '@unreachable' %t | count 0
|
||||||
|
|
||||||
|
extern void abort() __attribute__((noreturn));
|
||||||
extern int unreachable();
|
extern int unreachable();
|
||||||
|
|
||||||
int f0() {
|
int f0() {
|
||||||
|
@ -24,3 +25,13 @@ int f2(int i) {
|
||||||
a = i + 1;
|
a = i + 1;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int f3(int i) {
|
||||||
|
if (i) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
unreachable();
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue