aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGCall.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-02-20 18:54:31 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-02-20 18:54:31 +0000
commitf4fe0f082f21048c0777ad5aeac04a5a94db1f46 (patch)
treeb4569abeece8094f45c8c4eeca5ee62757e66946 /lib/CodeGen/CGCall.cpp
parent540b146d013b3b6d5ab7c485b9e692a866173e15 (diff)
Take advantage of noreturn attribute to add unreachable instruction &
clear insertion point. The rest of IRgen should theoretically take advantage of this to avoid emitting dead code. Theory != Practice. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65141 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGCall.cpp')
-rw-r--r--lib/CodeGen/CGCall.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index d0122fa4f9..02e00558d8 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -1760,6 +1760,18 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
if (const llvm::Function *F = dyn_cast<llvm::Function>(Callee))
CI->setCallingConv(F->getCallingConv());
+
+ // If the call doesn't return, finish the basic block and clear the
+ // insertion point; this allows the rest of IRgen to discard
+ // unreachable code.
+ if (CI->doesNotReturn()) {
+ Builder.CreateUnreachable();
+ Builder.ClearInsertionPoint();
+
+ // Return a reasonable RValue.
+ return GetUndefRValue(RetTy);
+ }
+
if (CI->getType() != llvm::Type::VoidTy)
CI->setName("call");