diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index f70620c15a7eb..15ba96b84fa47 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -3392,6 +3392,7 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) { bool HasFillExpr = false; int64_t FillExpr = 0; int64_t MaxBytesToFill = 0; + SMLoc FillExprLoc; auto parseAlign = [&]() -> bool { if (parseAbsoluteExpression(Alignment)) @@ -3402,7 +3403,7 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) { // .align 3,,4 if (getTok().isNot(AsmToken::Comma)) { HasFillExpr = true; - if (parseAbsoluteExpression(FillExpr)) + if (parseTokenLoc(FillExprLoc) || parseAbsoluteExpression(FillExpr)) return true; } if (parseOptionalToken(AsmToken::Comma)) @@ -3451,6 +3452,17 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) { } } + if (HasFillExpr) { + MCSection *Sec = getStreamer().getCurrentSectionOnly(); + if (Sec && Sec->isVirtualSection()) { + ReturnVal |= + Warning(FillExprLoc, "ignoring non-zero fill value in " + + Sec->getVirtualSectionKind() + " section '" + + Sec->getName() + "'"); + FillExpr = 0; + } + } + // Diagnose non-sensical max bytes to align. if (MaxBytesLoc.isValid()) { if (MaxBytesToFill < 1) { diff --git a/llvm/test/MC/ELF/nobits-non-zero-value.s b/llvm/test/MC/ELF/nobits-non-zero-value.s index 16d386dc62ad5..8f37a957b6b56 100644 --- a/llvm/test/MC/ELF/nobits-non-zero-value.s +++ b/llvm/test/MC/ELF/nobits-non-zero-value.s @@ -12,5 +12,8 @@ # CHECK: {{.*}}.s:[[#@LINE+1]]:3: error: SHT_NOBITS section '.bss' cannot have instructions addb %al,(%rax) +# CHECK: {{.*}}.s:[[#@LINE+1]]:11: warning: ignoring non-zero fill value in SHT_NOBITS section '.bss' +.align 4, 42 + # CHECK: :0: error: SHT_NOBITS section '.bss' cannot have non-zero initializers .long 1