[flang-commits] [flang] 6d44387 - [flang] Make subscript list argument a nullable pointer

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Mon Nov 8 12:12:56 PST 2021


Author: peter klausler
Date: 2021-11-08T11:53:13-08:00
New Revision: 6d44387e21a1b78eb7263f3610e7f11a42fecd24

URL: https://github.com/llvm/llvm-project/commit/6d44387e21a1b78eb7263f3610e7f11a42fecd24
DIFF: https://github.com/llvm/llvm-project/commit/6d44387e21a1b78eb7263f3610e7f11a42fecd24.diff

LOG: [flang] Make subscript list argument a nullable pointer

Component::CreatePointerDescriptor unconditionally expects a
vector of subscripts to be passed as an argument, but is called
from NAMELIST input with a null pointer.  Make that argument
a nullable pointer, move it to the end of the argument list,
and give it a default value of nullptr.

Differential Revision: https://reviews.llvm.org/D113312

Added: 
    

Modified: 
    flang/runtime/assign.cpp
    flang/runtime/descriptor-io.h
    flang/runtime/namelist.cpp
    flang/runtime/type-info.cpp
    flang/runtime/type-info.h

Removed: 
    


################################################################################
diff  --git a/flang/runtime/assign.cpp b/flang/runtime/assign.cpp
index 0455980ddd4d..8d792011a6c8 100644
--- a/flang/runtime/assign.cpp
+++ b/flang/runtime/assign.cpp
@@ -193,9 +193,9 @@ void Assign(Descriptor &to, const Descriptor &from, Terminator &terminator) {
           Descriptor &fromCompDesc{statDesc[1].descriptor()};
           for (std::size_t j{0}; j < toElements; ++j,
                to.IncrementSubscripts(toAt), from.IncrementSubscripts(fromAt)) {
-            comp.CreatePointerDescriptor(toCompDesc, to, toAt, terminator);
+            comp.CreatePointerDescriptor(toCompDesc, to, terminator, toAt);
             comp.CreatePointerDescriptor(
-                fromCompDesc, from, fromAt, terminator);
+                fromCompDesc, from, terminator, fromAt);
             Assign(toCompDesc, fromCompDesc, terminator);
           }
         } else { // Component has intrinsic type; simply copy raw bytes

diff  --git a/flang/runtime/descriptor-io.h b/flang/runtime/descriptor-io.h
index f0d3deb69d09..03b7e798af43 100644
--- a/flang/runtime/descriptor-io.h
+++ b/flang/runtime/descriptor-io.h
@@ -249,7 +249,7 @@ static bool DefaultFormattedComponentIO(IoStatementState &io,
     StaticDescriptor<maxRank, true, 16 /*?*/> statDesc;
     Descriptor &desc{statDesc.descriptor()};
     component.CreatePointerDescriptor(
-        desc, origDescriptor, origSubscripts, terminator);
+        desc, origDescriptor, terminator, origSubscripts);
     return DescriptorIO<DIR>(io, desc);
   } else {
     // Component is itself a descriptor

diff  --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp
index 11fe49b5fc9a..0afdee5cfe94 100644
--- a/flang/runtime/namelist.cpp
+++ b/flang/runtime/namelist.cpp
@@ -236,7 +236,7 @@ static bool HandleComponent(IoStatementState &io, Descriptor &desc,
         type{addendum ? addendum->derivedType() : nullptr}) {
       if (const typeInfo::Component *
           comp{type->FindDataComponent(compName, std::strlen(compName))}) {
-        comp->CreatePointerDescriptor(desc, source, nullptr, handler);
+        comp->CreatePointerDescriptor(desc, source, handler);
         return true;
       } else {
         handler.SignalError(
@@ -244,6 +244,10 @@ static bool HandleComponent(IoStatementState &io, Descriptor &desc,
             "a component of its derived type",
             compName, name);
       }
+    } else if (source.type().IsDerived()) {
+      handler.Crash("Derived type object '%s' in NAMELIST is missing its "
+                    "derived type information!",
+          name);
     } else {
       handler.SignalError("NAMELIST component reference '%%%s' of input group "
                           "item %s for non-derived type",
@@ -320,9 +324,14 @@ bool IONAME(InputNamelist)(Cookie cookie, const NamelistGroup &group) {
         Descriptor &mutableDescriptor{staticDesc[whichStaticDesc].descriptor()};
         whichStaticDesc ^= 1;
         if (*next == '(') {
-          HandleSubscripts(io, mutableDescriptor, *useDescriptor, name);
+          if (!(HandleSubscripts(
+                  io, mutableDescriptor, *useDescriptor, name))) {
+            return false;
+          }
         } else {
-          HandleComponent(io, mutableDescriptor, *useDescriptor, name);
+          if (!HandleComponent(io, mutableDescriptor, *useDescriptor, name)) {
+            return false;
+          }
         }
         useDescriptor = &mutableDescriptor;
         next = io.GetCurrentChar();

diff  --git a/flang/runtime/type-info.cpp b/flang/runtime/type-info.cpp
index 8e26a53aac0b..37c3c1f5ab86 100644
--- a/flang/runtime/type-info.cpp
+++ b/flang/runtime/type-info.cpp
@@ -116,11 +116,15 @@ void Component::EstablishDescriptor(Descriptor &descriptor,
 }
 
 void Component::CreatePointerDescriptor(Descriptor &descriptor,
-    const Descriptor &container, const SubscriptValue subscripts[],
-    Terminator &terminator) const {
+    const Descriptor &container, Terminator &terminator,
+    const SubscriptValue *subscripts) const {
   RUNTIME_CHECK(terminator, genre_ == Genre::Data);
   EstablishDescriptor(descriptor, container, terminator);
-  descriptor.set_base_addr(container.Element<char>(subscripts) + offset_);
+  if (subscripts) {
+    descriptor.set_base_addr(container.Element<char>(subscripts) + offset_);
+  } else {
+    descriptor.set_base_addr(container.OffsetElement<char>() + offset_);
+  }
   descriptor.raw().attribute = CFI_attribute_pointer;
 }
 
@@ -167,12 +171,11 @@ static void DumpScalarCharacter(
 }
 
 FILE *DerivedType::Dump(FILE *f) const {
-  std::fprintf(
-      f, "DerivedType @ 0x%p:\n", reinterpret_cast<const void *>(this));
+  std::fprintf(f, "DerivedType @ %p:\n", reinterpret_cast<const void *>(this));
   const std::uint64_t *uints{reinterpret_cast<const std::uint64_t *>(this)};
   for (int j{0}; j < 64; ++j) {
     int offset{j * static_cast<int>(sizeof *uints)};
-    std::fprintf(f, "    [+%3d](0x%p) 0x%016jx", offset,
+    std::fprintf(f, "    [+%3d](%p) 0x%016jx", offset,
         reinterpret_cast<const void *>(&uints[j]),
         static_cast<std::uintmax_t>(uints[j]));
     if (offset == offsetof(DerivedType, binding_)) {
@@ -235,7 +238,7 @@ FILE *DerivedType::Dump(FILE *f) const {
 }
 
 FILE *Component::Dump(FILE *f) const {
-  std::fprintf(f, "Component @ 0x%p:\n", reinterpret_cast<const void *>(this));
+  std::fprintf(f, "Component @ %p:\n", reinterpret_cast<const void *>(this));
   std::fputs("    name: ", f);
   DumpScalarCharacter(f, name(), "Component::name");
   if (genre_ == Genre::Data) {
@@ -252,7 +255,7 @@ FILE *Component::Dump(FILE *f) const {
   std::fprintf(f, " category %d  kind %d  rank %d  offset 0x%zx\n", category_,
       kind_, rank_, static_cast<std::size_t>(offset_));
   if (initialization_) {
-    std::fprintf(f, " initialization @ 0x%p:\n",
+    std::fprintf(f, " initialization @ %p:\n",
         reinterpret_cast<const void *>(initialization_));
     for (int j{0}; j < 128; j += sizeof(std::uint64_t)) {
       std::fprintf(f, " [%3d] 0x%016jx\n", j,
@@ -265,7 +268,7 @@ FILE *Component::Dump(FILE *f) const {
 
 FILE *SpecialBinding::Dump(FILE *f) const {
   std::fprintf(
-      f, "SpecialBinding @ 0x%p:\n", reinterpret_cast<const void *>(this));
+      f, "SpecialBinding @ %p:\n", reinterpret_cast<const void *>(this));
   switch (which_) {
   case Which::ScalarAssignment:
     std::fputs("    ScalarAssignment", f);
@@ -297,7 +300,7 @@ FILE *SpecialBinding::Dump(FILE *f) const {
     break;
   }
   std::fprintf(f, "    isArgDescriptorSet: 0x%x\n", isArgDescriptorSet_);
-  std::fprintf(f, "    proc: 0x%p\n", reinterpret_cast<void *>(proc_));
+  std::fprintf(f, "    proc: %p\n", reinterpret_cast<void *>(proc_));
   return f;
 }
 

diff  --git a/flang/runtime/type-info.h b/flang/runtime/type-info.h
index 9f9bfb6337dd..62b8c6c3cbae 100644
--- a/flang/runtime/type-info.h
+++ b/flang/runtime/type-info.h
@@ -86,9 +86,10 @@ class Component {
   void EstablishDescriptor(
       Descriptor &, const Descriptor &container, Terminator &) const;
 
-  // Creates a pointer descriptor from this component description.
+  // Creates a pointer descriptor from this component description, possibly
+  // with subscripts
   void CreatePointerDescriptor(Descriptor &, const Descriptor &container,
-      const SubscriptValue[], Terminator &) const;
+      Terminator &, const SubscriptValue * = nullptr) const;
 
   FILE *Dump(FILE * = stdout) const;
 


        


More information about the flang-commits mailing list