https://gcc.gnu.org/g:915a4fb541490532868c0b4fb35de139e3f6c704

commit r17-2429-g915a4fb541490532868c0b4fb35de139e3f6c704
Author: John David Anglin <[email protected]>
Date:   Wed Jul 15 18:40:07 2026 -0400

    libgfortran: Fix caf tests on HP-UX
    
    On HP-UX, shm_open parses the name argument directly through file
    system checks.  As a result, we need a name that specifies a directory
    with read, write and execute permisions.  This differs from linux
    where the name specifies the shared memory object to be created or
    opened, and the shared object is identified by a name of the form
    /somename.
    
    We also limit the size of the shared objects to 1 GB on HP-UX.
    The maximum JFS file size is 2 GB - 1 with the default nolargefiles
    option in HP-UX 11.
    
    Finally, we need to compile and link tests with the -pthread option
    to ensure they are linked against libpthread.
    
    2026-06-13  John David Anglin  <[email protected]>
    
    libgfortran/ChangeLog:
    
            * caf/shmem/shared_memory.c (SHM_NAME_FMTD, SHM_NAME_FMTS): Define.
            (shared_memory_init) Use SHM_NAME_FMTD format to generate
            shm_name.
            (shared_memory_cleanup): Use SHM_NAME_FMTS to generate shm_name.
            * caf/shmem/supervisor.c (get_memory_size_from_envvar): Use
            1 GB on 64-bit Windows and HP-UX.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/coarray/caf.exp: Run test with -pthread option.

Diff:
---
 gcc/testsuite/gfortran.dg/coarray/caf.exp |  2 +-
 libgfortran/caf/shmem/shared_memory.c     | 16 ++++++++++++++--
 libgfortran/caf/shmem/supervisor.c        |  8 ++++----
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/coarray/caf.exp 
b/gcc/testsuite/gfortran.dg/coarray/caf.exp
index 3acf1a5a2ebc..b8c2ca773166 100644
--- a/gcc/testsuite/gfortran.dg/coarray/caf.exp
+++ b/gcc/testsuite/gfortran.dg/coarray/caf.exp
@@ -125,7 +125,7 @@ foreach test [lsort [glob -nocomplain 
$srcdir/$subdir/*.\[fF\]{,90,95,03,08} ]]
         foreach flags $option_list {
             verbose "Testing $nshort (libcaf_shmem), $flags" 1
             set gfortran_aux_module_flags "-fcoarray=lib $flags -lcaf_shmem"
-            if { [istarget *-*-freebsd*] } {
+            if { [istarget *-*-freebsd*] || [istarget *-*-hpux*] } {
                 dg-test $test "-fcoarray=lib -pthread $flags -lcaf_shmem" {}
             } else {
                 if { [istarget *-linux*] } {
diff --git a/libgfortran/caf/shmem/shared_memory.c 
b/libgfortran/caf/shmem/shared_memory.c
index a42b0963697c..fc9bdfbd5581 100644
--- a/libgfortran/caf/shmem/shared_memory.c
+++ b/libgfortran/caf/shmem/shared_memory.c
@@ -122,6 +122,17 @@ shared_memory_prepare (shared_memory_act *)
   asm volatile ("" ::: "memory");
 }
 
+#if defined(__hpux__)
+/* On HP-UX, shm_open parses the name argument directly through file
+   system checks.  We need to provide a file path inside a globally
+   writeable directory.  */
+#define SHM_NAME_FMTD "/tmp/gfor-shm-%d"
+#define SHM_NAME_FMTS "/tmp/gfor-shm-%s"
+#else
+#define SHM_NAME_FMTD "/gfor-shm-%d"
+#define SHM_NAME_FMTS "/gfor-shm-%s"
+#endif
+
 #define SHM_NAME_MAX 255
 
 /* Initialize the memory with one page, the shared metadata of the
@@ -140,7 +151,7 @@ shared_memory_init (shared_memory_act *mem, size_t size)
       int n = sscanf (env_val, "%d", &ppid);
       assert (n == 1);
     }
-  snprintf (shm_name, SHM_NAME_MAX, "/gfor-shm-%d", ppid);
+  snprintf (shm_name, SHM_NAME_MAX, SHM_NAME_FMTD, ppid);
   if (base)
     {
       int n = sscanf (base, "%p", &base_ptr);
@@ -286,7 +297,8 @@ shared_memory_cleanup (shared_memory_act *mem)
     {
       char shm_name[SHM_NAME_MAX];
 
-      snprintf (shm_name, SHM_NAME_MAX, "/gfor-shm-%s", shared_memory_get_env 
());
+      snprintf (shm_name, SHM_NAME_MAX, SHM_NAME_FMTS,
+               shared_memory_get_env ());
       /* Only the supervisor is to delete the shm-file.  */
       res = shm_unlink (shm_name);
       if (res == -1)
diff --git a/libgfortran/caf/shmem/supervisor.c 
b/libgfortran/caf/shmem/supervisor.c
index aa692a6551d1..a33b46ecf542 100644
--- a/libgfortran/caf/shmem/supervisor.c
+++ b/libgfortran/caf/shmem/supervisor.c
@@ -134,11 +134,11 @@ get_memory_size_from_envvar (void)
       if (sizeof (size_t) == 4)
        sz = ((size_t) 1) << 28;
       else
-#ifndef WIN32
-       sz = ((size_t) 1) << 34;
-#else
-       /* Use 1GB on Windows.  */
+#if defined(WIN32) || defined(__hpux__)
+       /* Use 1GB on Windows and HP-UX.  */
        sz = ((size_t) 1) << 30;
+#else
+       sz = ((size_t) 1) << 34;
 #endif
     }
   return sz;

Reply via email to