Skip to content

Commit

Permalink
[flang] simplify derived type info table format
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jeanPerier committed May 20, 2021
1 parent 2d574a1 commit 9438398
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion flang/include/flang/Semantics/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ &&
Expand Down
3 changes: 3 additions & 0 deletions flang/include/flang/Semantics/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion flang/module/__fortran_type_info.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions flang/test/Semantics/typeinfo01.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9438398

Please sign in to comment.