print common symbols


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31048 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/ARM/ARMAsmPrinter.cpp b/lib/Target/ARM/ARMAsmPrinter.cpp
index f67f39a..aa465cc 100644
--- a/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -278,26 +278,42 @@
     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/test/CodeGen/ARM/constants.ll b/test/CodeGen/ARM/constants.ll
index 9d5fb8e..f161b9d 100644
--- a/test/CodeGen/ARM/constants.ll
+++ b/test/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