]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Adjust error message for initialized variable in .bss
authorEric Botcazou <ebotcazou@adacore.com>
Sun, 24 Nov 2024 14:15:54 +0000 (15:15 +0100)
committerEric Botcazou <ebotcazou@adacore.com>
Sun, 24 Nov 2024 19:23:25 +0000 (20:23 +0100)
The current message does not make sense with -fno-zero-initialized-in-bss.

gcc/
* doc/invoke.texi (-fno-zero-initialized-in-bss): Adjust for Ada.
* varasm.cc (get_variable_section): Adjust the error message for an
initialized variable in .bss to -fno-zero-initialized-in-bss.

gcc/testsuite/
* gnat.dg/specs/bss1.ads: New test.

gcc/doc/invoke.texi
gcc/testsuite/gnat.dg/specs/bss1.ads [new file with mode: 0644]
gcc/varasm.cc

index 44f0fd297b29e1c80877ba7ad616f763f86b3fb6..8141811b4531f96d20789708dc130206798b9452 100644 (file)
@@ -13068,7 +13068,7 @@ rely on variables going to the data section---e.g., so that the
 resulting executable can find the beginning of that section and/or make
 assumptions based on that.
 
-The default is @option{-fzero-initialized-in-bss}.
+The default is @option{-fzero-initialized-in-bss} except in Ada.
 
 @opindex fthread-jumps
 @item -fthread-jumps
diff --git a/gcc/testsuite/gnat.dg/specs/bss1.ads b/gcc/testsuite/gnat.dg/specs/bss1.ads
new file mode 100644 (file)
index 0000000..56f1802
--- /dev/null
@@ -0,0 +1,5 @@
+package Bss1 is
+
+  I : Integer := 0 with Linker_Section => ".bss"; -- { dg-error "no initializers" }
+
+end Bss1;
index acc4b4a0419420353326889bdc5c39bc478fda66..dd67dd441c0f5ee103eb7de47c8d0a4da88bfc57 100644 (file)
@@ -1264,9 +1264,14 @@ get_variable_section (tree decl, bool prefer_noswitch_p)
       if ((sect->common.flags & SECTION_BSS)
          && !bss_initializer_p (decl, true))
        {
-         error_at (DECL_SOURCE_LOCATION (decl),
-                   "only zero initializers are allowed in section %qs",
-                   sect->named.name);
+         if (flag_zero_initialized_in_bss)
+           error_at (DECL_SOURCE_LOCATION (decl),
+                     "only zero initializers are allowed in section %qs",
+                     sect->named.name);
+         else
+           error_at (DECL_SOURCE_LOCATION (decl),
+                     "no initializers are allowed in section %qs",
+                     sect->named.name);
          DECL_INITIAL (decl) = error_mark_node;
        }
       return sect;