mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-10 04:33:40 +00:00
"@string = constant i8 0" is a value i8* string of length zero. Analyze that
correctly in GetStringLength, fixing PR11181! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@142558 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6690bca623
commit
0cd0fee91e
@ -1525,8 +1525,7 @@ Value *llvm::GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset,
|
|||||||
/// null-terminated C string pointed to by V. If successful, it returns true
|
/// null-terminated C string pointed to by V. If successful, it returns true
|
||||||
/// and returns the string in Str. If unsuccessful, it returns false.
|
/// and returns the string in Str. If unsuccessful, it returns false.
|
||||||
bool llvm::GetConstantStringInfo(const Value *V, std::string &Str,
|
bool llvm::GetConstantStringInfo(const Value *V, std::string &Str,
|
||||||
uint64_t Offset,
|
uint64_t Offset, bool StopAtNul) {
|
||||||
bool StopAtNul) {
|
|
||||||
// If V is NULL then return false;
|
// If V is NULL then return false;
|
||||||
if (V == NULL) return false;
|
if (V == NULL) return false;
|
||||||
|
|
||||||
@ -1536,7 +1535,7 @@ bool llvm::GetConstantStringInfo(const Value *V, std::string &Str,
|
|||||||
|
|
||||||
// If the value is not a GEP instruction nor a constant expression with a
|
// If the value is not a GEP instruction nor a constant expression with a
|
||||||
// GEP instruction, then return false because ConstantArray can't occur
|
// GEP instruction, then return false because ConstantArray can't occur
|
||||||
// any other way
|
// any other way.
|
||||||
const User *GEP = 0;
|
const User *GEP = 0;
|
||||||
if (const GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(V)) {
|
if (const GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(V)) {
|
||||||
GEP = GEPI;
|
GEP = GEPI;
|
||||||
@ -1585,8 +1584,8 @@ bool llvm::GetConstantStringInfo(const Value *V, std::string &Str,
|
|||||||
return false;
|
return false;
|
||||||
const Constant *GlobalInit = GV->getInitializer();
|
const Constant *GlobalInit = GV->getInitializer();
|
||||||
|
|
||||||
// Handle the ConstantAggregateZero case
|
// Handle the all-zeros case
|
||||||
if (isa<ConstantAggregateZero>(GlobalInit)) {
|
if (GlobalInit->isNullValue()) {
|
||||||
// This is a degenerate case. The initializer is constant zero so the
|
// This is a degenerate case. The initializer is constant zero so the
|
||||||
// length of the string must be zero.
|
// length of the string must be zero.
|
||||||
Str.clear();
|
Str.clear();
|
||||||
@ -1667,6 +1666,14 @@ static uint64_t GetStringLengthH(Value *V, SmallPtrSet<PHINode*, 32> &PHIs) {
|
|||||||
return Len1;
|
return Len1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// As a special-case, "@string = constant i8 0" is also a string with zero
|
||||||
|
// length, not wrapped in a bitcast or GEP.
|
||||||
|
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
|
||||||
|
if (GV->isConstant() && GV->hasDefinitiveInitializer())
|
||||||
|
if (GV->getInitializer()->isNullValue()) return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// If the value is not a GEP instruction nor a constant expression with a
|
// If the value is not a GEP instruction nor a constant expression with a
|
||||||
// GEP instruction, then return unknown.
|
// GEP instruction, then return unknown.
|
||||||
User *GEP = 0;
|
User *GEP = 0;
|
||||||
|
@ -6,6 +6,7 @@ target datalayout = "e-p:32:32"
|
|||||||
@hello = constant [6 x i8] c"hello\00" ; <[6 x i8]*> [#uses=3]
|
@hello = constant [6 x i8] c"hello\00" ; <[6 x i8]*> [#uses=3]
|
||||||
@null = constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=3]
|
@null = constant [1 x i8] zeroinitializer ; <[1 x i8]*> [#uses=3]
|
||||||
@null_hello = constant [7 x i8] c"\00hello\00" ; <[7 x i8]*> [#uses=1]
|
@null_hello = constant [7 x i8] c"\00hello\00" ; <[7 x i8]*> [#uses=1]
|
||||||
|
@nullstring = constant i8 0
|
||||||
|
|
||||||
declare i32 @strlen(i8*)
|
declare i32 @strlen(i8*)
|
||||||
|
|
||||||
@ -54,3 +55,8 @@ define i1 @test7() {
|
|||||||
%ne_null = icmp ne i32 %null_l, 0 ; <i1> [#uses=1]
|
%ne_null = icmp ne i32 %null_l, 0 ; <i1> [#uses=1]
|
||||||
ret i1 %ne_null
|
ret i1 %ne_null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
define i32 @test8() {
|
||||||
|
%len = tail call i32 @strlen(i8* @nullstring) nounwind
|
||||||
|
ret i32 %len
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user