[llvm] r309841 - [AsmParser][GAS-compatibility] Ignore an empty 'p2align' directive

Coby Tayree via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 2 10:36:10 PDT 2017


Author: coby
Date: Wed Aug  2 10:36:10 2017
New Revision: 309841

URL: http://llvm.org/viewvc/llvm-project?rev=309841&view=rev
Log:
[AsmParser][GAS-compatibility] Ignore an empty 'p2align' directive

GAS ignores the aforementioned issue
this patch aligns LLVM + throws in an appropriate warning

Differential Revision: https://reviews.llvm.org/D36060

Modified:
    llvm/trunk/lib/MC/MCParser/AsmParser.cpp
    llvm/trunk/test/MC/AsmParser/directive_align.s

Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=309841&r1=309840&r2=309841&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
+++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Wed Aug  2 10:36:10 2017
@@ -3199,7 +3199,7 @@ bool AsmParser::parseDirectiveAlign(bool
   int64_t MaxBytesToFill = 0;
 
   auto parseAlign = [&]() -> bool {
-    if (checkForValidSection() || parseAbsoluteExpression(Alignment))
+    if (parseAbsoluteExpression(Alignment))
       return true;
     if (parseOptionalToken(AsmToken::Comma)) {
       // The fill expression can be omitted while specifying a maximum number of
@@ -3218,6 +3218,13 @@ bool AsmParser::parseDirectiveAlign(bool
     return parseToken(AsmToken::EndOfStatement);
   };
 
+  if (checkForValidSection())
+    return addErrorSuffix(" in directive");
+  // Ignore empty '.p2align' directives for GNU-as compatibility
+  if (IsPow2 && (ValueSize == 1) && getTok().is(AsmToken::EndOfStatement)) {
+    Warning(AlignmentLoc, "p2align directive with no operand(s) is ignored");
+    return parseToken(AsmToken::EndOfStatement);
+  }
   if (parseAlign())
     return addErrorSuffix(" in directive");
 

Modified: llvm/trunk/test/MC/AsmParser/directive_align.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_align.s?rev=309841&r1=309840&r2=309841&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_align.s (original)
+++ llvm/trunk/test/MC/AsmParser/directive_align.s Wed Aug  2 10:36:10 2017
@@ -1,4 +1,5 @@
-# RUN: not llvm-mc -triple i386-apple-darwin9 %s | FileCheck %s
+# RUN: not llvm-mc -triple i386-apple-darwin9 %s 2> %t.err | FileCheck %s
+# RUN: FileCheck < %t.err %s --check-prefix=CHECK-WARN
 
 # CHECK: TEST0:
 # CHECK: .p2align 1
@@ -14,3 +15,7 @@ TEST1:
 # CHECK: .balign 3, 10
 TEST2:  
         .balign 3,10
+
+# CHECK-WARN: p2align directive with no operand(s) is ignored
+TEST3:  
+        .p2align




More information about the llvm-commits mailing list