[flang-commits] [flang] [Flang][OpenMP] Correct ArrayElements in Reduction Clause (PR #196094)
Jack Styles via flang-commits
flang-commits at lists.llvm.org
Wed May 13 06:49:35 PDT 2026
================
@@ -1592,6 +1592,29 @@ static bool hasDeferredCharacterLength(const Fortran::semantics::Symbol &sym) {
type->characterTypeSpec().length().isDeferred();
}
+static mlir::Value
+findOverriddenExprValue(const Fortran::lower::ExprToValueMap &map,
+ const Fortran::lower::SomeExpr &expr) {
+ if (auto match = map.find(&expr); match != map.end())
+ return match->second;
+
+ if (!Fortran::evaluate::IsArrayElement(expr))
+ return {};
+
+ for (auto [key, value] : map) {
+ if (key == llvm::DenseMapInfo<
+ const Fortran::lower::SomeExpr *>::getEmptyKey() ||
+ key == llvm::DenseMapInfo<
+ const Fortran::lower::SomeExpr *>::getTombstoneKey())
+ continue;
+ if (Fortran::evaluate::IsArrayElement(*key) &&
+ key->AsFortran() == expr.AsFortran())
----------------
Stylie777 wrote:
I'm not sure this is defensive, rather ensuring that cases where multiple array elements are included in a reduction (say `reduction(+: a(2), a(3))`, the correct element is selected. Otherwise it may end up selecting the wrong array element.
I have however reworked this to use the ArrayRef's for comparison rather than pure string comparison, this is safer and allows for Array Sections too.
https://github.com/llvm/llvm-project/pull/196094
More information about the flang-commits
mailing list