<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/83451>83451</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [flang] Bad descriptor created for polymorphic dummy argument with sequence remapping
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            bug,
            flang:fir-hlfir
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            jeanPerier
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          jeanPerier
      </td>
    </tr>
</table>

<pre>
    https://github.com/llvm/llvm-test-suite/blob/main/Fortran/gfortran/regression/select_type_48.f90 is failing with flang.

Root cause is that descriptor created for polymorphic dummy argument with explicit shape is created according to the actual argument shape instead of the dummy argument shape. Because of sequence association rules (F2018 15.5.2.11), these shapes do not have to match when the dummy has explicit shape. Even the rank may differ.

Lowering should prepare the descriptor according to the dummy argument specifications in that case (the alternative to "fix" the descriptor inside the callee, would be cumbersome because the rank of the incoming descriptor could not be trust, which would make retrieval of the type descriptor more complex (like for assumed-rank). Also, in the BIND(C) case, the shape has to be the one of the dummy.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVMuOrEYM_ZrqjTUI3I-BRS_mEaRIURTlB65MYcB3CoqUi5npv48Kep7ZRHfTTTf28TnHD1KVfmI-m-O9QfzJNP3FQTgYRHN83NESBx_OH__vGt9ezkOMs5r9ncHaYN1LHJYms340WDv3_PZ1E1njjS4S2WDdON8YrEeSyWBd-xADpae-e38M3AdWFZ9-KDu28Ue8zPzjUGZdlYModCROph5eJA7QOZr6zOSPJr_bPv_2PoKlRTkFx4EitKw2yBx9ABuYIrfQ-QCzd5fRh3kQC-0yjheg0C8jT3HD5tfZiZUIOtC8or1lk7U-tIlE9BAHBrJxIfeRf82YNDK14Ls16FuNNSaDe97I-g6U_1l4sgyk6q1QFD9BWBwrGCxrzIsSimN2zDArCoOVwYcErLxhKbQeJh9hoGdOzEaKdoCXgadP9QfSb8oy-O35GhJoeoKRLtBK13H4Yuwf_oVD0qyDX1wLc-CZAm_QHw7_x5vvsme20old1SnItPXIknJSubrpIoeJomwyDGInrwbxeymZVNqNgCXnmJMhLyu5hsEuY8NB_cjQXD1-l3jtiEzWj4nq5wlZ85ONDUMMi8YVdZBk5fpupCeGwDEIP5N7w0pT-hln9IHB-nF2_JqEOXnidexIdRm5vUlEDFYZ3Dn1qYZsPbj__c9Hg-WDwWp15drl60yl9kW_chsY_MRfpivbted9W-0r2vG5uM0rxPJY4G44d3TE06ltqpa67rY7IpdlccASy6rcl6f9Ts6Y4yFHrIrbQ3EosxPTCS2f2rxomltL5pDzSOKytNiZD_1OVBc-l_vDsdg5atjp9Yg0S5-uBz6k1qUNNfu7TsLN4Dp5uyvhvB6IZunVHHInGvUDOUp060Xaso-PcE_tr-7x-1oFHmmeZep3S3D_94LNwf9kGw3Wq1w1WK-K_w0AAP__SEXMtA">