<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/124979>124979</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang] Extension: to support polymorphic PAD= of intrinsic RESHAPE.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang:frontend,
flang:fir-hlfir
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
DanielCChen
</td>
</tr>
</table>
<pre>
Consider the following code:
```
module m
type Base(k1) ! (4)
integer, kind :: k1
integer(k1) :: i = 88
end type
type, extends(Base) :: Child ! (4)
integer(k1) :: j = 99
end type
end module
program reshape003
use m
type(Child(4)) :: c1(10)
type(Child(4)) :: c2(3,5)
class(Base(4)), allocatable :: b1(:)
c1 = (/ (Child(4)(i,i+100), i=1,10) /)
allocate(Child(4)::b1(2))
c2 = reshape(c1, (/3,5/), b1, (/2,1/))
print *, c1
print *, c2
end
```
Flang supported it unintentionally until PR #124226
While the standard indeed requires the declare type of SOURCE and PAD to be the same, which makes the code above invalid. it is a reasonable extension to allow PAD to have different declare type but the same dynamic type as shown in the above code as the compiler can always do runtime check and pad it accordingly.
Issue #124976 required a compile-time semantic check for the code above to be standard conforming. It should be also reverted when this extension is implemented.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEVUFv4zgP_TXKhWgg00njHHJwkwbfnL6ig8WeZYmONZUlryQnm3-_kGy3neksNggQw6Tee3wkFRGCvliiA9s-se1pJcbYOX84CavJHI8d2VXj1P1wdDZoRR5iR9A6Y9xN2wtIp4iVNeM1e-Tzl9e9U6Mh6BmvAQDifSB4EoEYVm8Fw316ybAAhtWG4T6laRvpQp7hEd60VZBAyxreihkjfd5z3lHmLA2sPEFVzblkVeZMqng9PeIR6O9IVgWG1aRlvxw_dtqo32j6F9r51I9Mut9_JU2PkwWTgsG7ixc9eAqdGIjzkvF6DD8bxLDKOhb-DyJZMKwKPov6j1xk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