[flang-commits] [flang] [flang] Disallow implied-DO indices in initial data target subscripts (PR #177989)
via flang-commits
flang-commits at lists.llvm.org
Mon Jan 26 08:07:32 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-semantics
Author: Miguel Saldivar (Saldivarcher)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/177989.diff
2 Files Affected:
- (modified) flang/lib/Evaluate/check-expression.cpp (+4-2)
- (added) flang/test/Semantics/bug79850.f90 (+19)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/177989
More information about the flang-commits
mailing list