https://gcc.gnu.org/g:e2e54655d9d655bdef42a2c9eadb81dfdf88e1c7

commit r17-2451-ge2e54655d9d655bdef42a2c9eadb81dfdf88e1c7
Author: Tobias Burnus <[email protected]>
Date:   Thu Jul 16 13:23:15 2026 +0200

    OpenMP: Fix implicit declare target - aka fix 
libgomp.fortran/reverse-offload-6.f90
    
    This fixes a bug I introduced in commit r17-2404-g2468c79741f97c,
      OpenMP: Handle 'device_type(host)' on 'target'
    
    For code inside a target region with either 'device(ancestor:1)' or
    with 'device_type(host)' no device code should be generated. That's
    handled by both omp_discover_declare_target_tgt_fn_r and by
    omp_discover_declare_target_fn_r.
    
    While for the latter, walk_tree_without_duplicates is called when
    the condition is true, the former sets '*walk_subtrees = 0'.
    
    Looking too similar, r17-2404 ended up using the same condition for
    both. - The solution is to inverse the current condition for
    omp_discover_declare_target_tgt_fn_r.
    
    Testcase: The already existing and since r17-2404 failing
    test libgomp.fortran/reverse-offload-6.f90.
    
    gcc/ChangeLog:
    
            * omp-offload.cc (omp_discover_declare_target_tgt_fn_r): Fix
            the condition for anchestor + nohost handling.

Diff:
---
 gcc/omp-offload.cc | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/omp-offload.cc b/gcc/omp-offload.cc
index bbe13154d8f0..3c37956a28c5 100644
--- a/gcc/omp-offload.cc
+++ b/gcc/omp-offload.cc
@@ -273,9 +273,9 @@ omp_discover_declare_target_tgt_fn_r (tree *tp, int 
*walk_subtrees, void *data)
     {
       tree c = omp_find_clause (OMP_CLAUSES (*tp), OMP_CLAUSE_DEVICE);
       tree c2 = omp_find_clause (OMP_CLAUSES (*tp), OMP_CLAUSE_DEVICE_TYPE);
-      if ((!c || !OMP_CLAUSE_DEVICE_ANCESTOR (c))
-         && (!c2 || (OMP_CLAUSE_DEVICE_TYPE_KIND (c2)
-                     != OMP_CLAUSE_DEVICE_TYPE_HOST)))
+      if ((c && OMP_CLAUSE_DEVICE_ANCESTOR (c))
+          || (c2 && (OMP_CLAUSE_DEVICE_TYPE_KIND (c2)
+                     == OMP_CLAUSE_DEVICE_TYPE_HOST)))
        *walk_subtrees = 0;
     }
   return NULL_TREE;

Reply via email to