diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index 5b7629852ee..a8308b80a96 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -2288,9 +2288,11 @@ X86TargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, // Don't tail call optimize recursive call. GlobalAddressSDNode *G = dyn_cast(Callee); if (!G) return false; // FIXME: common external symbols? - const Function *CalleeF = cast(G->getGlobal()); - const Type *CalleeRetTy = CalleeF->getReturnType(); - return CallerRetTy == CalleeRetTy; + if (const Function *CalleeF = dyn_cast(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 index 00000000000..275117483d6 --- /dev/null +++ b/test/CodeGen/X86/2010-02-01-TaillCallCrash.ll @@ -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 ; [#uses=1] + ret i32 %0 +}