[flang-commits] [flang] [flang] fix private pointers and default initialized variables (PR #118494)

Leandro Lupori via flang-commits flang-commits at lists.llvm.org
Tue Dec 3 08:38:58 PST 2024


================
@@ -822,7 +830,20 @@ class FirConverter : public Fortran::lower::AbstractConverter {
           if_builder.end();
         },
         [&](const auto &) -> void {
-          // Do nothing
+          // Initialize local/private derived types with default
+          // initialization (Fortran 2023 section 11.1.7.5 and OpenMP 5.2
+          // section 5.3). Pointer and allocatable components, when allowed,
+          // also need to be established so that flang runtime can later work
+          // with them.
+          if (const Fortran::semantics::DeclTypeSpec *declTypeSpec =
+                  sym.GetType())
+            if (const Fortran::semantics::DerivedTypeSpec *derivedTypeSpec =
+                    declTypeSpec->AsDerived())
+              if (derivedTypeSpec->HasDefaultInitialization(
+                      /*ignoreAllocatable=*/false, /*ignorePointer=*/false)) {
+                mlir::Value box = builder->createBox(loc, exv);
+                fir::runtime::genDerivedTypeInitialize(*builder, loc, box);
+              }
----------------
luporl wrote:

`DataSharingProcessor::cloneSymbol` does something similar for privatizations, except for firstprivate:

```c++
  if (!isFirstPrivate &&
      Fortran::lower::hasDefaultInitialization(sym->GetUltimate()))
    Fortran::lower::defaultInitializeAtRuntime(converter, *sym, *symTable);
```

Won't this make `Initialize` be called twice for private clauses?

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


More information about the flang-commits mailing list