diff --git a/lib/Bytecode/Writer/SlotCalculator.cpp b/lib/Bytecode/Writer/SlotCalculator.cpp index 7b18a1dfd5a..d462bdd1e9f 100644 --- a/lib/Bytecode/Writer/SlotCalculator.cpp +++ b/lib/Bytecode/Writer/SlotCalculator.cpp @@ -146,7 +146,8 @@ void SlotCalculator::processModule() { TypePlane &Plane = Table[plane]; unsigned FirstNonStringID = 0; for (unsigned i = 0, e = Plane.size(); i != e; ++i) - if (cast(Plane[i])->isString()) { + if (isa(Plane[i]) || + cast(Plane[i])->isString()) { // Check to see if we have to shuffle this string around. If not, // don't do anything. if (i != FirstNonStringID) { diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 457a8b97b65..aa7720ece35 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -284,7 +284,8 @@ static Value *RemapOperand(const Value *In, // Check to see if it's a constant that we are interesting in transforming... if (const Constant *CPV = dyn_cast(In)) { - if (!isa(CPV->getType()) && !isa(CPV)) + if ((!isa(CPV->getType()) && !isa(CPV)) || + isa(CPV)) return const_cast(CPV); // Simple constants stay identical... Constant *Result = 0; @@ -796,12 +797,24 @@ static bool LinkAppendingVars(Module *M, // Merge the initializer... Inits.reserve(NewSize); - ConstantArray *I = cast(G1->getInitializer()); - for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i) - Inits.push_back(cast(I->getValues()[i])); - I = cast(G2->getInitializer()); - for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i) - Inits.push_back(cast(I->getValues()[i])); + if (ConstantArray *I = dyn_cast(G1->getInitializer())) { + for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i) + Inits.push_back(cast(I->getValues()[i])); + } else { + assert(isa(G1->getInitializer())); + Constant *CV = Constant::getNullValue(T1->getElementType()); + for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i) + Inits.push_back(CV); + } + if (ConstantArray *I = dyn_cast(G2->getInitializer())) { + for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i) + Inits.push_back(cast(I->getValues()[i])); + } else { + assert(isa(G2->getInitializer())); + Constant *CV = Constant::getNullValue(T2->getElementType()); + for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i) + Inits.push_back(CV); + } NG->setInitializer(ConstantArray::get(NewType, Inits)); Inits.clear(); diff --git a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp index e87f6a2215a..40aa81cab00 100644 --- a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp +++ b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp @@ -387,8 +387,9 @@ void AsmPrinter::printConstantValueOnly(const Constant* CV, } assert(sizeSoFar == cvsLayout->StructSize && "Layout of constant struct may be incorrect!"); - } - else + } else if (isa(CV)) { + PrintZeroBytesToPad(Target.getTargetData().getTypeSize(CV->getType())); + } else printSingleConstantValue(CV); if (numPadBytesAfter) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 85d580b8ce5..773441f5383 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2088,11 +2088,13 @@ static Constant *GetGEPGlobalInitializer(Constant *C, ConstantExpr *CE) { // addressing... for (unsigned i = 2, e = CE->getNumOperands(); i != e; ++i) if (ConstantUInt *CU = dyn_cast(CE->getOperand(i))) { - ConstantStruct *CS = cast(C); + ConstantStruct *CS = dyn_cast(C); + if (CS == 0) return 0; if (CU->getValue() >= CS->getValues().size()) return 0; C = cast(CS->getValues()[CU->getValue()]); } else if (ConstantSInt *CS = dyn_cast(CE->getOperand(i))) { - ConstantArray *CA = cast(C); + ConstantArray *CA = dyn_cast(C); + if (CA == 0) return 0; if ((uint64_t)CS->getValue() >= CA->getValues().size()) return 0; C = cast(CA->getValues()[CS->getValue()]); } else diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 4e5e5156bb7..8304e2e823b 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -689,14 +689,16 @@ static Constant *GetGEPGlobalInitializer(Constant *C, ConstantExpr *CE) { // addressing... for (unsigned i = 2, e = CE->getNumOperands(); i != e; ++i) if (ConstantUInt *CU = dyn_cast(CE->getOperand(i))) { - ConstantStruct *CS = cast(C); + ConstantStruct *CS = dyn_cast(C); + if (CS == 0) return 0; if (CU->getValue() >= CS->getValues().size()) return 0; C = cast(CS->getValues()[CU->getValue()]); } else if (ConstantSInt *CS = dyn_cast(CE->getOperand(i))) { - ConstantArray *CA = cast(C); + ConstantArray *CA = dyn_cast(C); + if (CA == 0) return 0; if ((uint64_t)CS->getValue() >= CA->getValues().size()) return 0; C = cast(CA->getValues()[CS->getValue()]); - } else + } else return 0; return C; } diff --git a/lib/Transforms/Utils/Linker.cpp b/lib/Transforms/Utils/Linker.cpp index 457a8b97b65..aa7720ece35 100644 --- a/lib/Transforms/Utils/Linker.cpp +++ b/lib/Transforms/Utils/Linker.cpp @@ -284,7 +284,8 @@ static Value *RemapOperand(const Value *In, // Check to see if it's a constant that we are interesting in transforming... if (const Constant *CPV = dyn_cast(In)) { - if (!isa(CPV->getType()) && !isa(CPV)) + if ((!isa(CPV->getType()) && !isa(CPV)) || + isa(CPV)) return const_cast(CPV); // Simple constants stay identical... Constant *Result = 0; @@ -796,12 +797,24 @@ static bool LinkAppendingVars(Module *M, // Merge the initializer... Inits.reserve(NewSize); - ConstantArray *I = cast(G1->getInitializer()); - for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i) - Inits.push_back(cast(I->getValues()[i])); - I = cast(G2->getInitializer()); - for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i) - Inits.push_back(cast(I->getValues()[i])); + if (ConstantArray *I = dyn_cast(G1->getInitializer())) { + for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i) + Inits.push_back(cast(I->getValues()[i])); + } else { + assert(isa(G1->getInitializer())); + Constant *CV = Constant::getNullValue(T1->getElementType()); + for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i) + Inits.push_back(CV); + } + if (ConstantArray *I = dyn_cast(G2->getInitializer())) { + for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i) + Inits.push_back(cast(I->getValues()[i])); + } else { + assert(isa(G2->getInitializer())); + Constant *CV = Constant::getNullValue(T2->getElementType()); + for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i) + Inits.push_back(CV); + } NG->setInitializer(ConstantArray::get(NewType, Inits)); Inits.clear(); diff --git a/lib/Transforms/Utils/ValueMapper.cpp b/lib/Transforms/Utils/ValueMapper.cpp index acc433a6ed2..2cb6a9d221d 100644 --- a/lib/Transforms/Utils/ValueMapper.cpp +++ b/lib/Transforms/Utils/ValueMapper.cpp @@ -28,7 +28,7 @@ Value *llvm::MapValue(const Value *V, std::map &VM) { if (Constant *C = const_cast(dyn_cast(V))) { if (isa(C) || isa(C) || - isa(C)) + isa(C) || isa(C)) return VMSlot = C; // Primitive constants map directly else if (ConstantPointerRef *CPR = dyn_cast(C)) { GlobalValue *MV = cast(MapValue((Value*)CPR->getValue(),VM)); diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp index 5fc7a893c44..29adfd079ad 100644 --- a/lib/VMCore/AsmWriter.cpp +++ b/lib/VMCore/AsmWriter.cpp @@ -288,12 +288,9 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV, "assuming that double is 64 bits!"); Out << "0x" << utohexstr(*(uint64_t*)Ptr); + } else if (isa(CV)) { + Out << "zeroinitializer"; } else if (const ConstantArray *CA = dyn_cast(CV)) { - if (CA->getNumOperands() > 5 && CA->isNullValue()) { - Out << "zeroinitializer"; - return; - } - // As a special case, print the array as a string if it is an array of // ubytes or an array of sbytes with positive values. // @@ -339,11 +336,6 @@ static void WriteConstantInt(std::ostream &Out, const Constant *CV, Out << " ]"; } } else if (const ConstantStruct *CS = dyn_cast(CV)) { - if (CS->getNumOperands() > 5 && CS->isNullValue()) { - Out << "zeroinitializer"; - return; - } - Out << "{"; if (CS->getNumOperands()) { Out << " "; diff --git a/lib/VMCore/Linker.cpp b/lib/VMCore/Linker.cpp index 457a8b97b65..aa7720ece35 100644 --- a/lib/VMCore/Linker.cpp +++ b/lib/VMCore/Linker.cpp @@ -284,7 +284,8 @@ static Value *RemapOperand(const Value *In, // Check to see if it's a constant that we are interesting in transforming... if (const Constant *CPV = dyn_cast(In)) { - if (!isa(CPV->getType()) && !isa(CPV)) + if ((!isa(CPV->getType()) && !isa(CPV)) || + isa(CPV)) return const_cast(CPV); // Simple constants stay identical... Constant *Result = 0; @@ -796,12 +797,24 @@ static bool LinkAppendingVars(Module *M, // Merge the initializer... Inits.reserve(NewSize); - ConstantArray *I = cast(G1->getInitializer()); - for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i) - Inits.push_back(cast(I->getValues()[i])); - I = cast(G2->getInitializer()); - for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i) - Inits.push_back(cast(I->getValues()[i])); + if (ConstantArray *I = dyn_cast(G1->getInitializer())) { + for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i) + Inits.push_back(cast(I->getValues()[i])); + } else { + assert(isa(G1->getInitializer())); + Constant *CV = Constant::getNullValue(T1->getElementType()); + for (unsigned i = 0, e = T1->getNumElements(); i != e; ++i) + Inits.push_back(CV); + } + if (ConstantArray *I = dyn_cast(G2->getInitializer())) { + for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i) + Inits.push_back(cast(I->getValues()[i])); + } else { + assert(isa(G2->getInitializer())); + Constant *CV = Constant::getNullValue(T2->getElementType()); + for (unsigned i = 0, e = T2->getNumElements(); i != e; ++i) + Inits.push_back(CV); + } NG->setInitializer(ConstantArray::get(NewType, Inits)); Inits.clear(); diff --git a/lib/VMCore/SlotCalculator.cpp b/lib/VMCore/SlotCalculator.cpp index 7b18a1dfd5a..d462bdd1e9f 100644 --- a/lib/VMCore/SlotCalculator.cpp +++ b/lib/VMCore/SlotCalculator.cpp @@ -146,7 +146,8 @@ void SlotCalculator::processModule() { TypePlane &Plane = Table[plane]; unsigned FirstNonStringID = 0; for (unsigned i = 0, e = Plane.size(); i != e; ++i) - if (cast(Plane[i])->isString()) { + if (isa(Plane[i]) || + cast(Plane[i])->isString()) { // Check to see if we have to shuffle this string around. If not, // don't do anything. if (i != FirstNonStringID) {