Hi Joseph,
> On Wed, 19 Nov 2025, Rainer Orth wrote:
>
>> This patch fixes this by providing a Solaris definition instead. At the
>> same time, it introduces __PID_TYPE__ etc. macros matching e.g. wint_t
>> as well as two testcases.
>
> The point of those macros is for use in the implementation of <stdint.h>
> (because that's a header in the C standard that doesn't involve any
> library functions and so is provided by GCC). Since pid_t isn't part of
> ISO C, I don't think there's a good basis for adding such macros for pid_t
> to GCC. (Tests can use __typeof (__builtin_fork ()) or similar so
> __PID_TYPE__ shouldn't even be needed there.)
I see, that's what you get for blindly following an apparent pattern ;-(
However, I think find that defining __PID_TYPE__ alone is still useful
since it follows a well-known and easily understandable pattern, even if
its use is limited. This is what the following revision does, also
clarifying the context for __PID_TYPE__.
Rainer
---------------------------------------------------------------------------
The pid_t type on 32-bit Solaris differs from gcc's builtin.
<sys/types.h> has
#if defined(_LP64) || defined(_I32LPx)
typedef int pid_t; /* process id type */
#else
typedef long pid_t; /* (historical version) */
#endif
while gcc/defaults.h uses
#define PID_TYPE "int"
on all targets.
This patch fixes this by providing a Solaris definition instead. At the
same time, it introduces the __PID_TYPE__ macro matching e.g. wint_t,
as well as two testcases.
g++.dg/lookup/extern-c-redecl3.C had to be adjusted to use the new
__PID_TYPE__.
Bootstrapped without regressions on i386-pc-solaris2.11,
sparc-sun-solaris2.11, and x86_64-pc-linux-gnu.
Ok for trunk?
--
-----------------------------------------------------------------------------
Rainer Orth, Center for Biotechnology, Bielefeld University
2025-11-17 Rainer Orth <[email protected]>
gcc:
* config/sol2.h (PID_TYPE): Define.
* doc/cpp.texi (Common Predefined Macros): Document __PID_TYPE__
* doc/tm.texi.in (Type Layout): Document PID_TYPE.
* doc/tm.texi: Regenerate.
gcc/c-family:
* c-common.cc (c_stddef_cpp_builtins): Define __PID_TYPE__.
gcc/testsuite:
* g++.dg/lookup/extern-c-redecl3.C (fork): Use __PID_TYPE__
instead of int.
* g++.dg/pid_t-1.C: New test.
* gcc.dg/pid_t-1.c: Likewise.
# HG changeset patch
# Parent 9ed30cd47175d118e003ba3371e374c982e225e5
Fix PID_TYPE on Solaris
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -5637,6 +5637,9 @@ c_stddef_cpp_builtins(void)
Expose it as __SIZETYPE__. */
if (flag_gimple)
builtin_define_with_value ("__SIZETYPE__", SIZETYPE, 0);
+ /* Similarly for the GCC internal definition of 'pid_t'. */
+ if (PID_TYPE)
+ builtin_define_with_value ("__PID_TYPE__", PID_TYPE, 0);
}
static void
diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h
--- a/gcc/config/sol2.h
+++ b/gcc/config/sol2.h
@@ -41,6 +41,12 @@ along with GCC; see the file COPYING3.
#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
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
--- a/gcc/doc/cpp.texi
+++ b/gcc/doc/cpp.texi
@@ -2127,6 +2127,7 @@ OSF/rose @option{-mno-underscores} optio
@itemx __UINT_FAST64_TYPE__
@itemx __INTPTR_TYPE__
@itemx __UINTPTR_TYPE__
+@itemx __PID_TYPE__
These macros are defined to the correct underlying types for the
@code{size_t}, @code{ptrdiff_t}, @code{wchar_t}, @code{wint_t},
@code{intmax_t}, @code{uintmax_t}, @code{sig_atomic_t}, @code{int8_t},
@@ -2140,6 +2141,7 @@ These macros are defined to the correct
@code{uint_fast64_t}, @code{intptr_t}, and @code{uintptr_t} typedefs,
respectively. They exist to make the standard header files
@file{stddef.h}, @file{stdint.h}, and @file{wchar.h} work correctly.
+@code{__PID_TYPE__} reflects the built-in definition of @code{pid_t}.
You should not use these macros directly; instead, include the
appropriate headers and use the typedefs. Some of these macros may
not be defined on particular systems if GCC does not provide a
diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi
--- a/gcc/doc/tm.texi
+++ b/gcc/doc/tm.texi
@@ -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 @co
@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
diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in
--- a/gcc/doc/tm.texi.in
+++ b/gcc/doc/tm.texi.in
@@ -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 @co
@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
diff --git a/gcc/testsuite/g++.dg/lookup/extern-c-redecl3.C b/gcc/testsuite/g++.dg/lookup/extern-c-redecl3.C
--- a/gcc/testsuite/g++.dg/lookup/extern-c-redecl3.C
+++ b/gcc/testsuite/g++.dg/lookup/extern-c-redecl3.C
@@ -5,17 +5,17 @@
// { 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);
+extern "C" __PID_TYPE__ fork (void);
void
foo ()
{
- extern int fork (void);
+ extern __PID_TYPE__ fork (void);
fork ();
}
extern "C"
-int
+__PID_TYPE__
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
--- /dev/null
+++ b/gcc/testsuite/g++.dg/pid_t-1.C
@@ -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
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pid_t-1.c
@@ -0,0 +1,17 @@
+/* { 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>
+
+__PID_TYPE__ __p_t__;
+pid_t *p_t_p;
+
+void
+pt (void)
+{
+ p_t_p = &__p_t__;
+}