diff options
author | Dan Gohman <gohman@apple.com> | 2009-08-19 00:11:12 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2009-08-19 00:11:12 +0000 |
commit | dea2358c684926e11dc550f536b4f21b18af9dfb (patch) | |
tree | 5638039d99dc823fa8c35afd36a8d9f2edf17c01 /llvm | |
parent | 2fa67c9f70597ee5537e62301a1e1a4937e53550 (diff) | |
download | bcm5719-llvm-dea2358c684926e11dc550f536b4f21b18af9dfb.tar.gz bcm5719-llvm-dea2358c684926e11dc550f536b4f21b18af9dfb.zip |
Fix SimplifyLibcalls and ValueTracking to check mayBeOverridden
before performing optimizations based on constant string values.
llvm-svn: 79384
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp | 3 | ||||
-rw-r--r-- | llvm/test/Transforms/SimplifyLibCalls/weak-symbols.ll | 26 |
3 files changed, 30 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 604d10c68b9..3ab10c55d81 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1061,7 +1061,8 @@ bool llvm::GetConstantStringInfo(Value *V, std::string &Str, uint64_t Offset, // variable that is a constant and is initialized. The referenced constant // initializer is the array that we'll use for optimization. GlobalVariable* GV = dyn_cast<GlobalVariable>(V); - if (!GV || !GV->isConstant() || !GV->hasInitializer()) + if (!GV || !GV->isConstant() || !GV->hasInitializer() || + GV->mayBeOverridden()) return false; Constant *GlobalInit = GV->getInitializer(); diff --git a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp index 02b26bdac2b..761c309c200 100644 --- a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp @@ -438,7 +438,8 @@ static uint64_t GetStringLengthH(Value *V, SmallPtrSet<PHINode*, 32> &PHIs) { // variable that is a constant and is initialized. The referenced constant // initializer is the array that we'll use for optimization. GlobalVariable* GV = dyn_cast<GlobalVariable>(GEP->getOperand(0)); - if (!GV || !GV->isConstant() || !GV->hasInitializer()) + if (!GV || !GV->isConstant() || !GV->hasInitializer() || + GV->mayBeOverridden()) return 0; Constant *GlobalInit = GV->getInitializer(); diff --git a/llvm/test/Transforms/SimplifyLibCalls/weak-symbols.ll b/llvm/test/Transforms/SimplifyLibCalls/weak-symbols.ll new file mode 100644 index 00000000000..970ee0ddf12 --- /dev/null +++ b/llvm/test/Transforms/SimplifyLibCalls/weak-symbols.ll @@ -0,0 +1,26 @@ +; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | FileCheck %s +; PR4738 + +; SimplifyLibcalls shouldn't assume anything about weak symbols. + +@real_init = weak_odr constant [2 x i8] c"y\00" +@fake_init = weak constant [2 x i8] c"y\00" +@.str = private constant [2 x i8] c"y\00" + +; CHECK: define i32 @foo +; CHECK: call i32 @strcmp +define i32 @foo() nounwind { +entry: + %t0 = call i32 @strcmp(i8* getelementptr inbounds ([2 x i8]* @fake_init, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8]* @.str, i64 0, i64 0)) nounwind readonly + ret i32 %t0 +} + +; CHECK: define i32 @bar +; CHECK: ret i32 0 +define i32 @bar() nounwind { +entry: + %t0 = call i32 @strcmp(i8* getelementptr inbounds ([2 x i8]* @real_init, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8]* @.str, i64 0, i64 0)) nounwind readonly + ret i32 %t0 +} + +declare i32 @strcmp(i8*, i8*) nounwind readonly |