[llvm] Fix warning on align directives with non-zero fill value (PR #67237)

via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 23 06:04:53 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mc

<details>
<summary>Changes</summary>

The original patch (PR #<!-- -->66792) did not properly check the non-zero fill value condition. This patch adds a new test case to ensure the overly aggressive check does not return.


---
Full diff: https://github.com/llvm/llvm-project/pull/67237.diff


2 Files Affected:

- (modified) llvm/lib/MC/MCParser/AsmParser.cpp (+1-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 15ba96b84fa4701..b36c5f067a95392 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -3452,7 +3452,7 @@ bool AsmParser::parseDirectiveAlign(bool IsPow2, unsigned ValueSize) {
     }
   }
 
-  if (HasFillExpr) {
+  if (HasFillExpr && FillExpr != 0) {
     MCSection *Sec = getStreamer().getCurrentSectionOnly();
     if (Sec && Sec->isVirtualSection()) {
       ReturnVal |=
diff --git a/llvm/test/MC/ELF/nobits-non-zero-value.s b/llvm/test/MC/ELF/nobits-non-zero-value.s
index 8f37a957b6b56c0..9b2bea6278e6955 100644
--- a/llvm/test/MC/ELF/nobits-non-zero-value.s
+++ b/llvm/test/MC/ELF/nobits-non-zero-value.s
@@ -15,5 +15,8 @@
 # CHECK: {{.*}}.s:[[#@LINE+1]]:11: warning: ignoring non-zero fill value in SHT_NOBITS section '.bss'
 .align 4, 42
 
+# CHECK-NOT: {{.*}}.s:[[#@LINE+1]]:11: warning: ignoring non-zero fill value in SHT_NOBITS section '.bss'
+.align 4, 0
+
 # CHECK: <unknown>:0: error: SHT_NOBITS section '.bss' cannot have non-zero initializers
   .long 1

``````````

</details>


https://github.com/llvm/llvm-project/pull/67237


More information about the llvm-commits mailing list