[llvm-commits] [llvm] r163420 - in /llvm/trunk: include/llvm/MC/MCAsmInfo.h lib/CodeGen/AsmPrinter/AsmPrinter.cpp lib/MC/MCAsmInfo.cpp lib/MC/MCAsmInfoCOFF.cpp lib/MC/MCAsmInfoDarwin.cpp lib/MC/MCAsmStreamer.cpp lib/MC/MCParser/AsmParser.cpp lib/Target/Hexagon/MCTargetDesc/HexagonMCAsmInfo.cpp test/MC/COFF/comm.ll

Benjamin Kramer benny.kra at googlemail.com
Fri Sep 7 14:08:01 PDT 2012


Author: d0k
Date: Fri Sep  7 16:08:01 2012
New Revision: 163420

URL: http://llvm.org/viewvc/llvm-project?rev=163420&view=rev
Log:
Fix alignment of .comm and .lcomm on mingw32.

For some reason .lcomm uses byte alignment and .comm log2 alignment so we can't
use the same setting for both. Fix this by reintroducing the LCOMM enum.
I verified this against mingw's gcc.

Added:
    llvm/trunk/test/MC/COFF/comm.ll
Modified:
    llvm/trunk/include/llvm/MC/MCAsmInfo.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/MC/MCAsmInfo.cpp
    llvm/trunk/lib/MC/MCAsmInfoCOFF.cpp
    llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp
    llvm/trunk/lib/MC/MCAsmStreamer.cpp
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp
    llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCAsmInfo.cpp

Modified: llvm/trunk/include/llvm/MC/MCAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCAsmInfo.h?rev=163420&r1=163419&r2=163420&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCAsmInfo.h (original)
+++ llvm/trunk/include/llvm/MC/MCAsmInfo.h Fri Sep  7 16:08:01 2012
@@ -32,6 +32,10 @@
     enum ExceptionsType { None, DwarfCFI, SjLj, ARM, Win64 };
   }
 
+  namespace LCOMM {
+    enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
+  }
+
   /// MCAsmInfo - This class is intended to be used as a base class for asm
   /// properties and features specific to the target.
   class MCAsmInfo {
@@ -247,9 +251,9 @@
     /// alignment is to be specified in bytes instead of log2(n).
     bool COMMDirectiveAlignmentIsInBytes;    // Defaults to true;
 
-    /// LCOMMDirectiveSupportsAlignment - True if .lcomm supports an optional
-    /// alignment argument on this target.
-    bool LCOMMDirectiveSupportsAlignment;    // Defaults to false.
+    /// LCOMMDirectiveAlignment - Describes if the .lcomm directive for the
+    /// target supports an alignment argument and how it is interpreted.
+    LCOMM::LCOMMType LCOMMDirectiveAlignmentType; // Defaults to NoAlignment.
 
     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
     /// directives, this is true for most ELF targets.
@@ -495,8 +499,8 @@
     bool getCOMMDirectiveAlignmentIsInBytes() const {
       return COMMDirectiveAlignmentIsInBytes;
     }
-    bool getLCOMMDirectiveSupportsAlignment() const {
-      return LCOMMDirectiveSupportsAlignment;
+    LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
+      return LCOMMDirectiveAlignmentType;
     }
     bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
     bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=163420&r1=163419&r2=163420&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Fri Sep  7 16:08:01 2012
@@ -312,7 +312,8 @@
       return;
     }
 
