MCParser: Reject .balign with non-pow2 alignments.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sat, 16 Feb 2013 15:00:16 +0000 (15:00 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sat, 16 Feb 2013 15:00:16 +0000 (15:00 +0000)
GNU as rejects them and there are configure scripts in the wild that check if
the assembler rejects ".align 3" to determine whether the alignment is in bytes
or powers of two.

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

lib/MC/MCParser/AsmParser.cpp
test/MC/AsmParser/align_invalid.s [new file with mode: 0644]

index b7953c1a5977dd695ff3449f393fdc1ccfeb5027..9c998ff796c58b6b3853f0da7bd6dc707cd50d54 100644 (file)
@@ -2456,6 +2456,10 @@ bool AsmParser::ParseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
     }
 
     Alignment = 1ULL << Alignment;
+  } else {
+    // Reject alignments that aren't a power of two, for gas compatibility.
+    if (!isPowerOf2_64(Alignment))
+      Error(AlignmentLoc, "alignment must be a power of 2");
   }
 
   // Diagnose non-sensical max bytes to align.
diff --git a/test/MC/AsmParser/align_invalid.s b/test/MC/AsmParser/align_invalid.s
new file mode 100644 (file)
index 0000000..0d06d94
--- /dev/null
@@ -0,0 +1,10 @@
+# RUN: llvm-mc -triple i386-linux-gnu < %s 2>&1 | FileCheck %s -check-prefix=ELF
+# RUN: llvm-mc -triple i386-apple-darwin < %s 2>&1 | FileCheck %s -check-prefix=DARWIN
+
+.align 3
+# ELF: error: alignment must be a power of 2
+# DARWIN-NOT: error
+
+.align 32
+# ELF-NOT: error
+# DARWIN: error: invalid alignment value