[flang-commits] [flang] 5d8354c - [Flang][OpenMP]Missing convert to lhsType in atomic write (#92346)
via flang-commits
flang-commits at lists.llvm.org
Thu May 16 20:50:55 PDT 2024
Author: harishch4
Date: 2024-05-17T09:20:52+05:30
New Revision: 5d8354c009d5625fa140be47de1f91275f4698d3
URL: https://github.com/llvm/llvm-project/commit/5d8354c009d5625fa140be47de1f91275f4698d3
DIFF: https://github.com/llvm/llvm-project/commit/5d8354c009d5625fa140be47de1f91275f4698d3.diff
LOG: [Flang][OpenMP]Missing convert to lhsType in atomic write (#92346)
Fixes test.f90 in #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(#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.
Added:
Modified:
flang/lib/Lower/DirectivesCommon.h
flang/test/Lower/OpenMP/atomic-write.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/DirectivesCommon.h b/flang/lib/Lower/DirectivesCommon.h
index 42bd3868196b2..48b090f6d2dbe 100644
--- a/flang/lib/Lower/DirectivesCommon.h
+++ b/flang/lib/Lower/DirectivesCommon.h
@@ -180,6 +180,9 @@ static inline void genOmpAccAtomicWriteStatement(
// Generate `atomic.write` operation for atomic assignment statements
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+ mlir::Type varType = fir::unwrapRefType(lhsAddr.getType());
+ rhsExpr = firOpBuilder.createConvert(loc, varType, rhsExpr);
+
if constexpr (std::is_same<AtomicListT,
Fortran::parser::OmpAtomicClauseList>()) {
// If no hint clause is specified, the effect is as if
diff --git a/flang/test/Lower/OpenMP/atomic-write.f90 b/flang/test/Lower/OpenMP/atomic-write.f90
index 85955af64bbe2..e0fa802976d96 100644
--- a/flang/test/Lower/OpenMP/atomic-write.f90
+++ b/flang/test/Lower/OpenMP/atomic-write.f90
@@ -73,3 +73,17 @@ subroutine atomic_write_typed_assign
!$omp atomic write
r2 = 0
end subroutine
+
+!CHECK-LABEL: func.func @_QPatomic_write_logical()
+!CHECK: %[[L_REF:.*]] = fir.alloca !fir.logical<4> {bindc_name = "l", uniq_name = "_QFatomic_write_logicalEl"}
+!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>>)
+!CHECK: %true = arith.constant true
+!CHECK: %[[CVT:.*]] = fir.convert %true : (i1) -> !fir.logical<4>
+!CHECK: omp.atomic.write %[[L_DECL]]#1 = %[[CVT]] : !fir.ref<!fir.logical<4>>, !fir.logical<4>
+
+subroutine atomic_write_logical
+ logical :: l
+ !$omp atomic write
+ l = .true.
+ !$omp end atomic
+end
More information about the flang-commits
mailing list