-    if (Align == 1 || MAI->getLCOMMDirectiveSupportsAlignment()) {
+    if (Align == 1 ||
+        MAI->getLCOMMDirectiveAlignmentType() != LCOMM::NoAlignment) {
       // .lcomm _foo, 42
       OutStreamer.EmitLocalCommonSymbol(GVSym, Size, Align);
       return;

Modified: llvm/trunk/lib/MC/MCAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmInfo.cpp?rev=163420&r1=163419&r2=163420&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmInfo.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmInfo.cpp Fri Sep  7 16:08:01 2012
@@ -69,7 +69,7 @@
   HasSetDirective = true;
   HasAggressiveSymbolFolding = true;
   COMMDirectiveAlignmentIsInBytes = true;
-  LCOMMDirectiveSupportsAlignment = false;
+  LCOMMDirectiveAlignmentType = LCOMM::NoAlignment;
   HasDotTypeDotSizeDirective = true;
   HasSingleParameterDotFile = true;
   HasNoDeadStrip = false;

Modified: llvm/trunk/lib/MC/MCAsmInfoCOFF.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmInfoCOFF.cpp?rev=163420&r1=163419&r2=163420&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmInfoCOFF.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmInfoCOFF.cpp Fri Sep  7 16:08:01 2012
@@ -19,8 +19,10 @@
 
 MCAsmInfoCOFF::MCAsmInfoCOFF() {
   GlobalPrefix = "_";
-  COMMDirectiveAlignmentIsInBytes = true;
-  LCOMMDirectiveSupportsAlignment = true;
+  // MingW 4.5 and later support .comm with log2 alignment, but .lcomm uses byte
+  // alignment.
+  COMMDirectiveAlignmentIsInBytes = false;
+  LCOMMDirectiveAlignmentType = LCOMM::ByteAlignment;
   HasDotTypeDotSizeDirective = false;
   HasSingleParameterDotFile = false;
   PrivateGlobalPrefix = "L";  // Prefix for private global symbols

Modified: llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp?rev=163420&r1=163419&r2=163420&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmInfoDarwin.cpp Fri Sep  7 16:08:01 2012
@@ -32,7 +32,7 @@
 
   AlignmentIsInBytes = false;
   COMMDirectiveAlignmentIsInBytes = false;
-  LCOMMDirectiveSupportsAlignment = true;
+  LCOMMDirectiveAlignmentType = LCOMM::Log2Alignment;
   InlineAsmStart = " InlineAsm Start";
   InlineAsmEnd = " InlineAsm End";
 

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=163420&r1=163419&r2=163420&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Fri Sep  7 16:08:01 2012
@@ -519,13 +519,16 @@
                                           unsigned ByteAlign) {
   OS << "\t.lcomm\t" << *Symbol << ',' << Size;
   if (ByteAlign > 1) {
-    assert(MAI.getLCOMMDirectiveSupportsAlignment() &&
-           "alignment not supported on .lcomm!");
-    if (MAI.getCOMMDirectiveAlignmentIsInBytes()) {
+    switch (MAI.getLCOMMDirectiveAlignmentType()) {
+    case LCOMM::NoAlignment:
+      llvm_unreachable("alignment not supported on .lcomm!");
+    case LCOMM::ByteAlignment:
       OS << ',' << ByteAlign;
-    } else {
+      break;
+    case LCOMM::Log2Alignment:
       assert(isPowerOf2_32(ByteAlign) && "alignment must be a power of 2");
       OS << ',' << Log2_32(ByteAlign);
+      break;
     }
   }
   EmitEOL();

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=163420&r1=163419&r2=163420&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Fri Sep  7 16:08:01 2012
@@ -2280,11 +2280,13 @@
     if (ParseAbsoluteExpression(Pow2Alignment))
       return true;
 
-    if (IsLocal && !Lexer.getMAI().getLCOMMDirectiveSupportsAlignment())
+    LCOMM::LCOMMType LCOMM = Lexer.getMAI().getLCOMMDirectiveAlignmentType();
+    if (IsLocal && LCOMM == LCOMM::NoAlignment)
       return Error(Pow2AlignmentLoc, "alignment not supported on this target");
 
     // If this target takes alignments in bytes (not log) validate and convert.
-    if (Lexer.getMAI().getCOMMDirectiveAlignmentIsInBytes()) {
+    if ((!IsLocal && Lexer.getMAI().getCOMMDirectiveAlignmentIsInBytes()) ||
+        (IsLocal && LCOMM == LCOMM::ByteAlignment)) {
       if (!isPowerOf2_64(Pow2Alignment))
         return Error(Pow2AlignmentLoc, "alignment must be a power of 2");
       Pow2Alignment = Log2_64(Pow2Alignment);

Modified: llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCAsmInfo.cpp?rev=163420&r1=163419&r2=163420&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/Hexagon/MCTargetDesc/HexagonMCAsmInfo.cpp Fri Sep  7 16:08:01 2012
@@ -24,7 +24,7 @@
   HasLEB128 = true;
 
   PrivateGlobalPrefix = ".L";
-  LCOMMDirectiveSupportsAlignment = true;
+  LCOMMDirectiveAlignmentType = LCOMM::ByteAlignment;
   InlineAsmStart = "# InlineAsm Start";
   InlineAsmEnd = "# InlineAsm End";
   ZeroDirective = "\t.space\t";

Added: llvm/trunk/test/MC/COFF/comm.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/COFF/comm.ll?rev=163420&view=auto
==============================================================================
--- llvm/trunk/test/MC/COFF/comm.ll (added)
+++ llvm/trunk/test/MC/COFF/comm.ll Fri Sep  7 16:08:01 2012
@@ -0,0 +1,13 @@
+; RUN: llc -mtriple i386-pc-mingw32 < %s | FileCheck %s
+
+ at a = internal global i8 0, align 1
+ at b = internal global double 0.000000e+00, align 8
+ at c = common global i8 0, align 1
+ at d = common global double 0.000000e+00, align 8
+
+; .lcomm uses byte alignment
+; CHECK: .lcomm	_a,1
+; CHECK: .lcomm	_b,8,8
+; .comm uses log2 alignment
+; CHECK: .comm	_c,1,0
+; CHECK: .comm	_d,8,3





More information about the llvm-commits mailing list