[gcc r16-6670] Fix broken bootstrap on FreeBSD.

Thomas Koenig tkoenig@gcc.gnu.org
Fri Jan 9 21:03:48 GMT 2026


https://gcc.gnu.org/g:0a98b1a6ac91cb1aa0f89f7dcdb9c35daa88c2a1

commit r16-6670-g0a98b1a6ac91cb1aa0f89f7dcdb9c35daa88c2a1
Author: Thomas Koenig <tkoenig@gcc.gnu.org>
Date:   Fri Jan 9 22:00:07 2026 +0100

    Fix broken bootstrap on FreeBSD.
    
    As analyzed by Steve, on freebsd __gthread_t is a pointer type.
    I thought it the cleanest solution to remove the #ifdef in gfc_unit,
    make the "self" member a intptr_t and cast the return value of
    __gthread_t to that type.
    
    PR fortran/123512
    
    libgfortran/ChangeLog:
    
            * io/io.h: Change type of self to intptr_t.
            * io/async.h (LOCK_UNIT): Cast __gthread_self () to intptr_t.
            (TRYLOCK_UNIT): Likewise.
            (OWN_THREAD_ID): Likewise.

Diff:
---
 libgfortran/io/async.h | 16 ++++++++--------
 libgfortran/io/io.h    |  6 +-----
 2 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/libgfortran/io/async.h b/libgfortran/io/async.h
index c4451f28f318..596b6d6f5f71 100644
--- a/libgfortran/io/async.h
+++ b/libgfortran/io/async.h
@@ -248,7 +248,7 @@
 
 #define LOCK_UNIT(unit) do {		\
     LOCK (&(unit)->lock);		\
-    (unit)->self = __gthread_self ();	\
+    (unit)->self = (intptr_t) __gthread_self ();	\
   } while (0)
 
 #ifdef __GTHREAD_RWLOCK_INIT
@@ -390,11 +390,11 @@
    unlocking; the only use for this is checking for recursion.  */
 
 #define LOCK_UNIT(unit) do {					\
-  if (__gthread_active_p ()) {					\
-    LOCK (&(unit)->lock); (unit)->self = __gthread_self ();	\
-  } else {							\
-    (unit)->self = 1;						\
-  }								\
+    if (__gthread_active_p ()) {					\
+      LOCK (&(unit)->lock); (unit)->self = (intptr_t) __gthread_self (); \
+    } else {								\
+      (unit)->self = 1;							\
+    }									\
   } while(0)
 #else
 
@@ -430,7 +430,7 @@
       if (__gthread_active_p ()) {				\
 	res = __gthread_mutex_trylock (&(unit)->lock);		\
 	if (!res)						\
-	  (unit)->self = __gthread_self ();			\
+	  (unit)->self = (intptr_t) __gthread_self ();		\
       }								\
       else {							\
 	res = (unit)->self;					\
@@ -555,7 +555,7 @@ extern __thread gfc_unit *thread_unit;
    to be 1.  */
 
 #ifdef __GTHREADS_CXX0X
-#define OWN_THREAD_ID (__gthread_active_p () ? __gthread_self () : 1)
+#define OWN_THREAD_ID (__gthread_active_p () ? (intptr_t) __gthread_self () : 1)
 #else
 #define OWN_THREAD_ID 1
 #endif
diff --git a/libgfortran/io/io.h b/libgfortran/io/io.h
index ebb225296681..7928c196f63f 100644
--- a/libgfortran/io/io.h
+++ b/libgfortran/io/io.h
@@ -728,11 +728,7 @@ typedef struct gfc_unit
   int last_char;
   bool has_size;
   GFC_IO_INT size_used;
-#ifdef __GTHREADS_CXX0X
-  __gthread_t self;
-#else
-  int self;
-#endif
+  intptr_t self;
 }
 gfc_unit;


More information about the Gcc-cvs mailing list