[PATCH 1/3] fortran: fix unexpected runtime error in libgomp

Sebastian Galindo sebastian.galindo143@gmail.com
Mon Oct 5 03:29:32 GMT 2026


When the device_type clause had the argument as *,
the set directive was passing an invalid argument to
the runtime library.

gcc/fortran/ChangeLog:

	* trans-openmp.cc: For set, map device_type(*)
	to GOMP_DEVICE_DEFAULT.

gcc/testsuite/ChangeLog:

	* gfortran.dg/goacc/acc-set-1.f90: New test.

Signed-off-by: Sebastian Galindo <sebastian.galindo143@gmail.com>
---
 gcc/fortran/trans-openmp.cc                   | 7 ++++++-
 gcc/testsuite/gfortran.dg/goacc/acc-set-1.f90 | 7 +++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index 3e4375f6d60..930027a2741 100644
--- a/gcc/fortran/trans-openmp.cc
+++ b/gcc/fortran/trans-openmp.cc
@@ -6568,7 +6568,12 @@ builtin_oacc_exec_directive:
 		    GOMP_DEVICE_DEFAULT	      :
 		    GOMP_DEVICE_NONE;
   if (clauses->oacc_device_type_present)
-    device_type = clauses->oacc_device_type;
+    {
+      device_type = clauses->oacc_device_type;
+      /* For set, device_type (*) means the default device, not "all".  */
+      if (device_type == GOMP_DEVICE_NONE && code->op == EXEC_OACC_SET)
+	device_type = GOMP_DEVICE_DEFAULT;
+    }
 
   tree d_type = build_int_cst (integer_type_node, device_type);
 
diff --git a/gcc/testsuite/gfortran.dg/goacc/acc-set-1.f90 b/gcc/testsuite/gfortran.dg/goacc/acc-set-1.f90
index 013c301c775..5c9e3e3817d 100644
--- a/gcc/testsuite/gfortran.dg/goacc/acc-set-1.f90
+++ b/gcc/testsuite/gfortran.dg/goacc/acc-set-1.f90
@@ -29,8 +29,15 @@ subroutine set4(l)
   !$acc set if(l) device_type(radeon) device_num(1)
 end subroutine set4
 
+subroutine set5
+  implicit none
+  ! device_type(*) maps to GOMP_DEVICE_DEFAULT for set.
+  !$acc set device_type(*)
+end subroutine set5
+
 ! { dg-final { scan-tree-dump-times "__builtin_GOACC_set_device \\(-1, 2\\)" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "__builtin_GOACC_set_device \\(-1, 5\\)" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "__builtin_GOACC_set_device \\(0, 1\\)" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "__builtin_GOACC_set_device \\(0, 2\\)" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "__builtin_GOACC_set_device \\(1, 8\\)" 1 "original" } }
+! { dg-final { scan-tree-dump-times "__builtin_GOACC_set_device \\(-1, 1\\)" 1 "original" } }
-- 
2.55.0



More information about the Gcc-patches mailing list