[flang-commits] [flang] 9438398 - [flang] simplify derived type info table format

Jean Perier via flang-commits flang-commits at lists.llvm.org
Thu May 20 09:28:23 PDT 2021


Author: Jean Perier
Date: 2021-05-20T18:26:53+02:00
New Revision: 943839870a0be356c40629c75d4583976cb9e812

URL: https://github.com/llvm/llvm-project/commit/943839870a0be356c40629c75d4583976cb9e812
DIFF: https://github.com/llvm/llvm-project/commit/943839870a0be356c40629c75d4583976cb9e812.diff

LOG: [flang] simplify derived type info table format

- Replace class(*) member by a c_ptr member to avoid having to handle
  polymorphic components in the type info table generation. Polymorphic
  entity handling will require these very tables to be lowered properly.
  Note: keep the init as NullPointer/Designators. This is technically
  invalid Fortran, the init should have c_ptr type. But wrapping this
  in a C_LOC intrinsic call would make runtime generation and lowering
  more complex with no real benefits.

- ComponentIterator is crashing when used on the generated derived
  types in GetScope. This patch makes GetScope more robust, but it
  is not entirely clear to me why this is only happening with the
  generated derived types.

- The type of generated character globals was incorrect because
  Scope::FindType was matching character types with different
  length. Add a CharacterTypeSpec == operator to fix this.

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

Added: 
    

Modified: 
    flang/include/flang/Semantics/tools.h
    flang/include/flang/Semantics/type.h
    flang/module/__fortran_type_info.f90
    flang/test/Semantics/typeinfo01.f90

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Semantics/tools.h b/flang/include/flang/Semantics/tools.h
index ee368d9bcfe0..bb7d0b6009dd 100644
--- a/flang/include/flang/Semantics/tools.h
+++ b/flang/include/flang/Semantics/tools.h
@@ -459,7 +459,10 @@ template <ComponentKind componentKind> class ComponentIterator {
       name_iterator &nameIterator() { return nameIterator_; }
       name_iterator nameEnd() { return nameEnd_; }
       const Symbol &GetTypeSymbol() const { return derived_->typeSymbol(); }
-      const Scope &GetScope() const { return DEREF(derived_->scope()); }
+      const Scope &GetScope() const {
+        return derived_->scope() ? *derived_->scope()
+                                 : DEREF(GetTypeSymbol().scope());
+      }
       bool operator==(const ComponentPathNode &that) const {
         return &*derived_ == &*that.derived_ &&
             nameIterator_ == that.nameIterator_ &&

diff  --git a/flang/include/flang/Semantics/type.h b/flang/include/flang/Semantics/type.h
index eb506d1661e9..764b65941c12 100644
--- a/flang/include/flang/Semantics/type.h
+++ b/flang/include/flang/Semantics/type.h
@@ -154,6 +154,9 @@ class CharacterTypeSpec : public IntrinsicTypeSpec {
       : IntrinsicTypeSpec(TypeCategory::Character, std::move(kind)),
         length_{std::move(length)} {}
   const ParamValue &length() const { return length_; }
+  bool operator==(const CharacterTypeSpec &that) const {
+    return kind() == that.kind() && length_ == that.length_;
+  }
   std::string AsFortran() const;
 
 private:

diff  --git a/flang/module/__fortran_type_info.f90 b/flang/module/__fortran_type_info.f90
index eaa82e0cb5c3..6fce352c162e 100644
--- a/flang/module/__fortran_type_info.f90
+++ b/flang/module/__fortran_type_info.f90
@@ -88,7 +88,7 @@
     type(DerivedType), pointer :: derived ! for category == Derived
     type(Value), pointer :: lenValue(:) ! (SIZE(derived%lenParameterKind))
     type(Value), pointer :: bounds(:, :) ! (2, rank): lower, upper
-    class(*), pointer :: initialization
+    type(__builtin_c_ptr) :: initialization
   end type
 
   type :: ProcPtrComponent ! procedure pointer components

diff  --git a/flang/test/Semantics/typeinfo01.f90 b/flang/test/Semantics/typeinfo01.f90
index cb568fcf6a09..3a41ea64eef5 100644
--- a/flang/test/Semantics/typeinfo01.f90
+++ b/flang/test/Semantics/typeinfo01.f90
@@ -236,3 +236,14 @@ subroutine s1(x)
     type(t(*)), intent(in) :: x
   end subroutine
 end module
+
+module m12
+  type :: t1
+    integer :: n
+    integer :: n2
+    integer :: n_3
+    ! CHECK: .n.n, SAVE, TARGET: ObjectEntity type: CHARACTER(1_8,1) init:"n"
+    ! CHECK: .n.n2, SAVE, TARGET: ObjectEntity type: CHARACTER(2_8,1) init:"n2"
+    ! CHECK: .n.n_3, SAVE, TARGET: ObjectEntity type: CHARACTER(3_8,1) init:"n_3"
+  end type
+end module


        


More information about the flang-commits mailing list