Skip to content

Commit

Permalink
fix: use a bigger real transfering mask_val
Browse files Browse the repository at this point in the history
this change ensures the type of `mask_val` is big enough to satisfy the
`transfer`; otherwise, we risk transfering a 4-byte value to 2-element
arrays of 4-byte elements (i.e., `i4tmp(2)` and `r4tmp(2)`)

I encountered this issue compiling the project with Flang; see
https://godbolt.org/z/91EfY154n
  • Loading branch information
inaki-amatria committed Sep 5, 2024
1 parent d13c129 commit 4f25487
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mpp/include/mpp_chksum_int.fh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function MPP_CHKSUM_INT_RMASK_( var, pelist, mask_val )
MPP_TYPE_, intent(in) :: var MPP_RANK_
integer, optional :: pelist(:)
real, intent(in) :: mask_val
real(KIND=r8_kind) :: tmp_mask_val
integer(KIND(var))::imask_val
integer(KIND=i4_kind)::i4tmp(2)=0
real(KIND=r4_kind)::r4tmp(2)=0
Expand All @@ -74,9 +75,10 @@ function MPP_CHKSUM_INT_RMASK_( var, pelist, mask_val )
! Secondary Logic:
!! We've done something dangerous
else
i8tmp = TRANSFER(mask_val , i8tmp )
i4tmp = TRANSFER(mask_val , i4tmp )
r4tmp = TRANSFER(mask_val , r4tmp )
tmp_mask_val = mask_val
i8tmp = TRANSFER(tmp_mask_val , i8tmp )
i4tmp = TRANSFER(tmp_mask_val , i4tmp )
r4tmp = TRANSFER(tmp_mask_val , r4tmp )
if ( i8tmp == MPP_FILL_INT ) then
! we've packed an MPP_FILL_
imask_val = MPP_FILL_INT
Expand Down

0 comments on commit 4f25487

Please sign in to comment.