[flang-commits] [flang] [flang] Fix segfault in CSHIFT/EOSHIFT with dynamically optional DIM (PR #184431)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Wed Mar 4 09:06:37 PST 2026


================
@@ -489,6 +490,30 @@ mlir::Value HlfirCShiftLowering::lowerImpl(
   if (!dim) {
     // If DIM is not present, drop the last element which is a null Value.
     operands.truncate(2);
+  } else if (loweredActuals[2] && loweredActuals[2]->handleDynamicOptional()) {
+    // DIM is a dynamically optional dummy argument.
+    // Use getIsPresent() directly (per eugeneepshteyn's review) rather than a
+    // 0-sentinel arithmetic check. Building our own fir.if ensures an
+    // explicitly-passed DIM=0 loads the actual value and reaches the runtime
+    // bounds check (per vzakhari's review), while an absent DIM defaults to 1
+    // per Fortran §16.9.68.
----------------
vzakhari wrote:

```suggestion
    // Use getIsPresent() to select between a present DIM value or
    // the default 1 per Fortran 16.9.68.
```

I would recommend to avoid using special symbols like §

https://github.com/llvm/llvm-project/pull/184431


More information about the flang-commits mailing list