[cfe-commits] r76364 - in /cfe/trunk: lib/CodeGen/CGStmt.cpp test/CodeGen/unreachable.c
Daniel Dunbar
daniel at zuster.org
Sun Jul 19 01:23:12 PDT 2009
Author: ddunbar
Date: Sun Jul 19 03:23:12 2009
New Revision: 76364
URL: http://llvm.org/viewvc/llvm-project?rev=76364&view=rev
Log:
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.
Modified:
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/test/CodeGen/unreachable.c
Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=76364&r1=76363&r2=76364&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Sun Jul 19 03:23:12 2009
@@ -68,10 +68,19 @@
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:
Modified: cfe/trunk/test/CodeGen/unreachable.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/unreachable.c?rev=76364&r1=76363&r2=76364&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/unreachable.c (original)
+++ cfe/trunk/test/CodeGen/unreachable.c Sun Jul 19 03:23:12 2009
@@ -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 @@
a = i + 1;
return a;
}
+
+int f3(int i) {
+ if (i) {
+ return 0;
+ } else {
+ abort();
+ }
+ unreachable();
+ return 3;
+}
More information about the cfe-commits
mailing list