[clang] [flang] [flang] Add support for -finit-local-zero (PR #159788)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 28 00:59:24 PDT 2026
================
@@ -1317,6 +1366,48 @@ static void instantiateLocal(Fortran::lower::AbstractConverter &converter,
Fortran::lower::genUnpackArray(*converterPtr, loc, *varDef, *sym);
});
}
+
+ /// These options do not initialize:
+ /// 1) Any variable already initialized
+ /// 2) objects with the POINTER attribute
+ /// 3) allocatable arrays
+ /// 4) variables that appear in an EQUIVALENCE statement
+
+ auto isEligibleForImplicitAssignment = [&var]() -> bool {
+ if (!var.hasSymbol())
+ return false;
+
+ const Fortran::semantics::Symbol &sym = var.getSymbol();
+ if (const auto *details =
+ sym.detailsIf<Fortran::semantics::ObjectEntityDetails>()) {
+ if (details->init())
+ return false;
+ }
+
+ if (sym.attrs().test(Fortran::semantics::Attr::POINTER))
+ return false;
+
+ if (sym.Rank() > 0 &&
+ sym.attrs().test(Fortran::semantics::Attr::ALLOCATABLE))
+ return false;
----------------
jeanPerier wrote:
The code that you have will segfault (you can test it end to end, this is doing a plain write to null.
However, where is the requirement that `-finit-local-zero` should initialize local scalar allocatable, as far as I see, gfortran is not doing it and it seems a bit odd to me. I do not think we need to allocate/initialize allocatable on entry, this could change the behavior of valid programs (given this changes the result of ALLOCATED initrinsic), and any usage of unitialized allocatable will be caught by a segfault since the base address is set to null.
I would advise rejecting all allocatables.
https://github.com/llvm/llvm-project/pull/159788
More information about the cfe-commits
mailing list