From e52646cd802fa38471bfed3740ab3377d9da0687 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Fri, 1 Aug 2014 23:21:21 +0000 Subject: [PATCH] PartiallyInlineLibCalls: Check sqrt result type before transforming it. Some configure scripts declare this with the wrong prototype, which can lead to an assertion failure. llvm-svn: 214593 --- llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp | 4 ++++ .../Transforms/PartiallyInlineLibCalls/bad-prototype.ll | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 llvm/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll diff --git a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp index 7cce89e..5c8bed5 100644 --- a/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp +++ b/llvm/lib/Transforms/Scalar/PartiallyInlineLibCalls.cpp @@ -108,6 +108,10 @@ bool PartiallyInlineLibCalls::optimizeSQRT(CallInst *Call, if (Call->onlyReadsMemory()) return false; + // The call must have the expected result type. + if (!Call->getType()->isFloatingPointTy()) + return false; + // Do the following transformation: // // (before) diff --git a/llvm/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll b/llvm/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll new file mode 100644 index 0000000..34cd672 --- /dev/null +++ b/llvm/test/Transforms/PartiallyInlineLibCalls/bad-prototype.ll @@ -0,0 +1,13 @@ +; RUN: opt -S -partially-inline-libcalls < %s | FileCheck %s + +target triple = "x86_64-unknown-linux-gnu" + +declare i32 @sqrt() + +; CHECK-LABEL: @foo +define i32 @foo() { + ; CHECK: call{{.*}}@sqrt + ; CHECK-NOT: call{{.*}}@sqrt + %r = call i32 @sqrt() + ret i32 %r +} -- 2.7.4