[flang-commits] [flang] [flang] Ignore -fno-realloc-lhs for polymorphic allocatable LHS with warning (PR #192697)

Eugene Epshteyn via flang-commits flang-commits at lists.llvm.org
Fri Apr 17 11:21:05 PDT 2026


================
@@ -5592,15 +5592,28 @@ class FirConverter : public Fortran::lower::AbstractConverter {
 
     // Gather some information about the assignment that will impact how it is
     // lowered.
-    const bool isWholeAllocatableAssignment =
+    const bool lhsIsWholeAllocatable =
         !userDefinedAssignment && !isInsideHlfirWhere() &&
-        Fortran::lower::isWholeAllocatable(assign.lhs) &&
-        bridge.getLoweringOptions().getReallocateLHS();
+        Fortran::lower::isWholeAllocatable(assign.lhs);
+    std::optional<Fortran::evaluate::DynamicType> lhsType =
+        assign.lhs.GetType();
+    // Polymorphic allocatable LHS always requires reallocation semantics
+    // regardless of -fno-realloc-lhs: assignment to a polymorphic variable
+    // is a F2003+ feature that requires dynamic type tracking, which cannot
+    // be safely skipped.  When -fno-realloc-lhs is specified but the LHS is
+    // polymorphic, emit a warning and proceed with reallocation semantics.
+    const bool lhsIsPolymorphic =
+        lhsType.has_value() && lhsType->IsPolymorphic();
+    if (lhsIsWholeAllocatable && lhsIsPolymorphic &&
+        !bridge.getLoweringOptions().getReallocateLHS())
+      mlir::emitWarning(loc, "-fno-realloc-lhs is ignored for assignment to "
----------------
eugeneepshteyn wrote:

We would need to promote NoReallocateLHS to a proper language option, so that it's visible from Semantics. (Currently it's only a Lowering option.)

I can investigate.

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


More information about the flang-commits mailing list