https://gcc.gnu.org/g:510c4a8167db0e021aa4dd381e1dd1dae8412054

commit r17-1996-g510c4a8167db0e021aa4dd381e1dd1dae8412054
Author: Jakub Jelinek <[email protected]>
Date:   Tue Jun 30 09:24:56 2026 +0200

    c: Use bool rather than _Bool in debug info and diagnostics for C23 and 
later [PR125935]
    
    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  <[email protected]>
    
            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 <[email protected]>

Diff:
---
 gcc/c/c-decl.cc                                  |  3 +-
 gcc/testsuite/gcc.dg/Warray-bounds-65.c          | 38 ++++++++++++------------
 gcc/testsuite/gcc.dg/Wbad-function-cast-1.c      |  4 +--
 gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-3.c |  2 +-
 gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-1.c   |  8 +++++
 gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-2.c   |  8 +++++
 gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-3.c   |  8 +++++
 7 files changed, 48 insertions(+), 23 deletions(-)

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 286d29405a30..4dc1e94394bc 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -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.  */
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-65.c 
b/gcc/testsuite/gcc.dg/Warray-bounds-65.c
index 6bd50d0f8764..46180f15387a 100644
--- a/gcc/testsuite/gcc.dg/Warray-bounds-65.c
+++ b/gcc/testsuite/gcc.dg/Warray-bounds-65.c
@@ -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]);
diff --git a/gcc/testsuite/gcc.dg/Wbad-function-cast-1.c 
b/gcc/testsuite/gcc.dg/Wbad-function-cast-1.c
index 4a0547f0b529..9e0bcaf684f4 100644
--- a/gcc/testsuite/gcc.dg/Wbad-function-cast-1.c
+++ b/gcc/testsuite/gcc.dg/Wbad-function-cast-1.c
@@ -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\]*'" } */
 }
diff --git a/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-3.c 
b/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-3.c
index 411040db88fd..5d989f26966a 100644
--- a/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-3.c
+++ b/gcc/testsuite/gcc.dg/debug/ctf/ctf-bitfields-3.c
@@ -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
index 000000000000..2bcb8fb2a83d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-1.c
@@ -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
index 000000000000..0a8ff39b83f6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-2.c
@@ -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
index 000000000000..e8d540e37cc7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/debug/dwarf2/pr125935-3.c
@@ -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 } } */

Reply via email to