Fix PR6196. GV callee may not be a function.
authorEvan Cheng <evan.cheng@apple.com>
Mon, 1 Feb 2010 22:40:09 +0000 (22:40 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Mon, 1 Feb 2010 22:40:09 +0000 (22:40 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95017 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/2010-02-01-TaillCallCrash.ll [new file with mode: 0644]

index 5b7629852ee8b3e14a1ced94f8ca0116b91220ff..a8308b80a96dda81cbd3041d5f10ecccabe08be5 100644 (file)
@@ -2288,9 +2288,11 @@ X86TargetLowering::IsEligibleForTailCallOptimization(SDValue Callee,
   // Don't tail call optimize recursive call.
   GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);
   if (!G) return false;  // FIXME: common external symbols?
-  const Function *CalleeF = cast<Function>(G->getGlobal());
-  const Type *CalleeRetTy = CalleeF->getReturnType();
-  return CallerRetTy == CalleeRetTy;
+  if (const Function *CalleeF = dyn_cast<Function>(G->getGlobal())) {
+    const Type *CalleeRetTy = CalleeF->getReturnType();
+    return CallerRetTy == CalleeRetTy;
+  }
+  return false;
 }
 
 FastISel *
diff --git a/test/CodeGen/X86/2010-02-01-TaillCallCrash.ll b/test/CodeGen/X86/2010-02-01-TaillCallCrash.ll
new file mode 100644 (file)
index 0000000..2751174
--- /dev/null
@@ -0,0 +1,12 @@
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu
+; PR6196
+
+%"char[]" = type [1 x i8]
+
+@.str = external constant %"char[]", align 1      ; <%"char[]"*> [#uses=1]
+
+define i32 @regex_subst() nounwind {
+entry:
+  %0 = tail call i32 bitcast (%"char[]"* @.str to i32 (i32)*)(i32 0) nounwind ; <i32> [#uses=1]
+  ret i32 %0
+}