[all-commits] [llvm/llvm-project] d0ddae: [flang] Fix segfault in CSHIFT/EOSHIFT with dynami...
Sairudra More via All-commits
all-commits at lists.llvm.org
Sun Mar 8 22:24:47 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: d0ddae678e3f634c988542dfbdde1dd0afe66344
https://github.com/llvm/llvm-project/commit/d0ddae678e3f634c988542dfbdde1dd0afe66344
Author: Sairudra More <sairudra60 at gmail.com>
Date: 2026-03-09 (Mon, 09 Mar 2026)
Changed paths:
M flang/lib/Lower/HlfirIntrinsics.cpp
M flang/lib/Optimizer/Builder/IntrinsicCall.cpp
A flang/test/Lower/HLFIR/cshift-optional-dim.f90
Log Message:
-----------
[flang] Fix segfault in CSHIFT/EOSHIFT with dynamically optional DIM (#184431)
When `DIM` is passed as an optional dummy argument and is absent at
runtime, the HLFIR lowering for the `CSHIFT` and `EOSHIFT` intrinsics
treated it as unconditionally present. This resulted in an unconditional
load of the `DIM` reference, causing a null pointer dereference and a
runtime segmentation fault when absent.
The underlying issue was that the `dim` argument for `cshift` and
`eoshift` was not marked with `handleDynamicOptional` during intrinsic
argument lowering setup. As a result, the `isPresent` state was never
populated, and the lowering implementation incorrectly fell through to
an unconditional scalar load.
This patch resolves the issue by:
1. Updating the `dim` entries for `cshift` and `eoshift` in
`IntrinsicCall.cpp` to use `handleDynamicOptional`. This enables
`getOperandVector()` to appropriately emit a guarded load (via
`loadOptionalValue()`) that safely returns a 0 placeholder when `DIM` is
absent.
2. Updating the HLFIR lowering implementations (`HlfirCShiftLowering`
and `HlfirEOShiftLowering`) to use the loaded scalar. It now employs an
`arith.select` to substitute the 0 placeholder with the
standard-mandated default of 1 when `isPresent` is false, matching the
Fortran requirements (§16.9.68 and §16.9.77) without generating
redundant `fir.if` or `fir.load` operations. Explicit `DIM=0` calls
still correctly forward the 0 value to flang-rt to trigger the
appropriate runtime bounds check error.
Co-authored-by: Sairudra More <moresair at pe31.hpc.amslabs.hpecorp.net>
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list