https://gcc.gnu.org/g:62c888a8f13ddc7184a741dc849fd62e5a2b5962
commit r17-5500-g62c888a8f13ddc7184a741dc849fd62e5a2b5962 Author: Thomas Schwinge <[email protected]> Date: Thu Oct 22 14:43:38 2026 +0200 openmp c++: Temporary fix for some lambda mapping problems: Map lambda objects that are subobjects of aggregates [PR127559] Since commit 84d5fecd2694ad70f391a20451d43d82fde37eb5 "openmp c++: Temporary fix for some lambda mapping problems [PR127559]", the C++ front end no longer maps lambda objects that are subobjects of aggregates, such as 'c.x' or 'd[y].x' in 'libgomp.c++/target-lambda-6.C', or their by-reference captures. 'gcc/cp/semantics.cc:finish_omp_target_clauses_r' looks through 'COMPONENT_REF's, 'ARRAY_REF's for a 'VAR_DECL', 'PARM_DECL', 'RESULT_DECL' base, but the base is wrapped in a 'VIEW_CONVERT_EXPR' (location wrapper), and therefore not recognized. Strip location wrappers while looking for the base of a lambda object. With that, un-XFAIL the 'libgomp.c++/target-lambda-6.C' execution test, its 'scan-tree-dump's, and similarly in the new 'g++.dg/gomp/target-lambda-3.C'; all these are now regression-fixed, and back to the PASSing behavior that they (would have) had before commit 84d5fecd2694ad70f391a20451d43d82fde37eb5 "openmp c++: Temporary fix for some lambda mapping problems [PR127559]". PR c++/127559 gcc/cp/ * semantics.cc (finish_omp_target_clauses_r): Strip location wrappers while looking for the base of a lambda object. gcc/testsuite/ * g++.dg/gomp/target-lambda-3.C: Un-XFAIL. libgomp/ * testsuite/libgomp.c++/target-lambda-6.C: Un-XFAIL. Diff: --- gcc/cp/semantics.cc | 5 +++++ gcc/testsuite/g++.dg/gomp/target-lambda-3.C | 8 ++++---- libgomp/testsuite/libgomp.c++/target-lambda-6.C | 11 +++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 42b974a764ba..8117c2891138 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -11289,6 +11289,10 @@ finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr) { gcc_assert (CLASS_TYPE_P (lt)); + if (location_wrapper_p (t)) + /* The wrapped DECL gets handled when walking its operand. */ + return NULL_TREE; + if (TREE_CODE (t) == TARGET_EXPR && !data->local_decls.contains (TARGET_EXPR_SLOT (t))) data->local_decls.add (TARGET_EXPR_SLOT (t)); @@ -11302,6 +11306,7 @@ finish_omp_target_clauses_r (tree *tp, int *walk_subtrees, void *ptr) local to the target region. */ || TREE_CODE (b) == ARRAY_REF) b = TREE_OPERAND (b, 0); + STRIP_ANY_LOCATION_WRAPPER (b); if ((VAR_P (b) || TREE_CODE (b) == PARM_DECL || TREE_CODE (b) == RESULT_DECL) diff --git a/gcc/testsuite/g++.dg/gomp/target-lambda-3.C b/gcc/testsuite/g++.dg/gomp/target-lambda-3.C index 163cc0e05095..6d7b2965d527 100644 --- a/gcc/testsuite/g++.dg/gomp/target-lambda-3.C +++ b/gcc/testsuite/g++.dg/gomp/target-lambda-3.C @@ -18,7 +18,7 @@ f1 (int x) __builtin_abort (); } -/* { dg-final { scan-tree-dump {map\(to:c1\.x \[len: [0-9]+\]\) map\(tofrom:\*c1\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:c1\.x\.__x \[pointer assign, bias: 0\]\)} original { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump {map\(to:c1\.x \[len: [0-9]+\]\) map\(tofrom:\*c1\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:c1\.x\.__x \[pointer assign, bias: 0\]\)} original } } */ void f2 (int x, int y) @@ -30,8 +30,8 @@ f2 (int x, int y) __builtin_abort (); } -/* { dg-final { scan-tree-dump {map\(to:d2\[1\]\.x \[len: [0-9]+\]\) map\(tofrom:\*d2\[1\]\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:d2\[1\]\.x\.__x \[pointer assign, bias: 0\]\)} original { xfail *-*-* } } } - { dg-final { scan-tree-dump {map\(to:d2\[y\]\.x \[len: [0-9]+\]\) map\(tofrom:\*d2\[y\]\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:d2\[y\]\.x\.__x \[pointer assign, bias: 0\]\)} original { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump {map\(to:d2\[1\]\.x \[len: [0-9]+\]\) map\(tofrom:\*d2\[1\]\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:d2\[1\]\.x\.__x \[pointer assign, bias: 0\]\)} original } } + { dg-final { scan-tree-dump {map\(to:d2\[y\]\.x \[len: [0-9]+\]\) map\(tofrom:\*d2\[y\]\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:d2\[y\]\.x\.__x \[pointer assign, bias: 0\]\)} original } } */ void f3 (int x) @@ -43,7 +43,7 @@ f3 (int x) __builtin_abort (); } -/* { dg-final { scan-tree-dump {map\(to:e3\.x\.x \[len: [0-9]+\]\) map\(tofrom:\*e3\.x\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:e3\.x\.x\.__x \[pointer assign, bias: 0\]\)} original { xfail *-*-* } } } */ +/* { dg-final { scan-tree-dump {map\(to:e3\.x\.x \[len: [0-9]+\]\) map\(tofrom:\*e3\.x\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:e3\.x\.x\.__x \[pointer assign, bias: 0\]\)} original } } */ void f4 (int x) diff --git a/libgomp/testsuite/libgomp.c++/target-lambda-6.C b/libgomp/testsuite/libgomp.c++/target-lambda-6.C index a997f2118f82..ab0607619f39 100644 --- a/libgomp/testsuite/libgomp.c++/target-lambda-6.C +++ b/libgomp/testsuite/libgomp.c++/target-lambda-6.C @@ -1,6 +1,5 @@ // PR c++/127559 // { dg-do run } -// { dg-xfail-run-if PR127559 { offload_device_nonshared_as } } // { dg-additional-options {-fdump-tree-original -fdump-tree-gimple} } template <typename T> @@ -35,9 +34,9 @@ main () } /* Lambda objects 'c.x', 'd[y].x' must be mapped, including their by-reference capture of 'x'. - { dg-final { scan-tree-dump {map\(to:c\.x \[len: [0-9]+\]\) map\(tofrom:\*c\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:c\.x\.__x \[pointer assign, bias: 0\]\)} original { xfail *-*-* } } } - { dg-final { scan-tree-dump {map\(to:d\[y\]\.x \[len: [0-9]+\]\) map\(tofrom:\*d\[y\]\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:d\[y\]\.x\.__x \[pointer assign, bias: 0\]\)} original { xfail *-*-* } } } - { dg-final { scan-tree-dump {map\(struct:c \[len: 1\]\) map\(to:c\.x \[len: [0-9]+\]\) map\(tofrom:\*c\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:c\.x\.__x \[pointer assign, bias: 0\]\)} gimple { xfail *-*-* } } } - { dg-final { scan-tree-dump {map\(struct_unord:d \[len: 1\]\) map\(to:d\[y\]\.x \[len: [0-9]+\]\) map\(tofrom:\*d\[y\]\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:d\[y\]\.x\.__x \[pointer assign, bias: 0\]\)} gimple { xfail *-*-* } } } + { dg-final { scan-tree-dump {map\(to:c\.x \[len: [0-9]+\]\) map\(tofrom:\*c\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:c\.x\.__x \[pointer assign, bias: 0\]\)} original } } + { dg-final { scan-tree-dump {map\(to:d\[y\]\.x \[len: [0-9]+\]\) map\(tofrom:\*d\[y\]\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:d\[y\]\.x\.__x \[pointer assign, bias: 0\]\)} original } } + { dg-final { scan-tree-dump {map\(struct:c \[len: 1\]\) map\(to:c\.x \[len: [0-9]+\]\) map\(tofrom:\*c\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:c\.x\.__x \[pointer assign, bias: 0\]\)} gimple } } + { dg-final { scan-tree-dump {map\(struct_unord:d \[len: 1\]\) map\(to:d\[y\]\.x \[len: [0-9]+\]\) map\(tofrom:\*d\[y\]\.x\.__x \[len: [0-9]+\]\) map\(always_pointer:d\[y\]\.x\.__x \[pointer assign, bias: 0\]\)} gimple } } ..., and in particular not as a whole, implicitly: - { dg-final { scan-tree-dump-not {runtime_implicit} gimple { xfail *-*-* } } } */ + { dg-final { scan-tree-dump-not {runtime_implicit} gimple } } */
