Fix bug with code for initializers for static arrays in generated C++ code.
(This was preventing aobench from compiling successfully with the generic target.)
This commit is contained in:
20
cbackend.cpp
20
cbackend.cpp
@@ -842,7 +842,8 @@ void CWriter::printConstantArray(ConstantArray *CPA, bool Static) {
|
|||||||
}
|
}
|
||||||
Out << '\"';
|
Out << '\"';
|
||||||
} else {
|
} else {
|
||||||
Out << '{';
|
if (Static)
|
||||||
|
Out << '{';
|
||||||
if (CPA->getNumOperands()) {
|
if (CPA->getNumOperands()) {
|
||||||
Out << ' ';
|
Out << ' ';
|
||||||
printConstant(cast<Constant>(CPA->getOperand(0)), Static);
|
printConstant(cast<Constant>(CPA->getOperand(0)), Static);
|
||||||
@@ -851,7 +852,8 @@ void CWriter::printConstantArray(ConstantArray *CPA, bool Static) {
|
|||||||
printConstant(cast<Constant>(CPA->getOperand(i)), Static);
|
printConstant(cast<Constant>(CPA->getOperand(i)), Static);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Out << " }";
|
if (Static)
|
||||||
|
Out << " }";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1321,8 +1323,9 @@ void CWriter::printConstant(Constant *CPV, bool Static) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case Type::ArrayTyID:
|
case Type::ArrayTyID: {
|
||||||
if (Static)
|
ArrayType *AT = cast<ArrayType>(CPV->getType());
|
||||||
|
if (Static || !isa<StructType>(AT->getElementType()))
|
||||||
// arrays are wrapped in structs...
|
// arrays are wrapped in structs...
|
||||||
Out << "{ ";
|
Out << "{ ";
|
||||||
else {
|
else {
|
||||||
@@ -1334,7 +1337,6 @@ void CWriter::printConstant(Constant *CPV, bool Static) {
|
|||||||
printConstantArray(CA, Static);
|
printConstantArray(CA, Static);
|
||||||
} else {
|
} else {
|
||||||
assert(isa<ConstantAggregateZero>(CPV) || isa<UndefValue>(CPV));
|
assert(isa<ConstantAggregateZero>(CPV) || isa<UndefValue>(CPV));
|
||||||
ArrayType *AT = cast<ArrayType>(CPV->getType());
|
|
||||||
if (AT->getNumElements()) {
|
if (AT->getNumElements()) {
|
||||||
Out << ' ';
|
Out << ' ';
|
||||||
Constant *CZ = Constant::getNullValue(AT->getElementType());
|
Constant *CZ = Constant::getNullValue(AT->getElementType());
|
||||||
@@ -1345,12 +1347,12 @@ void CWriter::printConstant(Constant *CPV, bool Static) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Static)
|
if (Static || !isa<StructType>(AT->getElementType()))
|
||||||
Out << " }";
|
Out << " }";
|
||||||
else
|
else
|
||||||
Out << ")";
|
Out << ")";
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case Type::VectorTyID:
|
case Type::VectorTyID:
|
||||||
printType(Out, CPV->getType());
|
printType(Out, CPV->getType());
|
||||||
Out << "(";
|
Out << "(";
|
||||||
@@ -2203,7 +2205,7 @@ bool CWriter::doInitialization(Module &M) {
|
|||||||
// FIXME common linkage should avoid this problem.
|
// FIXME common linkage should avoid this problem.
|
||||||
if (!I->getInitializer()->isNullValue()) {
|
if (!I->getInitializer()->isNullValue()) {
|
||||||
Out << " = " ;
|
Out << " = " ;
|
||||||
writeOperand(I->getInitializer(), true);
|
writeOperand(I->getInitializer(), false);
|
||||||
} else if (I->hasWeakLinkage()) {
|
} else if (I->hasWeakLinkage()) {
|
||||||
// We have to specify an initializer, but it doesn't have to be
|
// We have to specify an initializer, but it doesn't have to be
|
||||||
// complete. If the value is an aggregate, print out { 0 }, and let
|
// complete. If the value is an aggregate, print out { 0 }, and let
|
||||||
@@ -2218,7 +2220,7 @@ bool CWriter::doInitialization(Module &M) {
|
|||||||
Out << "{ { 0 } }";
|
Out << "{ { 0 } }";
|
||||||
} else {
|
} else {
|
||||||
// Just print it out normally.
|
// Just print it out normally.
|
||||||
writeOperand(I->getInitializer(), true);
|
writeOperand(I->getInitializer(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Out << ";\n";
|
Out << ";\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user