]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Do not register nullptr_t built-in type [PR114869]
authorJoseph Myers <josmyers@redhat.com>
Tue, 19 Nov 2024 21:31:24 +0000 (21:31 +0000)
committerJoseph Myers <josmyers@redhat.com>
Tue, 19 Nov 2024 21:31:24 +0000 (21:31 +0000)
As reported in bug 114869, the C front end wrongly creates nullptr_t
as a built-in typedef; it should only be defined in <stddef.h>.  While
the type node needs a name for debug info generation, it doesn't need
to be a valid identifier; use typeof (nullptr) instead, similar to how
the C++ front end uses decltype(nullptr) for this purpose.

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

PR c/114869

gcc/c/
* c-decl.cc (c_init_decl_processing): Register nullptr_type_node
as typeof (nullptr) not nullptr_t.

gcc/testsuite/
* gcc.dg/c23-nullptr-5.c: Use typeof (nullptr) not nullptr_t.
* gcc.dg/c11-nullptr-2.c, gcc.dg/c11-nullptr-3.c,
gcc.dg/c23-nullptr-7.c: New tests

gcc/c/c-decl.cc
gcc/testsuite/gcc.dg/c11-nullptr-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c11-nullptr-3.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c23-nullptr-5.c
gcc/testsuite/gcc.dg/c23-nullptr-7.c [new file with mode: 0644]

index 1128d72ccb03d8e40095b71469c7fc0c396d3a85..96bfe9290fd9b501886e8936e64063e42078c6c8 100644 (file)
@@ -4799,7 +4799,7 @@ c_init_decl_processing (void)
                        boolean_type_node));
 
   /* C-specific nullptr initialization.  */
-  record_builtin_type (RID_MAX, "nullptr_t", nullptr_type_node);
+  record_builtin_type (RID_MAX, "typeof (nullptr)", nullptr_type_node);
   /* The size and alignment of nullptr_t is the same as for a pointer to
      character type.  */
   SET_TYPE_ALIGN (nullptr_type_node, GET_MODE_ALIGNMENT (ptr_mode));
diff --git a/gcc/testsuite/gcc.dg/c11-nullptr-2.c b/gcc/testsuite/gcc.dg/c11-nullptr-2.c
new file mode 100644 (file)
index 0000000..3b37b11
--- /dev/null
@@ -0,0 +1,5 @@
+/* Test there is no nullptr_t built-in typedef.  Bug 114869.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+int nullptr_t;
diff --git a/gcc/testsuite/gcc.dg/c11-nullptr-3.c b/gcc/testsuite/gcc.dg/c11-nullptr-3.c
new file mode 100644 (file)
index 0000000..5abb082
--- /dev/null
@@ -0,0 +1,7 @@
+/* Test there is no nullptr_t in <stddef.h> for C11.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c11 -pedantic-errors" } */
+
+#include <stddef.h>
+
+int nullptr_t;
index 54266af70fb3c5009d14ed79d3a1af4776fdc440..f708ec2cfc088448a99a78d471525f36293015e4 100644 (file)
@@ -3,7 +3,7 @@
 /* { dg-options "-std=c23 -pedantic-errors" } */
 
 int i;
-nullptr_t fn () { ++i; return nullptr; }
+typeof (nullptr) fn () { ++i; return nullptr; }
 
 int
 main ()
diff --git a/gcc/testsuite/gcc.dg/c23-nullptr-7.c b/gcc/testsuite/gcc.dg/c23-nullptr-7.c
new file mode 100644 (file)
index 0000000..2692e30
--- /dev/null
@@ -0,0 +1,5 @@
+/* Test there is no nullptr_t built-in typedef.  Bug 114869.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -pedantic-errors" } */
+
+int nullptr_t;