llvm.org GIT mirror llvm / 107f41f
Fix SimplifyLibcalls and ValueTracking to check mayBeOverridden before performing optimizations based on constant string values. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79384 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
3 changed file(s) with 30 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
10601060 // variable that is a constant and is initialized. The referenced constant
10611061 // initializer is the array that we'll use for optimization.
10621062 GlobalVariable* GV = dyn_cast(V);
1063 if (!GV || !GV->isConstant() || !GV->hasInitializer())
1063 if (!GV || !GV->isConstant() || !GV->hasInitializer() ||
1064 GV->mayBeOverridden())
10641065 return false;
10651066 Constant *GlobalInit = GV->getInitializer();
10661067
437437 // variable that is a constant and is initialized. The referenced constant
438438 // initializer is the array that we'll use for optimization.
439439 GlobalVariable* GV = dyn_cast(GEP->getOperand(0));
440 if (!GV || !GV->isConstant() || !GV->hasInitializer())
440 if (!GV || !GV->isConstant() || !GV->hasInitializer() ||
441 GV->mayBeOverridden())
441442 return 0;
442443 Constant *GlobalInit = GV->getInitializer();
443444
0 ; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | FileCheck %s
1 ; PR4738
2
3 ; SimplifyLibcalls shouldn't assume anything about weak symbols.
4
5 @real_init = weak_odr constant [2 x i8] c"y\00"
6 @fake_init = weak constant [2 x i8] c"y\00"
7 @.str = private constant [2 x i8] c"y\00"
8
9 ; CHECK: define i32 @foo
10 ; CHECK: call i32 @strcmp
11 define i32 @foo() nounwind {
12 entry:
13 %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
14 ret i32 %t0
15 }
16
17 ; CHECK: define i32 @bar
18 ; CHECK: ret i32 0
19 define i32 @bar() nounwind {
20 entry:
21 %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
22 ret i32 %t0
23 }
24
25 declare i32 @strcmp(i8*, i8*) nounwind readonly