diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp index f67f39aa7d0b..aa465cc24f8c 100644 --- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp +++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp @@ -278,26 +278,42 @@ bool ARMAsmPrinter::doFinalization(Module &M) { unsigned Size = TD->getTypeSize(C->getType()); unsigned Align = TD->getTypeAlignment(C->getType()); - switch (I->getLinkage()) { - default: - assert(0 && "Unknown linkage type!"); - break; - case GlobalValue::ExternalLinkage: - O << "\t.globl " << name << "\n"; - break; - case GlobalValue::InternalLinkage: - break; + if (C->isNullValue() && + (I->hasLinkOnceLinkage() || I->hasInternalLinkage() || + I->hasWeakLinkage())) { + SwitchToDataSection(".data", I); + if (I->hasInternalLinkage()) + O << "\t.local " << name << "\n"; + + O << "\t.comm " << name << "," << TD->getTypeSize(C->getType()) + << "," << (unsigned)TD->getTypeAlignment(C->getType()); + O << "\t\t"; + O << TAI->getCommentString() << " "; + WriteAsOperand(O, I, true, true, &M); + O << "\n"; + } else { + switch (I->getLinkage()) { + default: + assert(0 && "Unknown linkage type!"); + break; + case GlobalValue::ExternalLinkage: + O << "\t.globl " << name << "\n"; + break; + case GlobalValue::InternalLinkage: + break; + } + + assert (!C->isNullValue()); + SwitchToDataSection(".data", I); + + EmitAlignment(Align, I); + O << "\t.type " << name << ", %object\n"; + O << "\t.size " << name << ", " << Size << "\n"; + O << name << ":\n"; + EmitGlobalConstant(C); } - - assert (!C->isNullValue()); - SwitchToDataSection(".data", I); - - EmitAlignment(Align, I); - O << "\t.type " << name << ", %object\n"; - O << "\t.size " << name << ", " << Size << "\n"; - O << name << ":\n"; - EmitGlobalConstant(C); } + AsmPrinter::doFinalization(M); return false; // success } diff --git a/llvm/test/Regression/CodeGen/ARM/constants.ll b/llvm/test/Regression/CodeGen/ARM/constants.ll index 9d5fb8e637d4..f161b9d070ba 100644 --- a/llvm/test/Regression/CodeGen/ARM/constants.ll +++ b/llvm/test/Regression/CodeGen/ARM/constants.ll @@ -4,7 +4,10 @@ ; RUN: llvm-as < %s | llc -march=arm | grep "mov r0, #256" | wc -l | grep 1 && ; RUN: llvm-as < %s | llc -march=arm | grep ".word.*257" | wc -l | grep 1 && ; RUN: llvm-as < %s | llc -march=arm | grep "mov r0, #-1073741761" | wc -l | grep 1 && -; RUN: llvm-as < %s | llc -march=arm | grep "mov r0, #1008" | wc -l | grep 1 +; RUN: llvm-as < %s | llc -march=arm | grep "mov r0, #1008" | wc -l | grep 1 && +; RUN: llvm-as < %s | llc -march=arm | grep "\.comm.*a,4,4" | wc -l | grep 1 + +%a = internal global int 0 uint %f1() { ret uint 0