Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: MFlowCode/MFC
Length of output: 3208
🏁 Script executed:
Repository: MFlowCode/MFC
Length of output: 4173
Aliasing violation and logic error:
s_decode_patch_periodicitycalled with same variable for encoded input and decoded output.The call
s_decode_patch_periodicity(patch_id, patch_id)at line 204 passes the same variable as both theintent(in)argument (encoded patch ID) and theintent(out)argument (decoded patch ID). The subroutine signature confirms this:This is a non-conforming Fortran argument alias. The Fortran standard prohibits the same actual argument from being associated with both
intent(in)andintent(out)dummy arguments in a single call. gfortran's-Waliasingflag specifically warns about this pattern. Under optimization on any of the four required compilers (gfortran, nvfortran, Cray ftn, ifx), the compiler may reorder reads and writes, causing theintent(in)value to be read after theintent(out)write, producing a decoded value derived from garbage instead of the original encoded ID.Additionally, this introduces a logic error:
ghost_points(i)%ib_patch_idis populated with an already-decoded value (line 576:ghost_points_in(local_idx)%ib_patch_id = patch_idwherepatch_idresults from a decode call). Decoding an already-decoded value will produce incorrect results.Fix: pass the encoded struct field directly as the first argument and write the decoded result to
patch_id:Proposed fix