Skip to content

Commit e7c6e35

Browse files
authored
[flang][OpenMP] Fix threadprivate pointer variable in common block (#131888)
Fixes #112538 The problem was that the host associated symbol for the threadprivate variable doesn't have all of the symbol attributes (e.g. POINTER). This caused the lowering code to generate the wrong type, eventually hitting an assertion.
1 parent 75ab43b commit e7c6e35

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ static void threadPrivatizeVars(lower::AbstractConverter &converter,
763763
commonSyms.insert(common);
764764
}
765765
symThreadprivateValue = lower::genCommonBlockMember(
766-
converter, currentLocation, *sym, commonThreadprivateValue);
766+
converter, currentLocation, sym->GetUltimate(),
767+
commonThreadprivateValue);
767768
} else {
768769
symThreadprivateValue = genThreadprivateOp(*sym);
769770
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
! Simple test for lowering of OpenMP Threadprivate Directive with a pointer var
2+
! from a common block.
3+
4+
!RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
5+
!RUN: bbc -hlfir -emit-hlfir -fopenmp %s -o - | FileCheck %s
6+
7+
! Regression test for a compiler crash
8+
9+
module mmm
10+
integer,pointer::nam1
11+
common /com1/nam1,nam2
12+
!$omp threadprivate(/com1/)
13+
end
14+
use mmm
15+
!$omp parallel copyin(nam1)
16+
!$omp end parallel
17+
end
18+
19+
20+
! CHECK-LABEL: fir.global common @com1_(dense<0> : vector<28xi8>) {alignment = 8 : i64} : !fir.array<28xi8>
21+
22+
! CHECK-LABEL: func.func @_QQmain() {
23+
! CHECK: %[[VAL_0:.*]] = fir.address_of(@com1_) : !fir.ref<!fir.array<28xi8>>
24+
! CHECK: omp.parallel {
25+
! CHECK: %[[VAL_17:.*]] = omp.threadprivate %[[VAL_0]] : !fir.ref<!fir.array<28xi8>> -> !fir.ref<!fir.array<28xi8>>
26+
! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_17]] : (!fir.ref<!fir.array<28xi8>>) -> !fir.ref<!fir.array<?xi8>>
27+
! CHECK: %[[VAL_19:.*]] = arith.constant 0 : index
28+
! CHECK: %[[VAL_20:.*]] = fir.coordinate_of %[[VAL_18]], %[[VAL_19]] : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
29+
! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (!fir.ref<i8>) -> !fir.ref<!fir.box<!fir.ptr<i32>>>
30+
! CHECK: %[[VAL_22:.*]]:2 = hlfir.declare %[[VAL_21]] {fortran_attrs = #{{.*}}<pointer>, uniq_name = "_QMmmmEnam1"} : (!fir.ref<!fir.box<!fir.ptr<i32>>>) -> (!fir.ref<!fir.box<!fir.ptr<i32>>>, !fir.ref<!fir.box<!fir.ptr<i32>>>)
31+

0 commit comments

Comments
 (0)