[llvm] r247048 - [MC/ELF] Accept zero for .align directive

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 11:59:47 PDT 2015


Author: davide
Date: Tue Sep  8 13:59:47 2015
New Revision: 247048

URL: http://llvm.org/viewvc/llvm-project?rev=247048&view=rev
Log:
[MC/ELF] Accept zero for .align directive

.align directive refuses alignment 0 -- a comment in the code hints this is
done for GNU as compatibility, but it seems GNU as accepts .align 0
(and silently rounds up alignment to 1).

Differential Revision:	 http://reviews.llvm.org/D12682

Added:
    llvm/trunk/test/MC/ELF/align-zero.s
Modified:
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=247048&r1=247047&r2=247048&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Tue Sep  8 13:59:47 2015
@@ -2706,7 +2706,11 @@ bool AsmParser::parseDirectiveAlign(bool
 
     Alignment = 1ULL << Alignment;
   } else {
-    // Reject alignments that aren't a power of two, for gas compatibility.
+    // Reject alignments that aren't either a power of two or zero,
+    // for gas compatibility. Alignment of zero is silently rounded
+    // up to one.
+    if (Alignment == 0)
+      Alignment = 1;
     if (!isPowerOf2_64(Alignment))
       Error(AlignmentLoc, "alignment must be a power of 2");
   }

Added: llvm/trunk/test/MC/ELF/align-zero.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/align-zero.s?rev=247048&view=auto
==============================================================================
--- llvm/trunk/test/MC/ELF/align-zero.s (added)
+++ llvm/trunk/test/MC/ELF/align-zero.s Tue Sep  8 13:59:47 2015
@@ -0,0 +1,4 @@
+// Test that an alignment of zero is accepted.
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o -
+
+  .align 0




More information about the llvm-commits mailing list