]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
OpenMP: Fix reverse offload GOMP_TARGET_REV IFN corner cases [PR107236]
authorTobias Burnus <tobias@codesourcery.com>
Mon, 24 Oct 2022 13:19:00 +0000 (15:19 +0200)
committerTobias Burnus <tobias@codesourcery.com>
Mon, 24 Oct 2022 13:19:00 +0000 (15:19 +0200)
For 'target parallel' and similarly nested directives, cgraph_node's
calls_declare_variant_alt was not set in the parent region node but in
cfun->decl. Hence, pass_omp_device_lower did not process handle the
internal function GOMP_TARGET_REV. - Solution is to set it to the
DECL_CONTEXT, which is set in adjust_context_and_scope.

The cgraph_node::create_clone issue is exposed with -O2 for the existing
libgomp.fortran/reverse-offload-1.f90.

PR middle-end/107236

gcc/ChangeLog:
* omp-expand.cc (expand_omp_target): Set calls_declare_variant_alt
in DECL_CONTEXT and not to cfun->decl.
* cgraphclones.cc (cgraph_node::create_clone): Copy also the
node's calls_declare_variant_alt value.

gcc/testsuite/ChangeLog:
* gfortran.dg/gomp/target-device-ancestor-6.f90: New test.

gcc/cgraphclones.cc
gcc/omp-expand.cc
gcc/testsuite/gfortran.dg/gomp/target-device-ancestor-6.f90 [new file with mode: 0644]

index eb0fa87b554c0cb27217f60da6526006bec518d9..bb4b3c5407d56c1ea23b97131a7b91fa5b362e02 100644 (file)
@@ -375,6 +375,7 @@ cgraph_node::create_clone (tree new_decl, profile_count prof_count,
   if (!new_inlined_to)
     prof_count = count.combine_with_ipa_count (prof_count);
   new_node->count = prof_count;
+  new_node->calls_declare_variant_alt = this->calls_declare_variant_alt;
 
   /* Update IPA profile.  Local profiles need no updating in original.  */
   if (update_original)
index 5dc0bf16e17ed0a10ab916c74cd7a19889f11014..c636a174e361e4905ce28532e9390f45e25524d1 100644 (file)
@@ -10054,13 +10054,8 @@ expand_omp_target (struct omp_region *region)
 
       /* Handle the case that an inner ancestor:1 target is called by an outer
         target region. */
-      if (!is_ancestor)
-       cgraph_node::get (child_fn)->calls_declare_variant_alt
-         |= cgraph_node::get (cfun->decl)->calls_declare_variant_alt;
-      else  /* Duplicate function to create empty nonhost variant. */
+      if (is_ancestor)
        {
-         /* Enable pass_omp_device_lower pass.  */
-         cgraph_node::get (cfun->decl)->calls_declare_variant_alt = 1;
          cgraph_node *fn2_node;
          child_fn2 = build_decl (DECL_SOURCE_LOCATION (child_fn),
                                  FUNCTION_DECL,
@@ -10074,7 +10069,7 @@ expand_omp_target (struct omp_region *region)
          TREE_PUBLIC (child_fn2) = 0;
          DECL_UNINLINABLE (child_fn2) = 1;
          DECL_EXTERNAL (child_fn2) = 0;
-         DECL_CONTEXT (child_fn2) = NULL_TREE;
+         DECL_CONTEXT (child_fn2) = DECL_CONTEXT (child_fn);
          DECL_INITIAL (child_fn2) = make_node (BLOCK);
          BLOCK_SUPERCONTEXT (DECL_INITIAL (child_fn2)) = child_fn2;
          DECL_ATTRIBUTES (child_fn)
@@ -10098,6 +10093,10 @@ expand_omp_target (struct omp_region *region)
          fn2_node->force_output = 1;
          node->offloadable = 0;
 
+         /* Enable pass_omp_device_lower pass.  */
+         fn2_node = cgraph_node::get (DECL_CONTEXT (child_fn));
+         fn2_node->calls_declare_variant_alt = 1;
+
          t = build_decl (DECL_SOURCE_LOCATION (child_fn),
                          RESULT_DECL, NULL_TREE, void_type_node);
          DECL_ARTIFICIAL (t) = 1;
diff --git a/gcc/testsuite/gfortran.dg/gomp/target-device-ancestor-6.f90 b/gcc/testsuite/gfortran.dg/gomp/target-device-ancestor-6.f90
new file mode 100644 (file)
index 0000000..821e785
--- /dev/null
@@ -0,0 +1,17 @@
+! PR middle-end/107236
+
+! Did ICE before because IFN .GOMP_TARGET_REV was not
+! processed in omp-offload.cc.
+! Note: Test required ENABLE_OFFLOADING being true inside GCC.
+
+implicit none
+!$omp requires reverse_offload
+!$omp target parallel num_threads(4)
+  !$omp target device(ancestor:1)
+    call foo()
+  !$omp end target 
+!$omp end target parallel
+contains
+  subroutine foo
+  end
+end