From 18d73c206e8259de61abf54d8d0f47c0e54f42aa Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 9 Jun 2008 07:58:07 +0000 Subject: [PATCH] Fix PR2411, where ip constant prop would propagate the result of a weak function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52137 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/IPConstantPropagation.cpp | 5 +++++ .../IPConstantProp/2008-06-09-WeakProp.ll | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/Transforms/IPConstantProp/2008-06-09-WeakProp.ll diff --git a/lib/Transforms/IPO/IPConstantPropagation.cpp b/lib/Transforms/IPO/IPConstantPropagation.cpp index 792fa980a60..4ebdaf3fb2b 100644 --- a/lib/Transforms/IPO/IPConstantPropagation.cpp +++ b/lib/Transforms/IPO/IPConstantPropagation.cpp @@ -147,6 +147,11 @@ bool IPCP::PropagateConstantReturn(Function &F) { if (F.getReturnType() == Type::VoidTy) return false; // No return value. + // If this function could be overridden later in the link stage, we can't + // propagate information about its results into callers. + if (F.hasLinkOnceLinkage() || F.hasWeakLinkage()) + return false; + // Check to see if this function returns a constant. SmallVector RetVals; const StructType *STy = dyn_cast(F.getReturnType()); diff --git a/test/Transforms/IPConstantProp/2008-06-09-WeakProp.ll b/test/Transforms/IPConstantProp/2008-06-09-WeakProp.ll new file mode 100644 index 00000000000..fc7e3bba38a --- /dev/null +++ b/test/Transforms/IPConstantProp/2008-06-09-WeakProp.ll @@ -0,0 +1,15 @@ +; RUN: llvm-as < %s | opt -ipconstprop | llvm-dis | grep {ret i32 %r} +; Should not propagate the result of a weak function. +; PR2411 + +define weak i32 @foo() nounwind { +entry: + ret i32 1 +} + +define i32 @main() nounwind { +entry: + %r = call i32 @foo( ) nounwind + ret i32 %r +} +