aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-07-19 08:23:12 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-07-19 08:23:12 +0000
commitcd5e60e1d4093b9a757cc85e35fccc093f8f8527 (patch)
tree73100569c8330f683e2bc709e6db33572bf1e9d6 /lib/CodeGen
parent25b6ebf0f8c07514250ec76c987f84b6810d4d17 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76364 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGStmt.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index 4e6ec82eb5..04b26ea80a 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -68,10 +68,19 @@ void CodeGenFunction::EmitStmt(const Stmt *S) {
default:
// Must be an expression in a stmt context. Emit the value (to get
// side-effects) and ignore the result.
- if (const Expr *E = dyn_cast<Expr>(S)) {
- EmitAnyExpr(E, 0, false, true);
- } else {
+ if (!isa<Expr>(S))
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;
case Stmt::IndirectGotoStmtClass: