Hi all,

attached patches goes on top of other 6 caf_shmem coarray patches and fixes
missing includes esp. on non-Linux systems. I have tested this on a FreeBSD,
which is very time consuming due to it being fully virtualized on my system.

Regtests ok on x86_64-pc-linux-gnu and aarch64-unknown-freebsd14.3. Ok for
mainline?

Thanks to Steve for bringing these deficiencies to my attention.

Regards,
        Andre
-- 
Andre Vehreschild * Email: vehre ad gmx dot de 
From 6a50f10bfa802fc93eaf302bf5493506b5795e6a Mon Sep 17 00:00:00 2001
From: Andre Vehreschild <ve...@gcc.gnu.org>
Date: Wed, 2 Jul 2025 11:47:18 +0200
Subject: [PATCH] Fortran: Fix includes in caf_shmem (esp. for BSDs) [PR88076]

	PR fortran/88076

libgfortran/ChangeLog:

	* caf/shmem.c: Remove declaration of environment.
	* caf/shmem/allocator.h: Fix required includes.
	* caf/shmem/hashmap.h: Same.
	* caf/shmem/shared_memory.h: Same.
	* caf/shmem/supervisor.c (ensure_shmem_initialization): Insert
	declaration of environment and fix includes.
---
 libgfortran/caf/shmem.c               | 2 --
 libgfortran/caf/shmem/allocator.h     | 1 +
 libgfortran/caf/shmem/hashmap.h       | 3 ++-
 libgfortran/caf/shmem/shared_memory.h | 1 +
 libgfortran/caf/shmem/supervisor.c    | 8 ++++++++
 5 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/libgfortran/caf/shmem.c b/libgfortran/caf/shmem.c
index b52f9479948..3d83782db24 100644
--- a/libgfortran/caf/shmem.c
+++ b/libgfortran/caf/shmem.c
@@ -78,8 +78,6 @@ static enum {
 } accessor_hash_table_state
   = AHT_UNINITIALIZED;
 
-extern char **environ;
-
 void
 _gfortran_caf_init (int *argc, char ***argv)
 {
diff --git a/libgfortran/caf/shmem/allocator.h b/libgfortran/caf/shmem/allocator.h
index e55d974301d..53b6abeeba1 100644
--- a/libgfortran/caf/shmem/allocator.h
+++ b/libgfortran/caf/shmem/allocator.h
@@ -31,6 +31,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include "shared_memory.h"
 
 #include <stddef.h>
+#include <pthread.h>
 
 /* The number of bits a void pointer has.  */
 #define VOIDP_BITS (__CHAR_BIT__ * sizeof (void *))
diff --git a/libgfortran/caf/shmem/hashmap.h b/libgfortran/caf/shmem/hashmap.h
index dbb5a1171c4..bc263d32dcd 100644
--- a/libgfortran/caf/shmem/hashmap.h
+++ b/libgfortran/caf/shmem/hashmap.h
@@ -27,8 +27,9 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #include "allocator.h"
 
-#include <stdint.h>
 #include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
 
 /* Data structures and variables:
 
diff --git a/libgfortran/caf/shmem/shared_memory.h b/libgfortran/caf/shmem/shared_memory.h
index b2e6bbe4ae9..01ac2811e5d 100644
--- a/libgfortran/caf/shmem/shared_memory.h
+++ b/libgfortran/caf/shmem/shared_memory.h
@@ -27,6 +27,7 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 
 #include <stdlib.h>
 #include <stddef.h>
+#include <unistd.h>
 
 /* Global metadata for shared memory, always kept at offset 0.  */
 
diff --git a/libgfortran/caf/shmem/supervisor.c b/libgfortran/caf/shmem/supervisor.c
index c24bb30aa95..53b6facb6e1 100644
--- a/libgfortran/caf/shmem/supervisor.c
+++ b/libgfortran/caf/shmem/supervisor.c
@@ -22,6 +22,8 @@ a copy of the GCC Runtime Library Exception along with this program;
 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
+#include "config.h"
+
 #include "../caf_error.h"
 #include "supervisor.h"
 #include "teams_mgmt.h"
@@ -30,7 +32,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 #include <assert.h>
 #include <unistd.h>
 #include <string.h>
+#ifdef HAVE_WAIT_H
 #include <wait.h>
+#elif HAVE_SYS_WAIT_H
+#include <sys/wait.h>
+#endif
 
 #define GFORTRAN_ENV_NUM_IMAGES "GFORTRAN_NUM_IMAGES"
 #define GFORTRAN_ENV_SHARED_MEMORY_SIZE "GFORTRAN_SHARED_MEMORY_SIZE"
@@ -198,6 +204,8 @@ ensure_shmem_initialization (void)
     }
 }
 
+extern char **environ;
+
 int
 supervisor_main_loop (int *argc __attribute__ ((unused)), char ***argv,
 		      int *exit_code)
-- 
2.50.0

Reply via email to