assert(ByteOffset <= TD.getTypeAllocSize(C->getType()) &&
"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))
return true;
unsigned IntBytes = unsigned(CI->getBitWidth()/8);
for (unsigned i = 0; i != BytesLeft && ByteOffset != IntBytes; ++i) {
- CurPtr[i] = (unsigned char)(Val >> ByteOffset * 8);
+ CurPtr[i] = (unsigned char)(Val >> (ByteOffset * 8));
++ByteOffset;
}
return true;
C = ConstantExpr::getBitCast(C, Type::getInt32Ty(C->getContext()));
return ReadDataFromGlobal(C, ByteOffset, CurPtr, BytesLeft, TD);
}
+ return false;
}
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
return 0;
GlobalVariable *GV = dyn_cast<GlobalVariable>(GVal);
- if (!GV || !GV->isConstant() || !GV->hasInitializer() ||
- !GV->hasDefinitiveInitializer() ||
+ if (!GV || !GV->isConstant() || !GV->hasDefinitiveInitializer() ||
!GV->getInitializer()->getType()->isSized())
return 0;