Skip to content

Commit 7cee61c

Browse files
[Flang][OpenMP] Fix lastprivate store issue (#92777)
Fix an issue where the lastprivate variable type is different from the type used for the index of the loop. Fixes #79780
1 parent 9d70975 commit 7cee61c

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

flang/lib/Lower/OpenMP/DataSharingProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ void DataSharingProcessor::insertLastPrivateCompare(mlir::Operation *op) {
225225
auto ifOp = firOpBuilder.create<fir::IfOp>(loc, cmpOp, /*else*/ false);
226226
firOpBuilder.setInsertionPointToStart(&ifOp.getThenRegion().front());
227227
assert(loopIV && "loopIV was not set");
228-
firOpBuilder.create<fir::StoreOp>(loopOp.getLoc(), v, loopIV);
228+
firOpBuilder.createStoreWithConvert(loc, v, loopIV);
229229
lastPrivIP = firOpBuilder.saveInsertionPoint();
230230
} else if (mlir::isa<mlir::omp::SectionsOp>(op)) {
231231
// Already handled by genOMP()

flang/test/Lower/OpenMP/lastprivate-iv.f90

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,22 @@ subroutine lastprivate_iv_dec()
7070
end do
7171
!$omp end do
7272
end subroutine
73+
74+
75+
!CHECK-LABEL: @_QPlastprivate_iv_i1
76+
subroutine lastprivate_iv_i1
77+
integer*1 :: i1
78+
i1=0
79+
!CHECK: omp.wsloop
80+
!CHECK: omp.loop_nest
81+
!CHECK: fir.if %{{.*}} {
82+
!CHECK: %[[I8_VAL:.*]] = fir.convert %{{.*}} : (i32) -> i8
83+
!CHECK: fir.store %[[I8_VAL]] to %[[IV:.*]]#1 : !fir.ref<i8>
84+
!CHECK: %[[IV_VAL:.*]] = fir.load %[[IV]]#0 : !fir.ref<i8>
85+
!CHECK: hlfir.assign %[[IV_VAL]] to %{{.*}}#0 temporary_lhs : i8, !fir.ref<i8>
86+
!CHECK: }
87+
!$omp do lastprivate(i1)
88+
do i1=1,8
89+
enddo
90+
!$omp end do
91+
end subroutine

0 commit comments

Comments
 (0)