round zero-byte .zerofill directives up to 1 byte. This
authorChris Lattner <sabre@nondot.org>
Tue, 27 Apr 2010 07:41:44 +0000 (07:41 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 27 Apr 2010 07:41:44 +0000 (07:41 +0000)
should fix some "g++.dg-struct-layout-1" failures,
rdar://7886017

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@102421 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/AsmPrinter.cpp
test/CodeGen/X86/global-sections.ll

index 31cb0cab580c3b99fba333022bfc72a8747716a4..f000a7063d567c067e774912b4527e4aea16ef02 100644 (file)
@@ -283,6 +283,8 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
   // Handle the zerofill directive on darwin, which is a special form of BSS
   // emission.
   if (GVKind.isBSSExtern() && MAI->hasMachoZeroFillDirective()) {
+    if (Size == 0) Size = 1;  // zerofill of 0 bytes is undefined.
+    
     // .globl _foo
     OutStreamer.EmitSymbolAttribute(GVSym, MCSA_Global);
     // .zerofill __DATA, __common, _foo, 400, 5
index 732d764dbdea9c95da73df421e2b41ce4b05bb55..6d211913b0153eae0f58dd4bfab51dc42db01954 100644 (file)
 ; LINUX: G10:
 ; LINUX:       .zero   400
 
+
+
+;; Zero sized objects should round up to 1 byte in zerofill directives.
+; rdar://7886017
+@G11 = global [0 x i32] zeroinitializer
+@G12 = global {} zeroinitializer
+@G13 = global { [0 x {}] } zeroinitializer
+
+; DARWIN: .globl _G11
+; DARWIN: .zerofill __DATA,__common,_G11,1,2
+; DARWIN: .globl _G12
+; DARWIN: .zerofill __DATA,__common,_G12,1,3
+; DARWIN: .globl _G13
+; DARWIN: .zerofill __DATA,__common,_G13,1,3