From a4b5717ea7ea09afeb5cda2683f6e91a802f5906 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sat, 18 Aug 2012 22:04:34 +0000 Subject: [PATCH] InstCombine: Fix a crasher when encountering a function pointer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162180 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/InstCombine/InstCombineCompares.cpp | 2 +- test/Transforms/InstCombine/fcmp.ll | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index c43fb71c2dd..c3fc18c3006 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2990,7 +2990,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) { CallInst *CI = cast(LHSI); LibFunc::Func Func; // Various optimization for fabs compared with zero. - if (RHSC->isNullValue() && + if (RHSC->isNullValue() && CI->getCalledFunction() && TLI->getLibFunc(CI->getCalledFunction()->getName(), Func) && TLI->has(Func)) { if (Func == LibFunc::fabs || Func == LibFunc::fabsf || diff --git a/test/Transforms/InstCombine/fcmp.ll b/test/Transforms/InstCombine/fcmp.ll index 82fef484a02..fc1ced052a3 100644 --- a/test/Transforms/InstCombine/fcmp.ll +++ b/test/Transforms/InstCombine/fcmp.ll @@ -151,3 +151,11 @@ define i32 @test16(double %a) nounwind { ; CHECK-NOT: fabs ; CHECK: fcmp ueq double %a, 0.000000e+00 } + +; Don't crash. +define i32 @test17(double %a, double (double)* %p) nounwind { + %call = tail call double %p(double %a) nounwind + %cmp = fcmp ueq double %call, 0.000000e+00 + %conv = zext i1 %cmp to i32 + ret i32 %conv +} -- 2.34.1