]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Use bool rather than _Bool in debug info and diagnostics for C23 and later [PR125935]
authorJakub Jelinek <jakub@redhat.com>
Tue, 30 Jun 2026 07:24:56 +0000 (09:24 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 30 Jun 2026 07:24:56 +0000 (09:24 +0200)
In C23, the primary boolean spelling is bool rather than _Bool, which is
just a backward compatibility thing.
So, we shouldn't spell the type as _Bool in debug info (and in diagnostics)
but as bool.
Obviously, for C17 and earlier it should be _Bool.

The following patch does that.

2026-06-30  Jakub Jelinek  <jakub@redhat.com>

PR c/125935
* c-decl.cc (c_init_decl_processing): Use "bool" rather than "_Bool"
as the name of boolean_type_node for C23+.

* gcc.dg/debug/dwarf2/pr125935-1.c: New test.
* gcc.dg/debug/dwarf2/pr125935-2.c: New test.
* gcc.dg/debug/dwarf2/pr125935-3.c: New test.
* gcc.dg/debug/ctf/ctf-bitfields-3.c: Expect bool rather than _Bool.
* gcc.dg/Warray-bounds-65.c: Expect bool in diagnostics instead of
_Bool.
* gcc.dg/Wbad-function-cast-1.c: Likewise.

Reviewed-by: Jeffrey Law <jeffrey.law@oss.qualcomm.com>
gcc/c/c-decl.cc
gcc/testsuite/gcc.dg/Warray-bounds-65.c
gcc/testsuite/gcc.dg/Wbad-function-cast-1.c
gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-3.c
gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-3.c [new file with mode: 0644]

index 286d29405a30c7f1c237e6889e118a6a7fafd3ff..4dc1e94394bc098272e9c47ea36a6e5c84c50ca9 100644 (file)
@@ -4957,7 +4957,8 @@ c_init_decl_processing (void)
   truthvalue_false_node = integer_zero_node;
 
   /* Even in C99, which has a real boolean type.  */
-  pushdecl (build_decl (UNKNOWN_LOCATION, TYPE_DECL, get_identifier ("_Bool"),
+  pushdecl (build_decl (UNKNOWN_LOCATION, TYPE_DECL,
+                       get_identifier (flag_isoc23 ? "bool" : "_Bool"),
                        boolean_type_node));
 
   /* C-specific nullptr initialization.  */
index 6bd50d0f8764db1c767ae7f97a95aa95d6ccd3de..46180f15387a0f23201cc8998631d406f82f7f7a 100644 (file)
@@ -31,11 +31,11 @@ test_note (int (*pia3)[3])    // { dg-message "while referencing 'pia3'" }
 void test_a1_cst (_Bool (*pba0)[0], char (*pca1)[1],
                  short (*psa2)[2], int (*pia3)[3])
 {
-  T ((*pba0)[-1]);            // { dg-warning "array subscript -1 is (above|outside) array bounds of '_Bool\\\[0]'" }
-  T ((*pba0)[0]);             // { dg-warning "array subscript 0 is (above|outside) array bounds of '_Bool\\\[0]'" }
-  T ((*pba0)[1]);             // { dg-warning "array subscript 1 is (above|outside) array bounds of '_Bool\\\[0]'" }
-  T ((*pba0)[2]);             // { dg-warning "array subscript 2 is (above|outside) array bounds of '_Bool\\\[0]'" }
-  T ((*pba0)[12]);            // { dg-warning "array subscript 12 is (above|outside) array bounds of '_Bool\\\[0]'" }
+  T ((*pba0)[-1]);            // { dg-warning "array subscript -1 is (above|outside) array bounds of 'bool\\\[0]'" }
+  T ((*pba0)[0]);             // { dg-warning "array subscript 0 is (above|outside) array bounds of 'bool\\\[0]'" }
+  T ((*pba0)[1]);             // { dg-warning "array subscript 1 is (above|outside) array bounds of 'bool\\\[0]'" }
+  T ((*pba0)[2]);             // { dg-warning "array subscript 2 is (above|outside) array bounds of 'bool\\\[0]'" }
+  T ((*pba0)[12]);            // { dg-warning "array subscript 12 is (above|outside) array bounds of 'bool\\\[0]'" }
 
   T ((*pca1)[-1]);            // { dg-warning "array subscript -1 is (below|outside) array bounds of 'char\\\[1]'" }
   T ((*pca1)[0]);
@@ -61,20 +61,20 @@ void test_a1_cst (_Bool (*pba0)[0], char (*pca1)[1],
 void test_a2_cst (_Bool (*pba0_1)[0][1], char (*pca1_2)[1][2],
                  short (*psa2_3)[2][3], int (*pia3_4)[3][4])
 {
-  T ((*pba0_1)[-1][-1]);        // { dg-warning "array subscript -1 is (below|outside) array bounds of '_Bool\\\[1]'" }
-  T ((*pba0_1)[-1][0]);         // { dg-warning "array subscript -1 is (above|outside) array bounds of '_Bool\\\[0]\\\[1]'" }
-
-  T ((*pba0_1)[0][-1]);         // { dg-warning "array subscript -1 is (below|outside) array bounds of '_Bool\\\[1]'" }
-  T ((*pba0_1)[0][0]);          // { dg-warning "array subscript 0 is (above|outside) array bounds of '_Bool\\\[0]\\\[1]'" }
-  T ((*pba0_1)[0][1]);          // { dg-warning "array subscript 1 is (above|outside) array bounds of '_Bool\\\[1]'" }
-  T ((*pba0_1)[0][2]);          // { dg-warning "array subscript 2 is (above|outside) array bounds of '_Bool\\\[1]'" }
-  T ((*pba0_1)[0][12]);         // { dg-warning "array subscript 12 is (above|outside) array bounds of '_Bool\\\[1]'" }
-
-  T ((*pba0_1)[1][-1]);         // { dg-warning "array subscript -1 is (below|outside) array bounds of '_Bool\\\[1]'" }
-  T ((*pba0_1)[1][0]);          // { dg-warning "array subscript 1 is (above|outside) array bounds of '_Bool\\\[0]\\\[1]'" }
-  T ((*pba0_1)[1][1]);          // { dg-warning "array subscript 1 is (above|outside) array bounds of '_Bool\\\[1]'" }
-  T ((*pba0_1)[1][2]);          // { dg-warning "array subscript 2 is (above|outside) array bounds of '_Bool\\\[1]'" }
-  T ((*pba0_1)[1][12]);         // { dg-warning "array subscript 12 is (above|outside) array bounds of '_Bool\\\[1]'" }
+  T ((*pba0_1)[-1][-1]);        // { dg-warning "array subscript -1 is (below|outside) array bounds of 'bool\\\[1]'" }
+  T ((*pba0_1)[-1][0]);         // { dg-warning "array subscript -1 is (above|outside) array bounds of 'bool\\\[0]\\\[1]'" }
+
+  T ((*pba0_1)[0][-1]);         // { dg-warning "array subscript -1 is (below|outside) array bounds of 'bool\\\[1]'" }
+  T ((*pba0_1)[0][0]);          // { dg-warning "array subscript 0 is (above|outside) array bounds of 'bool\\\[0]\\\[1]'" }
+  T ((*pba0_1)[0][1]);          // { dg-warning "array subscript 1 is (above|outside) array bounds of 'bool\\\[1]'" }
+  T ((*pba0_1)[0][2]);          // { dg-warning "array subscript 2 is (above|outside) array bounds of 'bool\\\[1]'" }
+  T ((*pba0_1)[0][12]);         // { dg-warning "array subscript 12 is (above|outside) array bounds of 'bool\\\[1]'" }
+
+  T ((*pba0_1)[1][-1]);         // { dg-warning "array subscript -1 is (below|outside) array bounds of 'bool\\\[1]'" }
+  T ((*pba0_1)[1][0]);          // { dg-warning "array subscript 1 is (above|outside) array bounds of 'bool\\\[0]\\\[1]'" }
+  T ((*pba0_1)[1][1]);          // { dg-warning "array subscript 1 is (above|outside) array bounds of 'bool\\\[1]'" }
+  T ((*pba0_1)[1][2]);          // { dg-warning "array subscript 2 is (above|outside) array bounds of 'bool\\\[1]'" }
+  T ((*pba0_1)[1][12]);         // { dg-warning "array subscript 12 is (above|outside) array bounds of 'bool\\\[1]'" }
 
 
   T ((*pca1_2)[0][0]);
index 4a0547f0b529998f36a45411127d69fe04c6d162..9e0bcaf684f48c7dc42a6f0fe87adb253bf0b918 100644 (file)
@@ -40,12 +40,12 @@ foo(void)
      types.  */
   (float)if1(); /* { dg-warning "cast from function call of type 'int' to non-matching type 'float'" } */
   (double)if2(); /* { dg-warning "cast from function call of type 'char' to non-matching type 'double'" } */
-  (_Bool)if3(); /* { dg-warning "cast from function call of type 'long int' to non-matching type '_Bool'" } */
+  (_Bool)if3(); /* { dg-warning "cast from function call of type 'long int' to non-matching type 'bool'" } */
   (int)rf1(); /* { dg-warning "cast from function call of type 'float' to non-matching type 'int'" } */
   (long)rf2(); /* { dg-warning "cast from function call of type 'double' to non-matching type 'long int'" } */
   (double)cf(); /* { dg-warning "cast from function call of type 'complex double' to non-matching type 'double'" } */
   (int)ef(); /* { dg-warning "cast from function call of type 'enum e' to non-matching type 'int'" } */
-  (int)bf(); /* { dg-warning "cast from function call of type '_Bool' to non-matching type 'int'" } */
+  (int)bf(); /* { dg-warning "cast from function call of type 'bool' to non-matching type 'int'" } */
   (__SIZE_TYPE__)pf1(); /* { dg-warning "cast from function call of type 'char \\*' to non-matching type '\[^\\n\]*'" } */
   (__PTRDIFF_TYPE__)pf2(); /* { dg-warning "cast from function call of type 'int \\*' to non-matching type '\[^\\n\]*'" } */
 }
index 411040db88fd07914187eef8854ec715d1d73992..5d989f26966a30baac75dfe37537108b34591f9a 100644 (file)
@@ -6,7 +6,7 @@
 /* { dg-final { scan-assembler-times "\[\t \]0x2\[\t \]+\[^\n\]*cts_type" 2 } } */
 /* { dg-final { scan-assembler-times "\[\t \]0x1\[\t \]+\[^\n\]*cts_bits" 2 } } */
 
-/* { dg-final { scan-assembler-times "ascii \"_Bool.0\"\[\t \]+\[^\n\]*ctf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"bool.0\"\[\t \]+\[^\n\]*ctf_string" 1 } } */
 
 #include <stdbool.h>
 
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-1.c b/gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-1.c
new file mode 100644 (file)
index 0000000..2bcb8fb
--- /dev/null
@@ -0,0 +1,8 @@
+/* PR c/125935 */
+/* { dg-do compile } */
+/* { dg-options "-std=c17 -g -dA" } */
+
+_Bool x;
+
+/* { dg-final { scan-assembler-times "(DW_AT_name: \"_Bool\"|\"_Bool..\"\[^\\r\\n\]*DW_AT_name)" 1 } } */
+/* { dg-final { scan-assembler-not "(DW_AT_name: \"bool\"|\"bool..\"\[^\\r\\n\]*DW_AT_name)" } } */
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-2.c b/gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-2.c
new file mode 100644 (file)
index 0000000..0a8ff39
--- /dev/null
@@ -0,0 +1,8 @@
+/* PR c/125935 */
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -g -dA" } */
+
+_Bool x;
+
+/* { dg-final { scan-assembler-not "(DW_AT_name: \"_Bool\"|\"_Bool..\"\[^\\r\\n\]*DW_AT_name)" } } */
+/* { dg-final { scan-assembler-times "(DW_AT_name: \"bool\"|\"bool..\"\[^\\r\\n\]*DW_AT_name)" 1 } } */
diff --git a/gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-3.c b/gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-3.c
new file mode 100644 (file)
index 0000000..e8d540e
--- /dev/null
@@ -0,0 +1,8 @@
+/* PR c/125935 */
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -g -dA" } */
+
+bool x;
+
+/* { dg-final { scan-assembler-not "(DW_AT_name: \"_Bool\"|\"_Bool..\"\[^\\r\\n\]*DW_AT_name)" } } */
+/* { dg-final { scan-assembler-times "(DW_AT_name: \"bool\"|\"bool..\"\[^\\r\\n\]*DW_AT_name)" 1 } } */