@@ -306,6 +306,10 @@ static bool isArrayLike(mlir::Type type) {
306306}
307307
308308static bool isCompositeLike (mlir::Type type) {
309+ // class(*) is not a composite type since it does not have a determined type.
310+ if (fir::isUnlimitedPolymorphicType (type))
311+ return false ;
312+
309313 return mlir::isa<fir::RecordType, fir::ClassType, mlir::TupleType>(type);
310314}
311315
@@ -320,8 +324,18 @@ template <>
320324mlir::acc::VariableTypeCategory
321325OpenACCMappableModel<fir::BaseBoxType>::getTypeCategory(mlir::Type type,
322326 mlir::Value var) const {
327+ // Class-type does not behave like a normal box because it does not hold an
328+ // element type. Thus special handle it here.
329+ if (mlir::isa<fir::ClassType>(type)) {
330+ // class(*) is not a composite type since it does not have a determined
331+ // type.
332+ if (fir::isUnlimitedPolymorphicType (type))
333+ return mlir::acc::VariableTypeCategory::uncategorized;
334+ return mlir::acc::VariableTypeCategory::composite;
335+ }
323336
324337 mlir::Type eleTy = fir::dyn_cast_ptrOrBoxEleTy (type);
338+ assert (eleTy && " expect to be able to unwrap the element type" );
325339
326340 // If the type enclosed by the box is a mappable type, then have it
327341 // provide the type category.
@@ -346,7 +360,7 @@ OpenACCMappableModel<fir::BaseBoxType>::getTypeCategory(mlir::Type type,
346360 return mlir::acc::VariableTypeCategory::nonscalar;
347361}
348362
349- static mlir::TypedValue<mlir::acc::PointerLikeType>
363+ static mlir::Value
350364getBaseRef (mlir::TypedValue<mlir::acc::PointerLikeType> varPtr) {
351365 // If there is no defining op - the unwrapped reference is the base one.
352366 mlir::Operation *op = varPtr.getDefiningOp ();
@@ -372,7 +386,7 @@ getBaseRef(mlir::TypedValue<mlir::acc::PointerLikeType> varPtr) {
372386 })
373387 .Default ([&](mlir::Operation *) { return varPtr; });
374388
375- return mlir::cast<mlir::TypedValue<mlir::acc::PointerLikeType>>( baseRef) ;
389+ return baseRef;
376390}
377391
378392static mlir::acc::VariableTypeCategory
@@ -384,10 +398,17 @@ categorizePointee(mlir::Type pointer,
384398 // value would both be represented as !fir.ref<f32>. We do not want to treat
385399 // such a reference as a scalar. Thus unwrap interior pointer calculations.
386400 auto baseRef = getBaseRef (varPtr);
387- mlir::Type eleTy = baseRef.getType ().getElementType ();
388401
389- if (auto mappableTy = mlir::dyn_cast<mlir::acc::MappableType>(eleTy))
390- return mappableTy.getTypeCategory (varPtr);
402+ if (auto mappableTy =
403+ mlir::dyn_cast<mlir::acc::MappableType>(baseRef.getType ()))
404+ return mappableTy.getTypeCategory (baseRef);
405+
406+ // It must be a pointer-like type since it is not a MappableType.
407+ auto ptrLikeTy = mlir::cast<mlir::acc::PointerLikeType>(baseRef.getType ());
408+ mlir::Type eleTy = ptrLikeTy.getElementType ();
409+
410+ if (auto mappableEleTy = mlir::dyn_cast<mlir::acc::MappableType>(eleTy))
411+ return mappableEleTy.getTypeCategory (varPtr);
391412
392413 if (isScalarLike (eleTy))
393414 return mlir::acc::VariableTypeCategory::scalar;
@@ -397,8 +418,12 @@ categorizePointee(mlir::Type pointer,
397418 return mlir::acc::VariableTypeCategory::composite;
398419 if (mlir::isa<fir::CharacterType, mlir::FunctionType>(eleTy))
399420 return mlir::acc::VariableTypeCategory::nonscalar;
421+ // Assumed-type (type(*))does not have a determined type that can be
422+ // categorized.
423+ if (mlir::isa<mlir::NoneType>(eleTy))
424+ return mlir::acc::VariableTypeCategory::uncategorized;
400425 // "pointers" - in the sense of raw address point-of-view, are considered
401- // scalars. However
426+ // scalars.
402427 if (mlir::isa<fir::LLVMPointerType>(eleTy))
403428 return mlir::acc::VariableTypeCategory::scalar;
404429
0 commit comments