[llvm-commits] [llvm] r52137 - in /llvm/trunk: lib/Transforms/IPO/IPConstantPropagation.cpp test/Transforms/IPConstantProp/2008-06-09-WeakProp.ll
Chris Lattner
sabre at nondot.org
Mon Jun 9 00:58:08 PDT 2008
Author: lattner
Date: Mon Jun 9 02:58:07 2008
New Revision: 52137
URL: http://llvm.org/viewvc/llvm-project?rev=52137&view=rev
Log:
Fix PR2411, where ip constant prop would propagate the
result of a weak function.
Added:
llvm/trunk/test/Transforms/IPConstantProp/2008-06-09-WeakProp.ll
Modified:
llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp
Modified: llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp?rev=52137&r1=52136&r2=52137&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/IPConstantPropagation.cpp Mon Jun 9 02:58:07 2008
@@ -147,6 +147,11 @@
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<Value *,4> RetVals;
const StructType *STy = dyn_cast<StructType>(F.getReturnType());
Added: llvm/trunk/test/Transforms/IPConstantProp/2008-06-09-WeakProp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IPConstantProp/2008-06-09-WeakProp.ll?rev=52137&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/IPConstantProp/2008-06-09-WeakProp.ll (added)
+++ llvm/trunk/test/Transforms/IPConstantProp/2008-06-09-WeakProp.ll Mon Jun 9 02:58:07 2008
@@ -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
+}
+
More information about the llvm-commits
mailing list