aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.fortran
diff options
context:
space:
mode:
authorTobias Burnus <tburnus@baylibre.com>2024-07-29 11:46:57 +0200
committerTobias Burnus <tburnus@baylibre.com>2024-07-29 11:46:57 +0200
commit29b1587e7d34667a1fd63071c1e4f5475cd71026 (patch)
treeae397d08eea21d4bd0712ee9c90d496d55e701da /libgomp/testsuite/libgomp.fortran
parent14c47e7eb06e8b95913794f6059560fc2fa6de91 (diff)
downloadgcc-29b1587e7d34667a1fd63071c1e4f5475cd71026.zip
gcc-29b1587e7d34667a1fd63071c1e4f5475cd71026.tar.gz
gcc-29b1587e7d34667a1fd63071c1e4f5475cd71026.tar.bz2
OpenMP/Fortran: Fix handling of 'declare target' with 'link' clause [PR115559]
Contrary to a normal 'declare target', the 'declare target link' attribute also needs to set node->offloadable and push the offload_vars in the front end. Linked variables require that the data is mapped. For module variables, this can happen anywhere. For variables in an external subprograms or the main programm, this can only happen in the either that program itself or in an internal subprogram. - Whether a variable is just normally mapped or linked then becomes relevant if a device routine exists that can access that variable, i.e. an internal procedure has then to be marked as declare target. PR fortran/115559 gcc/fortran/ChangeLog: * trans-common.cc (build_common_decl): Add 'omp declare target' and 'omp declare target link' variables to offload_vars. * trans-decl.cc (add_attributes_to_decl): Likewise; update args and call decl_attributes. (get_proc_pointer_decl, gfc_get_extern_function_decl, build_function_decl): Update calls. (gfc_get_symbol_decl): Likewise; move after 'DECL_STATIC (t)=1' to avoid errors with symtab_node::get_create. libgomp/ChangeLog: * testsuite/libgomp.fortran/declare-target-link.f90: New test.
Diffstat (limited to 'libgomp/testsuite/libgomp.fortran')
-rw-r--r--libgomp/testsuite/libgomp.fortran/declare-target-link.f90116
1 files changed, 116 insertions, 0 deletions
diff --git a/libgomp/testsuite/libgomp.fortran/declare-target-link.f90 b/libgomp/testsuite/libgomp.fortran/declare-target-link.f90
new file mode 100644
index 0000000..2ce212d
--- /dev/null
+++ b/libgomp/testsuite/libgomp.fortran/declare-target-link.f90
@@ -0,0 +1,116 @@
+! { dg-additional-options "-Wall" }
+! PR fortran/115559
+
+module m
+ integer :: A
+ !$omp declare target link(A)
+end module m
+
+subroutine f
+ implicit none (type, external)
+ integer, save :: x, y ! { dg-warning "Unused variable 'y' declared" }
+ !$omp declare target link(x, y)
+
+ ! note: y is not 'link' as gfortran doesn't regard it as used
+ x = 6
+ call ii
+
+contains
+ subroutine k
+ !$omp declare target
+ use m
+ A = 5
+ end
+ subroutine ii
+ integer :: res
+ !$omp target map(x) map(from: res)
+ call k()
+ call ll()
+ res = get()
+ !$omp end target
+ ! print *, res
+ if (res /= 6 + 7 + 5) &
+ stop 1
+ end
+ subroutine ll
+ !$omp declare target
+ x = x + 7
+ end
+ integer function get()
+ use m
+ !$omp declare target
+ get = x + A
+ end
+end
+
+
+subroutine sub
+ implicit none (type, external)
+ integer, save :: arr(100), arr2(1:4)
+ !$omp declare target link(arr,arr2)
+
+ call mapit
+ call device1
+ call re_mapit
+ call device2
+contains
+ subroutine mapit
+ integer :: i
+ arr = [(i, i=1,100)]
+ !$omp target enter data map(to:arr(10:50)) map(alloc: arr2(1:4))
+ end subroutine
+ subroutine re_mapit
+ integer :: i
+ !$omp target exit data map(from:arr(10:50)) map(delete: arr2)
+
+ if (any (arr(1:9) /= [(i, i=1,9)])) stop 2
+ if (any (arr(10:50) /= [(3-10*i, i=10,50)])) stop 3
+ if (any (arr(51:100) /= [(i, i=51,100)])) stop 4
+ end subroutine
+
+ subroutine device1
+ integer :: res
+ !$omp target map(from:res)
+ res = run_device1()
+ !$omp end target
+ print *, res
+ ! FIXME: arr2 not link mapped -> PR115637
+ ! if (res /= -11436) stop 5
+ if (res /= -11546) stop 5 ! FIXME
+ end
+ integer function run_device1()
+ !$omp declare target
+ integer :: i
+ run_device1 = -99
+ ! FIXME: arr2 not link mapped -> PR115637
+ ! arr2 = [11,22,33,44]
+ if (any (arr(10:50) /= [(i, i=10,50)])) then
+ run_device1 = arr(11)
+ return
+ end if
+ ! FIXME: -> PR115637
+ ! run_device1 = sum(arr(10:13) + arr2)
+ run_device1 = sum(arr(10:13) ) ! FIXME
+ do i = 10, 50
+ arr(i) = 3 - 10 * arr(i)
+ end do
+ run_device1 = run_device1 + sum(arr(15:50))
+ end
+ subroutine device2
+ end
+ integer function run_device2()
+ !$omp declare target
+ run_device2 = -99
+ end
+end
+
+
+use m
+implicit none (type, external)
+external f
+external sub
+
+!$omp target enter data map(alloc: A)
+call f()
+call sub
+end