This patch expands the runtime check in move_alloc to allow the
destination to be unlimited polymorphic.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
flang/runtime/allocatable.cpp | ||
---|---|---|
49 | If allocated the type of the unlimited polymorphic descriptor will not be CFI_type_other. |
flang/runtime/allocatable.cpp | ||
---|---|---|
49 | Oh, is it then set to the concrete type? |
flang/runtime/allocatable.cpp | ||
---|---|---|
49 | There is no way to directly check if a descriptor is for a polymorphic/unlimited polymorphic entity. We could either pass a boolean value in the lowering or just perform the check inline when it is needed before calling the runtime. So in both case the current check should not be preserved in this form. |
I think we just want to get rid of this. Is there an additional check that needs doing somewhere in Semantic analysis or anything? I couldn't find a case that shouldn't be allowed that is when I tried.
It seems to me it's ok to just remove the runtime checks, as you did.
Semantic analysis already checks if both arguments are allocatable and type compatible, except for polymorphic types.
For these, I currently get a not yet implemented error.
But given the spec of move_alloc (16.9.137), it's possible to verify all cases in compile time (as gfortran does). These should be the possible cases involving (unlimited) polymorphic types:
- from isn't polymorphic but to is: invalid, unless to is unlimited polymorphic.
- from is polymorphic but to isn't: invalid, not type compatible.
- from and to are polymorphic: from must have the same declared type of to or any of its extensions (7.3.2.3).
- from is unlimited polymorphic but to isn't: invalid.
- to is unlimited polymorphic: from may have any declared type.
None of the cases above depend on runtime type information.
This is not invalid if from as a compatible type with to. monomorphic derived-type to a polymorphic with the same declared type.
- from is polymorphic but to isn't: invalid, not type compatible.
- from and to are polymorphic: from must have the same declared type of to or any of its extensions (7.3.2.3).
- from is unlimited polymorphic but to isn't: invalid.
- to is unlimited polymorphic: from may have any declared type.
None of the cases above depend on runtime type information.
It really makes sense to allow from to be a monomorphic derived-type and to a polymorphic with the same declared (base) type. gfortran allows this.
However, the F2018 standard (16.9.137 MOVE_ALLOC) states this about the TO argument:
It shall be polymorphic if FROM is polymorphic.
Then I guess it doesn't imply that TO shall not be polymorphic if FROM isn't.
If allocated the type of the unlimited polymorphic descriptor will not be CFI_type_other.