Skip to content

IBM: s_ibm_correct_state dereferences absent optional dummies (pb_in/mv_in) with no present() guard #1691

Description

@sbryngelson

Bug

s_ibm_correct_state (src/simulation/m_ibm.fpp:143) declares pb_in/mv_in as optional:

real(stp), dimension(...), optional, intent(inout) :: pb_in, mv_in

but m_ibm.fpp contains zero present() calls. The routine uses them unconditionally. One of
its two call sites omits them (m_time_steppers.fpp:556):

if (qbmm .and. .not. polytropic) then
    call s_ibm_correct_state(q_cons_ts(1)%vf, q_prim_vf, pb_ts(1)%sf, mv_ts(1)%sf)
else
    call s_ibm_correct_state(q_cons_ts(1)%vf, q_prim_vf)      ! absent optionals
end if

That path is undefined behaviour. It happens to survive on some compilers; on Cray CCE 21 the
absent dummy presents a null dope vector to the device data environment and the run segfaults
(exit 139) on every IBM test.

Fix

pb_ts(1)%sf is always allocatedm_time_steppers.fpp allocates it in both branches
(full size when QBMM, beg:beg+1 otherwise), both with ACC_SETUP_SFs, and deallocates it
unconditionally. So it can be passed unconditionally:

  1. drop optional from pb_in/mv_in in m_ibm.fpp:143
  2. replace the if/else at m_time_steppers.fpp:553 with the single call

This is a net simplification (−4 lines) and removes the branch rather than making the absent
case survivable. Safe because the writes at m_ibm.fpp:437-438 are already guarded by
if (qbmm) / if (.not. polytropic), so the small non-QBMM allocation is never indexed.

Verification

Frontier (MI250X), CCE 21.0.2 / ROCm 7.2.0, full 627-test suite: zero exit-139 segfaults
after this change, where the IBM tests previously aborted. Found independently by two sessions.

Related

There is a second routine with the same shape that is not covered by this fix:
s_interpolate_image_point (m_ibm.fpp:807) has nine optional array dummies, and its call
sites pass different subsets — e.g. m_ibm.fpp:251 passes one and omits nine. That is a
suspect for a remaining IBM fault and should be audited the same way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions