mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-03 14:31:10 +00:00
Fix InstCombine/load.ll & PR347.
This code hadn't been updated after the "structs with more than 256 elements" related changes to the GEP instruction. Also it was not handling the ConstantAggregateZero class. Now it does! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13834 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3ba3097516
commit
e1368aef23
@ -2852,19 +2852,31 @@ static Constant *GetGEPGlobalInitializer(Constant *C, ConstantExpr *CE) {
|
|||||||
|
|
||||||
// Loop over all of the operands, tracking down which value we are
|
// Loop over all of the operands, tracking down which value we are
|
||||||
// addressing...
|
// addressing...
|
||||||
for (unsigned i = 2, e = CE->getNumOperands(); i != e; ++i)
|
gep_type_iterator I = gep_type_begin(CE), E = gep_type_end(CE);
|
||||||
if (ConstantUInt *CU = dyn_cast<ConstantUInt>(CE->getOperand(i))) {
|
for (++I; I != E; ++I)
|
||||||
ConstantStruct *CS = dyn_cast<ConstantStruct>(C);
|
if (const StructType *STy = dyn_cast<StructType>(*I)) {
|
||||||
if (CS == 0) return 0;
|
ConstantUInt *CU = cast<ConstantUInt>(I.getOperand());
|
||||||
if (CU->getValue() >= CS->getValues().size()) return 0;
|
assert(CU->getValue() < STy->getNumElements() &&
|
||||||
C = cast<Constant>(CS->getValues()[CU->getValue()]);
|
"Struct index out of range!");
|
||||||
} else if (ConstantSInt *CS = dyn_cast<ConstantSInt>(CE->getOperand(i))) {
|
if (ConstantStruct *CS = dyn_cast<ConstantStruct>(C)) {
|
||||||
ConstantArray *CA = dyn_cast<ConstantArray>(C);
|
C = cast<Constant>(CS->getValues()[CU->getValue()]);
|
||||||
if (CA == 0) return 0;
|
} else if (isa<ConstantAggregateZero>(C)) {
|
||||||
if ((uint64_t)CS->getValue() >= CA->getValues().size()) return 0;
|
C = Constant::getNullValue(STy->getElementType(CU->getValue()));
|
||||||
C = cast<Constant>(CA->getValues()[CS->getValue()]);
|
} else {
|
||||||
} else
|
return 0;
|
||||||
|
}
|
||||||
|
} else if (ConstantInt *CI = dyn_cast<ConstantInt>(I.getOperand())) {
|
||||||
|
const ArrayType *ATy = cast<ArrayType>(*I);
|
||||||
|
if ((uint64_t)CI->getRawValue() >= ATy->getNumElements()) return 0;
|
||||||
|
if (ConstantArray *CA = dyn_cast<ConstantArray>(C))
|
||||||
|
C = cast<Constant>(CA->getValues()[CI->getRawValue()]);
|
||||||
|
else if (isa<ConstantAggregateZero>(C))
|
||||||
|
C = Constant::getNullValue(ATy->getElementType());
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
return C;
|
return C;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user