[PATCH v4 10/12] RISC-V/gas: warn about non-power-of-2 stack-align attribute

Jan Beulich <[email protected]> Fri, 24 Jul 2026 12:06:03 +0200
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
Only power-of-2 values are sensible for alignment.

Reviewed-by: Jiawei <[email protected]>
---
Should we reject changing an already set non-zero value, like
riscv_merge_attributes() does?

Should we permit 0 as an explicit indication of "attribute not set"?
---
v2: New.

--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -6137,6 +6137,13 @@ s_riscv_attribute (int ignored ATTRIBUTE
 		   "any instructions"));
       break;
 
+    case Tag_RISCV_stack_align:
+      if (!attr[Tag_RISCV_stack_align].i
+	  || (attr[Tag_RISCV_stack_align].i &
+	      (attr[Tag_RISCV_stack_align].i - 1)))
+	as_warn (_("`stack_align' attribute with non-power-of-2 value"));
+      break;
+
     case Tag_RISCV_unaligned_access:
       if (attr[Tag_RISCV_unaligned_access].i > 1)
 	as_warn (_("`unaligned_access' attribute with non-boolean value"));
--- a/gas/testsuite/gas/riscv/attribute-warn.d
+++ b/gas/testsuite/gas/riscv/attribute-warn.d
@@ -4,4 +4,5 @@
 
 Attribute Section: riscv
 File Attributes
+  Tag_RISCV_stack_align: 65536-bytes
   Tag_RISCV_arch: [a-zA-Z0-9_\"].*
--- a/gas/testsuite/gas/riscv/attribute-warn.l
+++ b/gas/testsuite/gas/riscv/attribute-warn.l
@@ -1,2 +1,4 @@
 .*: Assembler messages:
 .*:2: Warning: `unaligned_access' attribute with non-boolean value
+.*:5: Warning: `stack_align' attribute with non-power-of-2 value
+.*:6: Warning: `stack_align' attribute with non-power-of-2 value
--- a/gas/testsuite/gas/riscv/attribute-warn.s
+++ b/gas/testsuite/gas/riscv/attribute-warn.s
@@ -1,3 +1,7 @@
 	.attribute unaligned_access, 1
 	.attribute unaligned_access, 0x1234
 	.attribute unaligned_access, 0
+
+	.attribute stack_align, 0
+	.attribute stack_align, 0x4444
+	.attribute stack_align, 0x10000