Skip to content

Fix crash in dynamics due to Fortran standard violation#1448

Merged
mgduda merged 3 commits into
MPAS-Dev:hotfix-v8.4.1from
kuanchihwang:staging/fix-undefined-pointer-argument
Jun 5, 2026
Merged

Fix crash in dynamics due to Fortran standard violation#1448
mgduda merged 3 commits into
MPAS-Dev:hotfix-v8.4.1from
kuanchihwang:staging/fix-undefined-pointer-argument

Conversation

@kuanchihwang
Copy link
Copy Markdown
Contributor

At line 1970 inside the atm_srk3 time stepping subroutine, if the DO_PHYSICS macro is undefined, the diag_physics pointer will not be initialized by the call to mpas_pool_get_subpool, and therefore its pointer association status will remain undefined.

However, at line 2250, this pointer is used as an actual argument to call atm_compute_dyn_tend, which constitutes a Fortran standard violation.

Quoted from Fortran 2023,

15.5.2.4 Argument association
Except in references to intrinsic inquiry functions, a pointer actual argument that corresponds to a nonoptional nonpointer dummy argument shall be pointer associated with a target.

This bug can lead to a runtime crash for models that use MPAS as a dynamical core (e.g., CAM, CAM-SIMA).

Fix this issue by adding the pointer attribute to the diag_physics dummy argument for the atm_compute_dyn_tend subroutine.

In addition, two one-line changes have also been introduced to better conform to the Fortran best practices.

@mgduda
Copy link
Copy Markdown
Contributor

mgduda commented Jun 4, 2026

@kuanchihwang Could you rebase this PR branch off of the v8.4.0 tag? Also, would you see if there's additional details that could be included in the one-line summary of each commit message (while staying under 80 characters)? This is helpful, e.g., when scanning through the commit log with git log --oneline. Adding variable, function, or file names, etc. helps to make this output easier to sift through with, e.g., grep.

…nt in atm_srk3

At line 1970 inside the `atm_srk3` time stepping subroutine, if the `DO_PHYSICS` macro
is undefined, the `diag_physics` pointer will not be initialized by the call to the
`mpas_pool_get_subpool` subroutine, and therefore its pointer association status will
remain undefined.

However, at line 2250, this pointer is used as an actual argument to call the
`atm_compute_dyn_tend` subroutine, which constitutes a Fortran standard violation.

Quoted from Fortran 2023,

> 15.5.2.4 Argument association
> Except in references to intrinsic inquiry functions, a pointer actual argument that
> corresponds to a nonoptional nonpointer dummy argument shall be pointer associated with
> a target.

This bug can lead to a runtime crash for models that use MPAS as a dynamical core
(e.g., CAM, CAM-SIMA).

Fix this issue by adding the `pointer` attribute to the `diag_physics` dummy argument
for the `atm_compute_dyn_tend` subroutine.
Throughout the `atm_compute_dyn_tend` subroutine, the `tend_physics` pointer dummy
argument never changes its pointer association status. Add the missing `intent(in)`
attribute for better safety.
In Fortran, explicit initialization of a variable implies the `save` attribute,
which may have surprising result and is not thread-safe.

Avoid doing it to conform to the Fortran best practices.
@kuanchihwang kuanchihwang force-pushed the staging/fix-undefined-pointer-argument branch from 2bef546 to 94029b3 Compare June 5, 2026 18:25
@kuanchihwang
Copy link
Copy Markdown
Contributor Author

I rebased the PR branch against the v8.4.0 tag. I also added clues about subroutine names to the commit titles.

Copy link
Copy Markdown
Contributor

@mgduda mgduda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for uncovering this issue, and thanks for the fix!

@mgduda mgduda merged commit 62b3a0a into MPAS-Dev:hotfix-v8.4.1 Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants