Do not mark no-return calls tail calls. It'll screw up special calls like longjmp...
authorEvan Cheng <evan.cheng@apple.com>
Sun, 31 Jan 2010 00:59:31 +0000 (00:59 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Sun, 31 Jan 2010 00:59:31 +0000 (00:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94937 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/TailRecursionElimination.cpp
test/Transforms/TailCallElim/no-return-calls.ll [new file with mode: 0644]

index 162d902cfa4cb61ca502772b702bff550d941d44..913dd73cc17f1bc16ed537a256a9345701264013 100644 (file)
@@ -184,10 +184,11 @@ bool TailCallElim::runOnFunction(Function &F) {
   if (!FunctionContainsEscapingAllocas)
     for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
       for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
-        if (CallInst *CI = dyn_cast<CallInst>(I)) {
-          CI->setTailCall();
-          MadeChange = true;
-        }
+        if (CallInst *CI = dyn_cast<CallInst>(I))
+          if (!CI->doesNotReturn()) {
+            CI->setTailCall();
+            MadeChange = true;
+          }
 
   return MadeChange;
 }
diff --git a/test/Transforms/TailCallElim/no-return-calls.ll b/test/Transforms/TailCallElim/no-return-calls.ll
new file mode 100644 (file)
index 0000000..f5643ae
--- /dev/null
@@ -0,0 +1,12 @@
+; RUN: opt < %s -tailcallelim -S | FileCheck %s
+
+define void @t() nounwind ssp {
+entry:
+; CHECK: entry:
+; CHECK: %0 = call i32 @foo()
+; CHECK: ret void
+  %0 = call i32 @foo() nounwind noreturn
+  ret void
+}
+
+declare i32 @foo()