]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix PID_TYPE on 32-bit Solaris
authorRainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Wed, 10 Dec 2025 08:05:55 +0000 (09:05 +0100)
committerRainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Wed, 10 Dec 2025 08:05:55 +0000 (09:05 +0100)
The pid_t type on 32-bit Solaris differs from gcc's builtin.

<sys/types.h> has

typedef int pid_t; /* process id type */
typedef long pid_t; /* (historical version) */

while gcc/defaults.h uses

on all targets.

This patch fixes this by providing a Solaris definition.
g++.dg/lookup/extern-c-redecl3.C had to be adjusted accordingly.

Bootstrapped without regressions on i386-pc-solaris2.11,
sparc-sun-solaris2.11, and x86_64-pc-linux-gnu.

2025-11-17  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

gcc:
* config/sol2.h (PID_TYPE): Define.
* doc/tm.texi.in (Type Layout): Document PID_TYPE.
* doc/tm.texi: Regenerate.

gcc/testsuite:
* g++.dg/lookup/extern-c-redecl3.C (pid_t): Define.
Use it for fork return type.
terms of __builtin_fork.
* g++.dg/pid_t-1.C: New test.
* gcc.dg/pid_t-1.c: Likewise.

gcc/config/sol2.h
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/testsuite/g++.dg/lookup/extern-c-redecl3.C
gcc/testsuite/g++.dg/pid_t-1.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/pid_t-1.c [new file with mode: 0644]

index 4e3199d2c8c8be671a4b8bbfe5aa42e9b1066213..026d363ff6bbe1f325ca50d129400f86ef491fa1 100644 (file)
@@ -41,6 +41,12 @@ along with GCC; see the file COPYING3.  If not see
 #undef WINT_TYPE_SIZE
 #define WINT_TYPE_SIZE 32
 
+/* Same for pid_t.  See SCD 2.4.2, p. 6P-12, Figure 6-59 (64-bit).  There's
+   no corresponding 32-bit definition, but this is what Solaris 8
+   <sys/types.h> uses.  */
+
+#define PID_TYPE (TARGET_64BIT ? "int" : "long int")
+
 #define SIG_ATOMIC_TYPE "int"
 
 /* ??? This definition of int8_t follows the system header but does
index 25aad2eb74b6c3bedb5d527c6bfe216347d48a01..bbb1182117daabeab9b3bfe5066d0a43c2bbb618 100644 (file)
@@ -1825,6 +1825,7 @@ int}.
 @defmacx UINT_FAST64_TYPE
 @defmacx INTPTR_TYPE
 @defmacx UINTPTR_TYPE
+@defmacx PID_TYPE
 C expressions for the standard types @code{sig_atomic_t},
 @code{int8_t}, @code{int16_t}, @code{int32_t}, @code{int64_t},
 @code{uint8_t}, @code{uint16_t}, @code{uint32_t}, @code{uint64_t},
@@ -1833,8 +1834,8 @@ C expressions for the standard types @code{sig_atomic_t},
 @code{uint_least32_t}, @code{uint_least64_t}, @code{int_fast8_t},
 @code{int_fast16_t}, @code{int_fast32_t}, @code{int_fast64_t},
 @code{uint_fast8_t}, @code{uint_fast16_t}, @code{uint_fast32_t},
-@code{uint_fast64_t}, @code{intptr_t}, and @code{uintptr_t}.  See
-@code{SIZE_TYPE} above for more information.
+@code{uint_fast64_t}, @code{intptr_t}, and @code{uintptr_t} and the
+built-in type @code{pid_t}.  See @code{SIZE_TYPE} above for more information.
 
 If any of these macros evaluates to a null pointer, the corresponding
 type is not supported; if GCC is configured to provide
index 24d47b19e5f13e15f9d0b0e9c0b343825ce6e761..253965bdafc2ac7030a1810ed16115bffbd526c1 100644 (file)
@@ -1553,6 +1553,7 @@ int}.
 @defmacx UINT_FAST64_TYPE
 @defmacx INTPTR_TYPE
 @defmacx UINTPTR_TYPE
+@defmacx PID_TYPE
 C expressions for the standard types @code{sig_atomic_t},
 @code{int8_t}, @code{int16_t}, @code{int32_t}, @code{int64_t},
 @code{uint8_t}, @code{uint16_t}, @code{uint32_t}, @code{uint64_t},
@@ -1561,8 +1562,8 @@ C expressions for the standard types @code{sig_atomic_t},
 @code{uint_least32_t}, @code{uint_least64_t}, @code{int_fast8_t},
 @code{int_fast16_t}, @code{int_fast32_t}, @code{int_fast64_t},
 @code{uint_fast8_t}, @code{uint_fast16_t}, @code{uint_fast32_t},
-@code{uint_fast64_t}, @code{intptr_t}, and @code{uintptr_t}.  See
-@code{SIZE_TYPE} above for more information.
+@code{uint_fast64_t}, @code{intptr_t}, and @code{uintptr_t} and the
+built-in type @code{pid_t}.  See @code{SIZE_TYPE} above for more information.
 
 If any of these macros evaluates to a null pointer, the corresponding
 type is not supported; if GCC is configured to provide
index 56dcefa7670ece12ec6f8ff95f9677c3ec989764..c9c9bd5ba2ee685360eedb682a41343d000f6594 100644 (file)
@@ -5,17 +5,19 @@
 // { dg-final { scan-assembler-not "call\[\t \]+\[^\$\]*?_Z4forkv" { target i?86-*-* x86_64-*-* } } }
 // { dg-final { scan-assembler "call\[\t \]+_?fork" { target i?86-*-* x86_64-*-* } } }
 
-extern "C" int fork (void);
+typedef __typeof (__builtin_fork ()) pid_t;
+
+extern "C" pid_t fork (void);
 
 void
 foo ()
 {
-  extern int fork (void);
+  extern pid_t fork (void);
   fork ();
 }
 
 extern "C"
-int
+pid_t
 fork (void)
 {
   return 0;
diff --git a/gcc/testsuite/g++.dg/pid_t-1.C b/gcc/testsuite/g++.dg/pid_t-1.C
new file mode 100644 (file)
index 0000000..cb32eb4
--- /dev/null
@@ -0,0 +1,3 @@
+/* { dg-options "-Wall" } */
+
+extern "C" int fork (void); // { dg-warning "conflicts with built-in declaration" "" { target { *-*-solaris2* && ilp32 } } }
diff --git a/gcc/testsuite/gcc.dg/pid_t-1.c b/gcc/testsuite/gcc.dg/pid_t-1.c
new file mode 100644 (file)
index 0000000..f4f3f68
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+/* { dg-require-fork "" } */
+
+/* Compile with -Wall to get a warning if built-in and system pid_t don't
+   match.  */
+
+#include <sys/types.h>
+
+typedef __typeof (__builtin_fork ()) __builtin_pid_t;
+
+__builtin_pid_t __p_t__;
+pid_t *p_t_p;
+
+void
+pt (void)
+{
+  p_t_p = &__p_t__;
+}