From 6451c3d99da48e9d98eadc420e00ab58abc22c75 Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Wed, 18 Jan 2012 06:42:26 -0700 Subject: [PATCH] Fix bug with code for initializers for static arrays in generated C++ code. (This was preventing aobench from compiling successfully with the generic target.) --- cbackend.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cbackend.cpp b/cbackend.cpp index 96f54c23..3c9ce0af 100644 --- a/cbackend.cpp +++ b/cbackend.cpp @@ -842,7 +842,8 @@ void CWriter::printConstantArray(ConstantArray *CPA, bool Static) { } Out << '\"'; } else { - Out << '{'; + if (Static) + Out << '{'; if (CPA->getNumOperands()) { Out << ' '; printConstant(cast(CPA->getOperand(0)), Static); @@ -851,7 +852,8 @@ void CWriter::printConstantArray(ConstantArray *CPA, bool Static) { printConstant(cast(CPA->getOperand(i)), Static); } } - Out << " }"; + if (Static) + Out << " }"; } } @@ -1321,8 +1323,9 @@ void CWriter::printConstant(Constant *CPV, bool Static) { break; } - case Type::ArrayTyID: - if (Static) + case Type::ArrayTyID: { + ArrayType *AT = cast(CPV->getType()); + if (Static || !isa(AT->getElementType())) // arrays are wrapped in structs... Out << "{ "; else { @@ -1334,7 +1337,6 @@ void CWriter::printConstant(Constant *CPV, bool Static) { printConstantArray(CA, Static); } else { assert(isa(CPV) || isa(CPV)); - ArrayType *AT = cast(CPV->getType()); if (AT->getNumElements()) { Out << ' '; Constant *CZ = Constant::getNullValue(AT->getElementType()); @@ -1345,12 +1347,12 @@ void CWriter::printConstant(Constant *CPV, bool Static) { } } } - if (Static) + if (Static || !isa(AT->getElementType())) Out << " }"; else Out << ")"; break; - + } case Type::VectorTyID: printType(Out, CPV->getType()); Out << "("; @@ -2203,7 +2205,7 @@ bool CWriter::doInitialization(Module &M) { // FIXME common linkage should avoid this problem. if (!I->getInitializer()->isNullValue()) { Out << " = " ; - writeOperand(I->getInitializer(), true); + writeOperand(I->getInitializer(), false); } else if (I->hasWeakLinkage()) { // 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 @@ -2218,7 +2220,7 @@ bool CWriter::doInitialization(Module &M) { Out << "{ { 0 } }"; } else { // Just print it out normally. - writeOperand(I->getInitializer(), true); + writeOperand(I->getInitializer(), false); } } Out << ";\n";