[llvm] Warn on align directive with non-zero fill value in virtual sections (PR #66792)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 19 09:54:20 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mc
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/66792.diff
2 Files Affected:
- (modified) llvm/lib/MC/MCParser/AsmParser.cpp (+13-1)
- (modified) llvm/test/MC/ELF/nobits-non-zero-value.s (+3)
``````````diff
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index f70620c15a7ebb7..15ba96b84fa4701 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 16d386dc62ad549..8f37a957b6b56c0 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: <unknown>:0: error: SHT_NOBITS section '.bss' cannot have non-zero initializers
.long 1
``````````
</details>
https://github.com/llvm/llvm-project/pull/66792
More information about the llvm-commits
mailing list