diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp --- a/flang/lib/Lower/OpenMP.cpp +++ b/flang/lib/Lower/OpenMP.cpp @@ -1669,8 +1669,10 @@ mlir::Value result = fir::getBase(converter.genExprValue( *Fortran::semantics::GetExpr(assignmentStmtExpr), stmtCtx)); + mlir::Value convertResult = + firOpBuilder.createConvert(currentLocation, varType, result); // Insert the terminator: YieldOp. - firOpBuilder.create(currentLocation, result); + firOpBuilder.create(currentLocation, convertResult); // Reset the insert point to before the terminator. firOpBuilder.setInsertionPointToStart(&block); } diff --git a/flang/test/Lower/OpenMP/atomic-update.f90 b/flang/test/Lower/OpenMP/atomic-update.f90 --- a/flang/test/Lower/OpenMP/atomic-update.f90 +++ b/flang/test/Lower/OpenMP/atomic-update.f90 @@ -7,6 +7,8 @@ integer :: x, y, z integer, pointer :: a, b integer, target :: c, d + integer(1) :: i1 + a=>c b=>d @@ -21,6 +23,7 @@ !CHECK: fir.store %{{.*}} to %[[B_ADDR]] : !fir.ref> !CHECK: %[[C_ADDR:.*]] = fir.address_of(@_QFEc) : !fir.ref !CHECK: %[[D_ADDR:.*]] = fir.address_of(@_QFEd) : !fir.ref +!CHECK: %[[I1:.*]] = fir.alloca i8 {bindc_name = "i1", uniq_name = "_QFEi1"} !CHECK: %[[X:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFEx"} !CHECK: %[[Y:.*]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFEy"} !CHECK: %[[Z:.*]] = fir.alloca i32 {bindc_name = "z", uniq_name = "_QFEz"} @@ -115,10 +118,22 @@ !CHECK: %[[RESULT:.*]] = arith.addi %[[LOADED_Y]], %[[ARG]] : i32 !CHECK: omp.yield(%[[RESULT]] : i32) !CHECK: } -!CHECK: return -!CHECK: } !$omp atomic hint(omp_sync_hint_nonspeculative) seq_cst y = 10 + y !$omp atomic seq_cst update z = y + z + +!CHECK: omp.atomic.update %[[I1]] : !fir.ref { +!CHECK: ^bb0(%[[VAL:.*]]: i8): +!CHECK: %[[CVT_VAL:.*]] = fir.convert %[[VAL]] : (i8) -> i32 +!CHECK: %[[C1_VAL:.*]] = arith.constant 1 : i32 +!CHECK: %[[ADD_VAL:.*]] = arith.addi %[[CVT_VAL]], %[[C1_VAL]] : i32 +!CHECK: %[[UPDATED_VAL:.*]] = fir.convert %[[ADD_VAL]] : (i32) -> i8 +!CHECK: omp.yield(%[[UPDATED_VAL]] : i8) +!CHECK: } + !$omp atomic + i1 = i1 + 1 + !$omp end atomic +!CHECK: return +!CHECK: } end program OmpAtomicUpdate