[flang-commits] [flang] [flang] Disallow implied-DO indices in initial data target subscripts (PR #177989)
Miguel Saldivar via flang-commits
flang-commits at lists.llvm.org
Mon Jan 26 08:06:58 PST 2026
https://github.com/Saldivarcher created https://github.com/llvm/llvm-project/pull/177989
Since implied-DO indices are dynamic and depend on runtime iteration variables, it should not be considered for initial data targets. Only constant, scalar subscripts without implied-DO indices should be considered.
>From a50867a0cc1fb738a2c4c775329bd4735a05ebbb Mon Sep 17 00:00:00 2001
From: Miguel Saldivar <miguel.saldivar at hpe.com>
Date: Sun, 25 Jan 2026 10:37:09 -0600
Subject: [PATCH] [flang] Disallow implied-DO indices in initial data target
subscripts
Since implied-DO indices are dynamic and depend on runtime iteration
variables, it should not be considered for initial data targets. Only
constant, scalar subscripts without implied-DO indices should be
considered.
---
flang/lib/Evaluate/check-expression.cpp | 6 ++++--
flang/test/Semantics/bug79850.f90 | 19 +++++++++++++++++++
2 files changed, 23 insertions(+), 2 deletions(-)
create mode 100644 flang/test/Semantics/bug79850.f90
diff --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp
index f7636ecacfb78..50d40c3636655 100644
--- a/flang/lib/Evaluate/check-expression.cpp
+++ b/flang/lib/Evaluate/check-expression.cpp
@@ -299,8 +299,10 @@ class IsInitialDataTargetHelper
return common::visit(common::visitors{
[&](const Triplet &t) { return (*this)(t); },
[&](const auto &y) {
- return y.value().Rank() == 0 &&
- IsConstantExpr(y.value());
+ const auto &v = y.value();
+ return v.Rank() == 0 &&
+ !ContainsAnyImpliedDoIndex(v) &&
+ IsConstantExpr(v);
},
},
x.u);
diff --git a/flang/test/Semantics/bug79850.f90 b/flang/test/Semantics/bug79850.f90
new file mode 100644
index 0000000000000..ab826f510f8a2
--- /dev/null
+++ b/flang/test/Semantics/bug79850.f90
@@ -0,0 +1,19 @@
+! RUN: %flang_fc1 -emit-fir -o /dev/null %s 2>&1 | FileCheck %s --allow-empty
+! CHECK-NOT: error
+! CHECK-NOT: ac-do-variable has no binding
+!
+! Regression test for https://github.com/llvm/llvm-project/issues/79850
+! Ensure flang does not crash when compiling code that uses pointer components
+! in structure constructors.
+
+program p
+ type child
+ integer, pointer :: id
+ end type
+
+ integer, target :: t1(10)
+ type(child) :: t2(10)
+
+ t1 = 0
+ t2 = (/ ( child(t1(i)), i=1,10 ) /)
+end program
More information about the flang-commits
mailing list