https://gcc.gnu.org/g:dd03e12a3f8f17f4ca60d2e1d9c3cac8106c2dc8

commit r17-2431-gdd03e12a3f8f17f4ca60d2e1d9c3cac8106c2dc8
Author: John David Anglin <[email protected]>
Date:   Wed Jul 15 18:47:26 2026 -0400

    libgfortran: Define macro to handle z length modifier in format strings
    
    hppa64-hp-hpux* lacks the z length modifier.  It specifies the following
    integer conversion corresponds to a size_t or a ssize_t argument.  The
    size_t type is unsigned long on HP-UX, so we can replace the z length
    modifier with l on HP-UX.
    
    2026-06-10  John David Anglin  <[email protected]>
    
    libgfortran/ChangeLog:
    
            * libgfortran.h (FMT_Z): Define.
            * caf/shmem/alloc.c (get_memory_by_id_internal): Use FMT_Z.
            (alloc_free_memory_with_id): Likewise.
            * caf/shmem/supervisor.c (get_memory_size_from_envvar): Likewise.
            * caf/shmem/thread_support.c (get_handle): Likewise.
            (thread_support_init_supervisor): Likewise.
            * intrinsics/reduce.c (reduce): Likewise.

Diff:
---
 libgfortran/caf/shmem/alloc.c          | 5 +++--
 libgfortran/caf/shmem/supervisor.c     | 2 +-
 libgfortran/caf/shmem/thread_support.c | 9 +++++----
 libgfortran/intrinsics/reduce.c        | 2 +-
 libgfortran/libgfortran.h              | 8 ++++++++
 5 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/libgfortran/caf/shmem/alloc.c b/libgfortran/caf/shmem/alloc.c
index 4fc2307ffec8..adbab848bd27 100644
--- a/libgfortran/caf/shmem/alloc.c
+++ b/libgfortran/caf/shmem/alloc.c
@@ -85,7 +85,7 @@ get_memory_by_id_internal (alloc *iface, size_t size, memid 
id, bool *created)
        {
          allocator_unlock (&iface->alloc);
          caf_runtime_error (
-           "Size mismatch for coarray allocation id %zd: found = %lu "
+           "Size mismatch for coarray allocation id %" FLM_Z "d: found = %lu "
            "< size = %lu\n",
            id, found_size, size);
          return NULL; // The runtime_error exit()s, so this is never reached.
@@ -144,7 +144,8 @@ alloc_free_memory_with_id (alloc *iface, memid id)
   if (!hm_search_result_contains (&res))
     {
       allocator_unlock (&iface->alloc);
-      caf_runtime_error ("Error in free_memory_with_id: %zd not found.\n", id);
+      caf_runtime_error ("Error in free_memory_with_id: %" FLM_Z
+                        "d not found.\n", id);
       return;
     }
 
diff --git a/libgfortran/caf/shmem/supervisor.c 
b/libgfortran/caf/shmem/supervisor.c
index a33b46ecf542..0836b89d99f9 100644
--- a/libgfortran/caf/shmem/supervisor.c
+++ b/libgfortran/caf/shmem/supervisor.c
@@ -106,7 +106,7 @@ get_memory_size_from_envvar (void)
     {
       char suffix[2];
       int rv;
-      rv = sscanf (e, "%zu%1s", &sz, suffix);
+      rv = sscanf (e, "%" FLM_Z "u%1s", &sz, suffix);
       if (rv == 2)
        {
          switch (suffix[0])
diff --git a/libgfortran/caf/shmem/thread_support.c 
b/libgfortran/caf/shmem/thread_support.c
index 0c5f8cc2763f..dc907c95b0ab 100755
--- a/libgfortran/caf/shmem/thread_support.c
+++ b/libgfortran/caf/shmem/thread_support.c
@@ -122,7 +122,8 @@ get_handle (const size_t id, const char t)
 
       if (!pid)
        pid = shared_memory_get_env ();
-      snprintf (name, MAX_PATH, "Global_gfortran-%s-%c-%zd", pid, t, id);
+      snprintf (name, MAX_PATH, "Global_gfortran-%s-%c-%" FLM_Z "d",
+               pid, t, id);
       switch (t)
        {
        case 'm':
@@ -131,8 +132,8 @@ get_handle (const size_t id, const char t)
        case 'c':
          {
            handles[id] = CreateSemaphore (NULL, 0, __INT_MAX__, name);
-           snprintf (name, MAX_PATH, "Global_gfortran-%s-%c-%zd_lock", pid, t,
-                     id);
+           snprintf (name, MAX_PATH, "Global_gfortran-%s-%c-%" FLM_Z "d_lock",
+                     pid, t, id);
            handles[id + 1] = CreateSemaphore (NULL, 1, 1, name);
            this_image.supervisor->global_used_handles
              = smax (this_image.supervisor->global_used_handles, id + 2);
@@ -173,7 +174,7 @@ void
 thread_support_init_supervisor (void)
 {
   if (local->total_num_images > ULONGBITS * MAX_NUM_SIGNALED)
-    caf_runtime_error ("Maximum number of supported images is %zd.",
+    caf_runtime_error ("Maximum number of supported images is %" FLM_Z "d.",
                       ULONGBITS * MAX_NUM_SIGNALED);
   this_image.supervisor->global_used_handles = 0;
 }
diff --git a/libgfortran/intrinsics/reduce.c b/libgfortran/intrinsics/reduce.c
index f1f3b838adb0..28bc834bc731 100644
--- a/libgfortran/intrinsics/reduce.c
+++ b/libgfortran/intrinsics/reduce.c
@@ -110,7 +110,7 @@ reduce (parray *ret,
        {
          int mext = (int)GFC_DESCRIPTOR_EXTENT (mask, i);
          runtime_error ("shape mismatch between ARRAY and MASK in the REDUCE "
-                        "intrinsic (%zd/%d)", ext, mext);
+                        "intrinsic (%" FLM_Z "d/%d)", ext, mext);
        }
 
       if (scalar_result)
diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h
index e64862b55978..8381cbd7cd48 100644
--- a/libgfortran/libgfortran.h
+++ b/libgfortran/libgfortran.h
@@ -36,6 +36,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 #  define gfc_printf __printf__
 #endif
 
+/* Handle unsupported C99 length modifiers.  */
+#if defined(__hpux__)
+/* size_t is unsigned long on HP-UX.  */
+#define FLM_Z "l"
+#else
+#define FLM_Z "z"
+#endif
+
 /* config.h MUST be first because it can affect system headers.  */
 #include "config.h"

Reply via email to