aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/CodeGen/CGStmt.cpp15
-rw-r--r--test/CodeGen/unreachable.c11
2 files changed, 23 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:
diff --git a/test/CodeGen/unreachable.c b/test/CodeGen/unreachable.c
index ab029b613d..ea4f0478bb 100644
--- a/test/CodeGen/unreachable.c
+++ b/test/CodeGen/unreachable.c
@@ -1,6 +1,7 @@
// RUN: clang-cc -emit-llvm -o %t %s &&
// RUN: grep '@unreachable' %t | count 0
+extern void abort() __attribute__((noreturn));
extern int unreachable();
int f0() {
@@ -24,3 +25,13 @@ int f2(int i) {
a = i + 1;
return a;
}
+
+int f3(int i) {
+ if (i) {
+ return 0;
+ } else {
+ abort();
+ }
+ unreachable();
+ return 3;
+}