diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 74ed208f078..0d36ea73c32 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -475,22 +475,50 @@ void CWriter::printConstant(Constant *CPV) { } case Type::ArrayTyID: - printConstantArray(cast(CPV)); + if (isa(CPV)) { + const ArrayType *AT = cast(CPV->getType()); + Out << "{"; + if (AT->getNumElements()) { + Out << " "; + Constant *CZ = Constant::getNullValue(AT->getElementType()); + printConstant(CZ); + for (unsigned i = 1, e = AT->getNumElements(); i != e; ++i) { + Out << ", "; + printConstant(CZ); + } + } + Out << " }"; + } else { + printConstantArray(cast(CPV)); + } break; - case Type::StructTyID: { - Out << "{"; - if (CPV->getNumOperands()) { - Out << " "; - printConstant(cast(CPV->getOperand(0))); - for (unsigned i = 1, e = CPV->getNumOperands(); i != e; ++i) { - Out << ", "; - printConstant(cast(CPV->getOperand(i))); + case Type::StructTyID: + if (isa(CPV)) { + const StructType *ST = cast(CPV->getType()); + Out << "{"; + if (ST->getNumElements()) { + Out << " "; + printConstant(Constant::getNullValue(ST->getElementType(0))); + for (unsigned i = 1, e = ST->getNumElements(); i != e; ++i) { + Out << ", "; + printConstant(Constant::getNullValue(ST->getElementType(i))); + } } + Out << " }"; + } else { + Out << "{"; + if (CPV->getNumOperands()) { + Out << " "; + printConstant(cast(CPV->getOperand(0))); + for (unsigned i = 1, e = CPV->getNumOperands(); i != e; ++i) { + Out << ", "; + printConstant(cast(CPV->getOperand(i))); + } + } + Out << " }"; } - Out << " }"; break; - } case Type::PointerTyID: if (isa(CPV)) { diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp index 74ed208f078..0d36ea73c32 100644 --- a/lib/Target/CBackend/Writer.cpp +++ b/lib/Target/CBackend/Writer.cpp @@ -475,22 +475,50 @@ void CWriter::printConstant(Constant *CPV) { } case Type::ArrayTyID: - printConstantArray(cast(CPV)); + if (isa(CPV)) { + const ArrayType *AT = cast(CPV->getType()); + Out << "{"; + if (AT->getNumElements()) { + Out << " "; + Constant *CZ = Constant::getNullValue(AT->getElementType()); + printConstant(CZ); + for (unsigned i = 1, e = AT->getNumElements(); i != e; ++i) { + Out << ", "; + printConstant(CZ); + } + } + Out << " }"; + } else { + printConstantArray(cast(CPV)); + } break; - case Type::StructTyID: { - Out << "{"; - if (CPV->getNumOperands()) { - Out << " "; - printConstant(cast(CPV->getOperand(0))); - for (unsigned i = 1, e = CPV->getNumOperands(); i != e; ++i) { - Out << ", "; - printConstant(cast(CPV->getOperand(i))); + case Type::StructTyID: + if (isa(CPV)) { + const StructType *ST = cast(CPV->getType()); + Out << "{"; + if (ST->getNumElements()) { + Out << " "; + printConstant(Constant::getNullValue(ST->getElementType(0))); + for (unsigned i = 1, e = ST->getNumElements(); i != e; ++i) { + Out << ", "; + printConstant(Constant::getNullValue(ST->getElementType(i))); + } } + Out << " }"; + } else { + Out << "{"; + if (CPV->getNumOperands()) { + Out << " "; + printConstant(cast(CPV->getOperand(0))); + for (unsigned i = 1, e = CPV->getNumOperands(); i != e; ++i) { + Out << ", "; + printConstant(cast(CPV->getOperand(i))); + } + } + Out << " }"; } - Out << " }"; break; - } case Type::PointerTyID: if (isa(CPV)) {