Skip to content

Commit f882eb4

Browse files
authored
[Flang][OpenMP] Skip component symbols when creating extended values (#79657)
The `map` clause in OpenMP allows structure components to be specified (unlike other clauses). Structure components do get their own symbols, but these are not meant to be instantiated. When a component reference is passed as an argument to the omp.target op, it gets a corresponding parameter in the target op's entry block. The original symbols are then bound to the same kind of an extended value as before, but the value is now based on the parameters. To handle structure components more gracefully, put their symbols on the list of mapped objects, but skip them when creating extended values. Fixes #79478.
1 parent 3855757 commit f882eb4

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

flang/lib/Lower/OpenMP.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ getOmpObjectSymbol(const Fortran::parser::OmpObject &ompObject) {
5858
Fortran::parser::Unwrap<Fortran::parser::ArrayElement>(
5959
designator)) {
6060
sym = GetFirstName(arrayEle->base).symbol;
61+
} else if (auto *structComp = Fortran::parser::Unwrap<
62+
Fortran::parser::StructureComponent>(designator)) {
63+
sym = structComp->component.symbol;
6164
} else if (const Fortran::parser::Name *name =
6265
Fortran::semantics::getDesignatorNameIfDataRef(
6366
designator)) {
@@ -2743,6 +2746,9 @@ static void genBodyOfTargetOp(
27432746
const mlir::BlockArgument &arg = region.getArgument(argIndex);
27442747
// Avoid capture of a reference to a structured binding.
27452748
const Fortran::semantics::Symbol *sym = argSymbol;
2749+
// Structure component symbols don't have bindings.
2750+
if (sym->owner().IsDerivedType())
2751+
continue;
27462752
fir::ExtendedValue extVal = converter.getSymbolExtendedValue(*sym);
27472753
extVal.match(
27482754
[&](const fir::BoxValue &v) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
2+
! RUN: bbc -fopenmp -emit-fir %s -o - | FileCheck %s
3+
4+
! CHECK: %[[V0:[0-9]+]] = fir.alloca !fir.type<_QFfooTt0{a0:i32,a1:i32}> {bindc_name = "a", uniq_name = "_QFfooEa"}
5+
! CHECK: %[[V1:[0-9]+]] = fir.declare %[[V0]] {uniq_name = "_QFfooEa"} : (!fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>) -> !fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>
6+
! CHECK: %[[V2:[0-9]+]] = fir.field_index a1, !fir.type<_QFfooTt0{a0:i32,a1:i32}>
7+
! CHECK: %[[V3:[0-9]+]] = fir.coordinate_of %[[V1]], %[[V2]] : (!fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>, !fir.field) -> !fir.ref<i32>
8+
! CHECK: %[[V4:[0-9]+]] = omp.map_info var_ptr(%[[V3]] : !fir.ref<i32>, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref<i32> {name = "a%a1"}
9+
! CHECK: %[[V5:[0-9]+]] = omp.map_info var_ptr(%[[V1]] : !fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>, !fir.type<_QFfooTt0{a0:i32,a1:i32}>) map_clauses(implicit, tofrom) capture(ByRef) -> !fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>> {name = "a"}
10+
! CHECK: omp.target map_entries(%[[V4]] -> %arg0, %[[V5]] -> %arg1 : !fir.ref<i32>, !fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>) {
11+
! CHECK: ^bb0(%arg0: !fir.ref<i32>, %arg1: !fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>):
12+
! CHECK: %c0_i32 = arith.constant 0 : i32
13+
! CHECK: %[[V6:[0-9]+]] = fir.declare %arg1 {uniq_name = "_QFfooEa"} : (!fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>) -> !fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>
14+
! CHECK: %[[V7:[0-9]+]] = fir.field_index a1, !fir.type<_QFfooTt0{a0:i32,a1:i32}>
15+
! CHECK: %[[V8:[0-9]+]] = fir.coordinate_of %[[V6]], %[[V7]] : (!fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>, !fir.field) -> !fir.ref<i32>
16+
! CHECK: fir.store %c0_i32 to %[[V8]] : !fir.ref<i32>
17+
! CHECK: omp.terminator
18+
! CHECK: }
19+
20+
subroutine foo()
21+
implicit none
22+
23+
type t0
24+
integer :: a0, a1
25+
end type
26+
27+
type(t0) :: a
28+
29+
!$omp target map(a%a1)
30+
a%a1 = 0
31+
!$omp end target
32+
end
33+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
! RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
2+
! RUN: bbc -fopenmp -emit-hlfir %s -o - | FileCheck %s
3+
4+
! CHECK: %[[V0:[0-9]+]] = fir.alloca !fir.type<_QFfooTt0{a0:i32,a1:i32}> {bindc_name = "a", uniq_name = "_QFfooEa"}
5+
! CHECK: %[[V1:[0-9]+]]:2 = hlfir.declare %[[V0]] {uniq_name = "_QFfooEa"} : (!fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>) -> (!fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>, !fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>)
6+
! CHECK: %[[V2:[0-9]+]] = hlfir.designate %[[V1]]#0{"a1"} : (!fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>) -> !fir.ref<i32>
7+
! CHECK: %[[V3:[0-9]+]] = omp.map_info var_ptr(%[[V2]] : !fir.ref<i32>, i32) map_clauses(tofrom) capture(ByRef) -> !fir.ref<i32> {name = "a%a1"}
8+
! CHECK: %[[V4:[0-9]+]] = omp.map_info var_ptr(%[[V1]]#1 : !fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>, !fir.type<_QFfooTt0{a0:i32,a1:i32}>) map_clauses(implicit, tofrom) capture(ByRef) -> !fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>> {name = "a"}
9+
! CHECK: omp.target map_entries(%[[V3]] -> %arg0, %[[V4]] -> %arg1 : !fir.ref<i32>, !fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>) {
10+
! CHECK: ^bb0(%arg0: !fir.ref<i32>, %arg1: !fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>):
11+
! CHECK: %[[V5:[0-9]+]]:2 = hlfir.declare %arg1 {uniq_name = "_QFfooEa"} : (!fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>) -> (!fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>, !fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>)
12+
! CHECK: %c0_i32 = arith.constant 0 : i32
13+
! CHECK: %[[V6:[0-9]+]] = hlfir.designate %[[V5]]#0{"a1"} : (!fir.ref<!fir.type<_QFfooTt0{a0:i32,a1:i32}>>) -> !fir.ref<i32>
14+
! CHECK: hlfir.assign %c0_i32 to %[[V6]] : i32, !fir.ref<i32>
15+
! CHECK: omp.terminator
16+
! CHECK: }
17+
18+
subroutine foo()
19+
implicit none
20+
21+
type t0
22+
integer :: a0, a1
23+
end type
24+
25+
type(t0) :: a
26+
27+
!$omp target map(a%a1)
28+
a%a1 = 0
29+
!$omp end target
30+
end
31+

0 commit comments

Comments
 (0)