Skip to content

Commit 5d8354c

Browse files
authored
[Flang][OpenMP]Missing convert to lhsType in atomic write (llvm#92346)
Fixes test.f90 in llvm#83144. This issue is observed only when a boolean constant is assigned to a logical variable. In non-openmp flow, a conversion op is inserted before assigning it to a logical variable. This patch will insert a fir.convert operation when the types are not the same, before generating the atomic write operation. I've proposed another patch(llvm#85059 ) which removes checks at MLIR level and looks like it's too permissive. I'm planning to abandon this patch and address it here.
1 parent c339226 commit 5d8354c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

flang/lib/Lower/DirectivesCommon.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ static inline void genOmpAccAtomicWriteStatement(
180180
// Generate `atomic.write` operation for atomic assignment statements
181181
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
182182

183+
mlir::Type varType = fir::unwrapRefType(lhsAddr.getType());
184+
rhsExpr = firOpBuilder.createConvert(loc, varType, rhsExpr);
185+
183186
if constexpr (std::is_same<AtomicListT,
184187
Fortran::parser::OmpAtomicClauseList>()) {
185188
// If no hint clause is specified, the effect is as if

flang/test/Lower/OpenMP/atomic-write.f90

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,17 @@ subroutine atomic_write_typed_assign
7373
!$omp atomic write
7474
r2 = 0
7575
end subroutine
76+
77+
!CHECK-LABEL: func.func @_QPatomic_write_logical()
78+
!CHECK: %[[L_REF:.*]] = fir.alloca !fir.logical<4> {bindc_name = "l", uniq_name = "_QFatomic_write_logicalEl"}
79+
!CHECK: %[[L_DECL:.*]]:2 = hlfir.declare %[[L_REF]] {uniq_name = "_QFatomic_write_logicalEl"} : (!fir.ref<!fir.logical<4>>) -> (!fir.ref<!fir.logical<4>>, !fir.ref<!fir.logical<4>>)
80+
!CHECK: %true = arith.constant true
81+
!CHECK: %[[CVT:.*]] = fir.convert %true : (i1) -> !fir.logical<4>
82+
!CHECK: omp.atomic.write %[[L_DECL]]#1 = %[[CVT]] : !fir.ref<!fir.logical<4>>, !fir.logical<4>
83+
84+
subroutine atomic_write_logical
85+
logical :: l
86+
!$omp atomic write
87+
l = .true.
88+
!$omp end atomic
89+
end

0 commit comments

Comments
 (0)