various cleanups suggested by Duncan

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84993 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2009-10-24 05:27:19 +00:00
parent c5af649758
commit c7b1382e35

View File

@@ -103,6 +103,8 @@ static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset,
assert(ByteOffset <= TD.getTypeAllocSize(C->getType()) && assert(ByteOffset <= TD.getTypeAllocSize(C->getType()) &&
"Out of range access"); "Out of range access");
// If this element is zero or undefined, we can just return since *CurPtr is
// zero initialized.
if (isa<ConstantAggregateZero>(C) || isa<UndefValue>(C)) if (isa<ConstantAggregateZero>(C) || isa<UndefValue>(C))
return true; return true;
@@ -115,7 +117,7 @@ static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset,
unsigned IntBytes = unsigned(CI->getBitWidth()/8); unsigned IntBytes = unsigned(CI->getBitWidth()/8);
for (unsigned i = 0; i != BytesLeft && ByteOffset != IntBytes; ++i) { for (unsigned i = 0; i != BytesLeft && ByteOffset != IntBytes; ++i) {
CurPtr[i] = (unsigned char)(Val >> ByteOffset * 8); CurPtr[i] = (unsigned char)(Val >> (ByteOffset * 8));
++ByteOffset; ++ByteOffset;
} }
return true; return true;
@@ -130,6 +132,7 @@ static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset,
C = ConstantExpr::getBitCast(C, Type::getInt32Ty(C->getContext())); C = ConstantExpr::getBitCast(C, Type::getInt32Ty(C->getContext()));
return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, TD); return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, TD);
} }
return false;
} }
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) { if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
@@ -247,8 +250,7 @@ static Constant *FoldReinterpretLoadFromConstPtr(Constant *C,
return 0; return 0;
GlobalVariable *GV = dyn_cast<GlobalVariable>(GVal); GlobalVariable *GV = dyn_cast<GlobalVariable>(GVal);
if (!GV || !GV->isConstant() || !GV->hasInitializer() || if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer() ||
!GV->hasDefinitiveInitializer() ||
!GV->getInitializer()->getType()->isSized()) !GV->getInitializer()->getType()->isSized())
return 0; return 0;