InstCombine: Fix a crasher when encountering a function pointer.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 18 Aug 2012 22:04:34 +0000 (22:04 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 18 Aug 2012 22:04:34 +0000 (22:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162180 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/fcmp.ll

index c43fb71c2ddfb17f403e4845aed1f5765a4b9037..c3fc18c30064fd48b12e23b29a4aff65d2ef0bb7 100644 (file)
@@ -2990,7 +2990,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
         CallInst *CI = cast<CallInst>(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 ||
index 82fef484a02014e7f2f56b64b7afb00d41816005..fc1ced052a38fc47620d91b822e2a134577cc2dd 100644 (file)
@@ -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
+}