xref: /llvm-project/flang/test/Lower/OpenMP/declare-target-unnamed-main.f90 (revision 03579455bd941da6278f883ed8827ef0fbeb5e50)
1*03579455Sagozillon!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
2*03579455Sagozillon!RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-is-device %s -o - | FileCheck %s
3*03579455Sagozillon
4*03579455Sagozillon! This test is a reduced version of the example in issue 63362.
5*03579455Sagozillon! It aims to test that no crash occurs when declare target is
6*03579455Sagozillon! utilised within an unnamed main program and that we still
7*03579455Sagozillon! appropriately mark the function as declare target, even when
8*03579455Sagozillon! unused within the target region.
9*03579455Sagozillon
10*03579455Sagozillon!CHECK: func.func @_QPfoo(%{{.*}}: !fir.ref<f32>{{.*}}) -> f32 attributes {{{.*}}omp.declare_target = #omp.declaretarget<device_type = (any), capture_clause = (to)>{{.*}}}
11*03579455Sagozillon
12*03579455Sagozilloninterface
13*03579455Sagozillonreal function foo (x)
14*03579455Sagozillon  !$omp declare target
15*03579455Sagozillon  real, intent(in) :: x
16*03579455Sagozillonend function foo
17*03579455Sagozillonend interface
18*03579455Sagozilloninteger, parameter :: n = 1000
19*03579455Sagozilloninteger, parameter :: c = 100
20*03579455Sagozilloninteger :: i, j
21*03579455Sagozillonreal :: a(n)
22*03579455Sagozillondo i = 1, n
23*03579455Sagozillona(i) = i
24*03579455Sagozillonend do
25*03579455Sagozillondo i = 1, n, c
26*03579455Sagozillon  !$omp target map(a(i:i+c-1))
27*03579455Sagozillon    !$omp parallel do
28*03579455Sagozillon      do j = i, i + c - 1
29*03579455Sagozillon        a(j) = a(j)
30*03579455Sagozillon      end do
31*03579455Sagozillon  !$omp end target
32*03579455Sagozillonend do
33*03579455Sagozillondo i = 1, n
34*03579455Sagozillonif (a(i) /= i + 1) stop 1
35*03579455Sagozillonend do
36*03579455Sagozillonend
37*03579455Sagozillonreal function foo (x)
38*03579455Sagozillon!$omp declare target
39*03579455Sagozillonreal, intent(in) :: x
40*03579455Sagozillonfoo = x + 1
41*03579455Sagozillonend function foo
42