Skip to content

Commit 91f92e6

Browse files
authored
[flang][OpenMP] Fix common block missing symbol crash (#67330)
Fixes #65034 by skipping copy of host-association information if the concerned symbol is missing from the inner construct
1 parent e752b58 commit 91f92e6

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

flang/include/flang/Lower/AbstractConverter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ class AbstractConverter {
118118
const Fortran::semantics::Symbol &sym,
119119
mlir::OpBuilder::InsertPoint *copyAssignIP = nullptr) = 0;
120120

121+
/// For a given symbol, check if it is present in the inner-most
122+
/// level of the symbol map.
123+
virtual bool isPresentShallowLookup(Fortran::semantics::Symbol &sym) = 0;
124+
121125
/// Collect the set of symbols with \p flag in \p eval
122126
/// region if \p collectSymbols is true. Likewise, collect the
123127
/// set of the host symbols with \p flag of the associated symbols in \p eval

flang/lib/Lower/Bridge.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,10 @@ class FirConverter : public Fortran::lower::AbstractConverter {
603603
std::nullopt);
604604
}
605605

606+
bool isPresentShallowLookup(Fortran::semantics::Symbol &sym) override final {
607+
return bool(shallowLookupSymbol(sym));
608+
}
609+
606610
bool createHostAssociateVarClone(
607611
const Fortran::semantics::Symbol &sym) override final {
608612
mlir::Location loc = genLocation(sym.name());

flang/lib/Lower/OpenMP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,8 @@ bool ClauseProcessor::processCopyin() const {
15921592
mlir::OpBuilder::InsertPoint *copyAssignIP = nullptr) {
15931593
assert(sym->has<Fortran::semantics::HostAssocDetails>() &&
15941594
"No host-association found");
1595-
converter.copyHostAssociateVar(*sym, copyAssignIP);
1595+
if (converter.isPresentShallowLookup(*sym))
1596+
converter.copyHostAssociateVar(*sym, copyAssignIP);
15961597
};
15971598
bool hasCopyin = findRepeatableClause<ClauseTy::Copyin>(
15981599
[&](const ClauseTy::Copyin *copyinClause,

flang/test/Lower/OpenMP/FIR/copyin.f90

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,43 @@ subroutine common_2()
310310
end do
311311
!$omp end parallel do
312312
end subroutine
313+
314+
!CHECK: func.func @_QPcommon_3() {
315+
!CHECK: %[[val_0:.*]] = fir.address_of(@blk_) : !fir.ref<!fir.array<8xi8>>
316+
!CHECK: %[[val_1:.*]] = omp.threadprivate %[[val_0]] : !fir.ref<!fir.array<8xi8>> -> !fir.ref<!fir.array<8xi8>>
317+
!CHECK: %[[val_2:.*]] = fir.convert %[[val_1]] : (!fir.ref<!fir.array<8xi8>>) -> !fir.ref<!fir.array<?xi8>>
318+
!CHECK: %[[val_c4:.*]] = arith.constant 4 : index
319+
!CHECK: %[[val_3:.*]] = fir.coordinate_of %[[val_2]], %[[val_c4]] : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
320+
!CHECK: %[[val_4:.*]] = fir.convert %[[val_3]] : (!fir.ref<i8>) -> !fir.ref<i32>
321+
!CHECK: omp.parallel {
322+
!CHECK: %[[val_5:.*]] = omp.threadprivate %[[val_0]] : !fir.ref<!fir.array<8xi8>> -> !fir.ref<!fir.array<8xi8>>
323+
!CHECK: %[[val_6:.*]] = fir.convert %[[val_5]] : (!fir.ref<!fir.array<8xi8>>) -> !fir.ref<!fir.array<?xi8>>
324+
!CHECK: %[[val_c4_0:.*]] = arith.constant 4 : index
325+
!CHECK: %[[val_7:.*]] = fir.coordinate_of %[[val_6]], %[[val_c4_0]] : (!fir.ref<!fir.array<?xi8>>, index) -> !fir.ref<i8>
326+
!CHECK: %[[val_8:.*]] = fir.convert %[[val_7]] : (!fir.ref<i8>) -> !fir.ref<i32>
327+
!CHECK: %[[val_9:.*]] = fir.load %[[val_4]] : !fir.ref<i32>
328+
!CHECK: fir.store %[[val_9]] to %[[val_8]] : !fir.ref<i32>
329+
!CHECK: omp.barrier
330+
!CHECK: omp.sections {
331+
!CHECK: omp.section {
332+
!CHECK: %[[val_10:.*]] = fir.load %[[val_8]] : !fir.ref<i32>
333+
!CHECK: %[[val_c3_i32:.*]] = arith.constant 3 : i32
334+
!CHECK: %[[val_11:.*]] = arith.addi %[[val_10]], %[[val_c3_i32]] : i32
335+
!CHECK: fir.store %[[val_11]] to %[[val_8]] : !fir.ref<i32>
336+
!CHECK: omp.terminator
337+
!CHECK: }
338+
!CHECK: omp.terminator
339+
!CHECK: }
340+
!CHECK: return
341+
!CHECK: }
342+
subroutine common_3()
343+
integer :: x
344+
integer :: y
345+
common /blk/ x, y
346+
!$omp threadprivate (/blk/)
347+
348+
!$omp parallel sections copyin(/blk/)
349+
!$omp section
350+
y = y + 3
351+
!$omp end parallel sections
352+
end subroutine

0 commit comments

Comments
 (0)