diff options
| -rw-r--r-- | llvm/lib/MC/MCParser/AsmParser.cpp | 9 | ||||
| -rw-r--r-- | llvm/test/MC/AsmParser/directive_align.s | 7 |
2 files changed, 14 insertions, 2 deletions
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 2756cb71ed9..a75476d2298 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -3199,7 +3199,7 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) { 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 IsPow2, unsigned ValueSize) { 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"); diff --git a/llvm/test/MC/AsmParser/directive_align.s b/llvm/test/MC/AsmParser/directive_align.s index 9eb1d7f2d8f..91148eb635b 100644 --- a/llvm/test/MC/AsmParser/directive_align.s +++ b/llvm/test/MC/AsmParser/directive_align.s @@ -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 |

