[flang-dev] Intrinsic function with an optional TEAM_TYPE dummy argument

Rasmussen, Craig E. via flang-dev flang-dev at lists.llvm.org
Mon May 3 13:39:00 PDT 2021


I'm trying to implement team_number(team) in lib/Evaluate/intrinsics.cpp and I'm running into a problem.  The issue is how to handle team_type from the intrinsic module iso_fortran_env.  I'll outline the steps I've taken so far and then describe the problem I'm having.

I’ve:
  1. Changed the CategorySet in TypePattern TEAM_TYPE from IntType to DerivedType. I'm pretty sure this is the correct thing to do.
  2. Added team_number to the IntrinsicInterface list with an optional TEAM_TYPE. Again, no problem here.
  3. Implemented checking types and kinds of the actual argument against the team_number's interface. This is pretty straight forward:
         case KindCode::teamType:
           argOk = semantics::IsTeamType(GetDerivedTypeSpec(type));

The problem occurs when the code tries to check the dummy argument (team) for the case in which the optional actual argument is missing. The normal control flow path that this would take would be to move a characteristics::DummyDataObject (constructed with characteristics::TypeAndShape) onto the dummyArgs list. However, the TypeAndShape constructor calls GetDefaultKind() with a TEAM_TYPE category argument (which is TypeCategory::DerivedType).

Therein lies the problem. The function IntrinsicTypeDefaultKinds::GetDefaultKind(TypeCategory::DerivedType) fails with a hard error because a derived type is not an intrinsic type. At first I was thoroughly confused by the whole type kind thing for a derived type, specifically one from an intrinsic module. Then as a last (of course) resort, I checked the standard more carefully and found Note 16.34 which states that types in intrinsic modules are not themselves intrinsic. Thus IntrinsicTypeDefaultKinds::GetDefaultKind(TypeCategory::DerivedType) should fail.

So the conclusion is that I need help fixing this (for function team_type() and several other intrinsic functions with a dummy argument of TEAM_TYPE). The code could look something like the following (at roughly line 1670 in intrinsics.cpp):

      } else if (d.typePattern.kindCode == KindCode::teamType) {
        characteristics::TypeAndShape typeAndShape{DynamicType{TypeCategory::Derived}};
        dummyArgs.emplace_back(std::string{d.keyword},
            characteristics::DummyDataObject{std::move(typeAndShape)});
      }

However, there is no constructor for TypeAndShape with a single argument of type TypeCategory::Derived. After staring at many lines of code in flang I'm left wondering if there shouldn't be?

Thanks,
Craig

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/flang-dev/attachments/20210503/739fd684/attachment.html>


More information about the flang-dev mailing list