[flang-commits] [flang] [flang][OpenMP] Initialize allocatable members of derived types (PR #120295)

via flang-commits flang-commits at lists.llvm.org
Thu Dec 19 01:16:28 PST 2024


================
@@ -116,6 +116,31 @@ void DataSharingProcessor::cloneSymbol(const semantics::Symbol *sym) {
       *sym, /*skipDefaultInit=*/isFirstPrivate);
   (void)success;
   assert(success && "Privatization failed due to existing binding");
+
+  // Initialize clone from original object if it has any allocatable member.
+  auto needInitClone = [&] {
+    if (isFirstPrivate)
+      return false;
+
+    SymbolBox sb = symTable.lookupSymbol(sym);
+    assert(sb);
+    mlir::Value addr = sb.getAddr();
+    assert(addr);
+    mlir::Type ty = addr.getType();
+
+    // Unwrap type
+    while (auto eleTy = fir::dyn_cast_ptrOrBoxEleTy(ty))
+      ty = eleTy;
+    // For arrays, use its element type
+    if (auto seqTy = mlir::dyn_cast<fir::SequenceType>(ty))
+      ty = seqTy.getEleTy();
+    return fir::isRecordWithAllocatableMember(ty);
----------------
jeanPerier wrote:

```suggestion
    return hlfir::mayHaveAllocatableComponent(addr.getType());
```

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


More information about the flang-commits mailing list