Skip to content

Commit fc0c8f5

Browse files
committed
Warn on align directive with non-zero fill value in virtual sections
This patch warns when an align directive with a non-zero fill value is used in a virtual section. The fill value is also set to zero, preventing an assertion in MCAssembler::writeSectionData for the case of MCFragment::FT_Align from tripping.
1 parent c41b4b6 commit fc0c8f5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3392,6 +3392,7 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
33923392
bool HasFillExpr = false;
33933393
int64_t FillExpr = 0;
33943394
int64_t MaxBytesToFill = 0;
3395+
SMLoc FillExprLoc;
33953396

33963397
auto parseAlign = [&]() -> bool {
33973398
if (parseAbsoluteExpression(Alignment))
@@ -3402,7 +3403,7 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
34023403
// .align 3,,4
34033404
if (getTok().isNot(AsmToken::Comma)) {
34043405
HasFillExpr = true;
3405-
if (parseAbsoluteExpression(FillExpr))
3406+
if (parseTokenLoc(FillExprLoc) || parseAbsoluteExpression(FillExpr))
34063407
return true;
34073408
}
34083409
if (parseOptionalToken(AsmToken::Comma))
@@ -3451,6 +3452,17 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
34513452
}
34523453
}
34533454

3455+
if (HasFillExpr) {
3456+
MCSection *Sec = getStreamer().getCurrentSectionOnly();
3457+
if (Sec && Sec->isVirtualSection()) {
3458+
ReturnVal |=
3459+
Warning(FillExprLoc, "ignoring non-zero fill value in " +
3460+
Sec->getVirtualSectionKind() + " section '" +
3461+
Sec->getName() + "'");
3462+
FillExpr = 0;
3463+
}
3464+
}
3465+
34543466
// Diagnose non-sensical max bytes to align.
34553467
if (MaxBytesLoc.isValid()) {
34563468
if (MaxBytesToFill < 1) {

llvm/test/MC/ELF/nobits-non-zero-value.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
# CHECK: {{.*}}.s:[[#@LINE+1]]:3: error: SHT_NOBITS section '.bss' cannot have instructions
1313
addb %al,(%rax)
1414

15+
# CHECK: {{.*}}.s:[[#@LINE+1]]:11: warning: ignoring non-zero fill value in SHT_NOBITS section '.bss'
16+
.align 4, 42
17+
1518
# CHECK: <unknown>:0: error: SHT_NOBITS section '.bss' cannot have non-zero initializers
1619
.long 1

0 commit comments

Comments
 (0)