From 401b67d4eb0bed5dd9aa007f0a8241060cabb680 Mon Sep 17 00:00:00 2001 From: Davide Italiano Date: Sun, 29 Nov 2015 21:58:56 +0000 Subject: [PATCH] [SimplifyLibCalls] Don't crash if the function doesn't have a name. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254265 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Utils/SimplifyLibCalls.cpp | 5 ++--- test/Transforms/InstCombine/log-pow.ll | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp index e7eb39d6312..47e587fab7b 100644 --- a/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -1317,9 +1317,8 @@ Value *LibCallSimplifier::optimizeLog(CallInst *CI, IRBuilder<> &B) { LibFunc::Func Func; Function *F = OpC->getCalledFunction(); - StringRef FuncName = F->getName(); - if ((TLI->getLibFunc(FuncName, Func) && TLI->has(Func) && - Func == LibFunc::pow) || F->getIntrinsicID() == Intrinsic::pow) + if (F && ((TLI->getLibFunc(F->getName(), Func) && TLI->has(Func) && + Func == LibFunc::pow) || F->getIntrinsicID() == Intrinsic::pow)) return B.CreateFMul(OpC->getArgOperand(1), EmitUnaryFloatFnCall(OpC->getOperand(0), Callee->getName(), B, Callee->getAttributes()), "mul"); diff --git a/test/Transforms/InstCombine/log-pow.ll b/test/Transforms/InstCombine/log-pow.ll index 2cafccabf0a..c98a1a5bc62 100644 --- a/test/Transforms/InstCombine/log-pow.ll +++ b/test/Transforms/InstCombine/log-pow.ll @@ -13,6 +13,15 @@ entry: ; CHECK: ret double %mul ; CHECK: } +define double @test2(double ()* %fptr, double %p1) #0 { + %call1 = call double %fptr() + %pow = call double @log(double %call1) + ret double %pow +} + +; CHECK-LABEL: @test2 +; CHECK: log + declare double @log(double) #0 declare double @llvm.pow.f64(double, double) -- 2.34.1