[flang-commits] [flang] [flang][runtime] Establish derived type desc properly. (PR #67623)

via flang-commits flang-commits at lists.llvm.org
Fri Sep 29 01:53:32 PDT 2023


================
@@ -96,12 +96,19 @@ void Descriptor::Establish(const typeInfo::DerivedType &dt, void *p, int rank,
 
 OwningPtr<Descriptor> Descriptor::Create(TypeCode t, std::size_t elementBytes,
     void *p, int rank, const SubscriptValue *extent,
-    ISO::CFI_attribute_t attribute, int derivedTypeLenParameters) {
-  std::size_t bytes{SizeInBytes(rank, true, derivedTypeLenParameters)};
+    ISO::CFI_attribute_t attribute, bool addendum,
+    const typeInfo::DerivedType *dt) {
   Terminator terminator{__FILE__, __LINE__};
+  RUNTIME_CHECK(terminator, t.IsDerived() == (dt != nullptr));
+  int derivedTypeLenParameters = dt ? dt->LenParameters() : 0;
+  std::size_t bytes{SizeInBytes(rank, addendum, derivedTypeLenParameters)};
   Descriptor *result{
       reinterpret_cast<Descriptor *>(AllocateMemoryOrCrash(terminator, bytes))};
-  result->Establish(t, elementBytes, p, rank, extent, attribute, true);
----------------
jeanPerier wrote:

Thanks for clarifying, I think it is fine then.
Every fir.load of c descriptor may create a copy that will unconditionally copy the addendum, I was worried some descriptor allocated by the runtime without addendum would make it into inlined code as the descriptor of an unlimited polymorphic, but that is not what your patch is doing and the f18addendum flag is actually never used in inlined code (it is only set or copied).

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


More information about the flang-commits mailing list