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

    <tr>
        <th>Summary</th>
        <td>
            [Flang] fatal internal error: CHECK(!type.IsPolymorphic()) failed at /root/llvm-project/flang/lib/Evaluate/initial-image.cpp(83)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          k-arrows
      </td>
    </tr>
</table>

<pre>
    Reproducible on Godbolt:
https://godbolt.org/z/63e3dqPM4

Reproducer (reduced from https://github.com/rzurob/llvm-test-suite/blob/ibm_fortran_tests/Fortran/IBM/execute/F2003/OO_poly/intrinsics/transfer/associate003.f03)
```console
$ cat associate003_reduced.f03
module m
    type, abstract :: AbstractParent
    end type

    type, extends(AbstractParent) :: Base
        integer i
    end type

    type, extends(Base) :: Child
        integer j
    end type
end module

program associate003_reduced
use m
    class(AbstractParent), pointer :: ap1(:) => null()

    allocate(ap1(20), SOURCE=(/ (Base(i),i=1,20) /))

 associate(name1=>ap1(15))
        select type (name2=>transfer(Child(8,9), name1))
            type is (Base)
 print *, name2
            class default
                error stop 3_4
        end select
    end associate
end
```

Stack dump:
```console
fatal internal error: CHECK(!type.IsPolymorphic()) failed at /root/llvm-project/flang/lib/Evaluate/initial-image.cpp(83)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new -fc1 -triple x86_64-unknown-linux-gnu -S -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -mllvm -x86-asm-syntax=intel -resource-dir /opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/.. -mframe-pointer=all -o /app/output.s -x f95-cpp-input /app/example.f90
 #0 0x000000000386eb98 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x386eb98)
 #1 0x000000000386c50c SignalHandler(int) Signals.cpp:0:0
 #2 0x000072e7ace42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x000072e7ace969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x000072e7ace42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x000072e7ace287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x0000000004e0c829 (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x4e0c829)
 #7 0x000000000491778a Fortran::evaluate::InitialImage::AsConstant(Fortran::evaluate::FoldingContext&, Fortran::evaluate::DynamicType const&, std::optional<long>, std::vector<long, std::allocator<long>> const&, bool, long) const (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x491778a)
 #8 0x000000000454f8a1 Fortran::evaluate::FoldTransfer(Fortran::evaluate::FoldingContext&, std::vector<std::optional<Fortran::evaluate::ActualArgument>, std::allocator<std::optional<Fortran::evaluate::ActualArgument>>> const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x454f8a1)
 #9 0x000000000454f9f6 Fortran::evaluate::Folder<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>::TRANSFER(Fortran::evaluate::FunctionRef<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x454f9f6)
#10 0x000000000454feb3 Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>> Fortran::evaluate::FoldOperation<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>(Fortran::evaluate::FoldingContext&, Fortran::evaluate::FunctionRef<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x454feb3)
#11 0x000000000454fff5 Fortran::evaluate::ExpressionBase<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>::Rewrite(Fortran::evaluate::FoldingContext&, Fortran::evaluate::Expr<Fortran::evaluate::SomeKind<(Fortran::common::TypeCategory)5>>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x454fff5)
#12 0x0000000004551f27 Fortran::evaluate::ExpressionBase<Fortran::evaluate::SomeType>::Rewrite(Fortran::evaluate::FoldingContext&, Fortran::evaluate::Expr<Fortran::evaluate::SomeType>&&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x4551f27)
#13 0x0000000004131bf2 Fortran::evaluate::ExpressionAnalyzer::Analyze(Fortran::parser::Selector const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x4131bf2)
#14 0x00000000041850cd Fortran::semantics::ConstructVisitor::ResolveSelector(Fortran::parser::Selector const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x41850cd)
#15 0x00000000041c2016 std::enable_if<UnionTrait<Fortran::parser::Selector>, void>::type Fortran::parser::Walk<Fortran::parser::Selector, Fortran::semantics::ResolveNamesVisitor>(Fortran::parser::Selector const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x41c2016)
#16 0x00000000041e4bf2 std::enable_if<TupleTrait<Fortran::parser::SelectTypeConstruct>, void>::type Fortran::parser::Walk<Fortran::parser::SelectTypeConstruct, Fortran::semantics::ResolveNamesVisitor>(Fortran::parser::SelectTypeConstruct const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x41e4bf2)
#17 0x00000000041e356c void Fortran::parser::Walk<Fortran::semantics::ResolveNamesVisitor>(std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>> const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x41e356c)
#18 0x00000000041e38d9 void Fortran::parser::ForEachInTuple<0ul, void Fortran::parser::Walk<Fortran::semantics::ResolveNamesVisitor, Fortran::parser::Statement<Fortran::parser::AssociateStmt>, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::Statement<Fortran::parser::EndAssociateStmt>>(std::tuple<Fortran::parser::Statement<Fortran::parser::AssociateStmt>, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::Statement<Fortran::parser::EndAssociateStmt>> const&, Fortran::semantics::ResolveNamesVisitor&)::'lambda'(Fortran::semantics::ResolveNamesVisitor const&), std::tuple<Fortran::parser::Statement<Fortran::parser::AssociateStmt>, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::Statement<Fortran::parser::EndAssociateStmt>>>(std::tuple<Fortran::parser::Statement<Fortran::parser::AssociateStmt>, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::Statement<Fortran::parser::EndAssociateStmt>> const&, void Fortran::parser::Walk<Fortran::semantics::ResolveNamesVisitor, Fortran::parser::Statement<Fortran::parser::AssociateStmt>, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::Statement<Fortran::parser::EndAssociateStmt>>(std::tuple<Fortran::parser::Statement<Fortran::parser::AssociateStmt>, std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>>, Fortran::parser::Statement<Fortran::parser::EndAssociateStmt>> const&, Fortran::semantics::ResolveNamesVisitor&)::'lambda'(Fortran::semantics::ResolveNamesVisitor const&)) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x41e38d9)
#19 0x00000000041e3474 void Fortran::parser::Walk<Fortran::semantics::ResolveNamesVisitor>(std::__cxx11::list<Fortran::parser::ExecutionPartConstruct, std::allocator<Fortran::parser::ExecutionPartConstruct>> const&, Fortran::semantics::ResolveNamesVisitor&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x41e3474)
#20 0x00000000041e6832 Fortran::semantics::ResolveNamesVisitor::ResolveExecutionParts(Fortran::semantics::ProgramTree const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x41e6832)
#21 0x00000000041ea056 Fortran::semantics::ResolveNamesVisitor::Pre(Fortran::parser::ProgramUnit const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x41ea056)
#22 0x00000000041eb644 Fortran::semantics::ResolveNames(Fortran::semantics::SemanticsContext&, Fortran::parser::Program const&, Fortran::semantics::Scope&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x41eb644)
#23 0x0000000004243bc1 Fortran::semantics::Semantics::Perform() (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x4243bc1)
#24 0x00000000038c0555 Fortran::frontend::FrontendAction::runSemanticChecks() (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x38c0555)
#25 0x0000000003bed812 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x3bed812)
#26 0x00000000038bf965 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x38bf965)
#27 0x00000000038af217 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x38af217)
#28 0x00000000038c59ad Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x38c59ad)
#29 0x0000000002017a18 fc1_main(llvm::ArrayRef<char const*>, char const*) (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x2017a18)
#30 0x0000000001f05c44 main (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x1f05c44)
#31 0x000072e7ace29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#32 0x000072e7ace29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#33 0x000000000201697e _start (/opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin/flang-new+0x201697e)
flang-new: error: unable to execute command: Aborted (core dumped)
flang-new: error: flang frontend command failed due to signal (use -v to see invocation)
flang-new version 19.0.0git (https://github.com/llvm/llvm-project.git c5cd049566a795ba5de88dfbb2eb563cad4a9d8a)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-llvmflang-trunk-20240515/bin
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsW11zozjW_jXkRoULxIfhIhdux8yk5p3pVCfz7qVLCOFoIiRWEmlnfv2WBNgWSTvxdNyV2u1UfwSkc3Se5zlHElhGStENJ-TSSz55ydUF6vS9kJcPPpJSfFUXpaieLr-QVoqqw7RkBAgOfhFVKZj2ooUXXHnB4l7rVpkrWHiw2PStMyE3Hiz-9mCRRiSq_n3ze9x37_8dnRIJPJhJYn6tQC1FAyb-qL7vyhkWjQcL-XcnRenBgrHHxtdEaV91VBMPFiWzDbRs1rWQWiK-Nu3Kg0XRX3uwuP70uwcLsiW4s0YFDILIg8Xnz-tWsCdjz7WkXFFsDI2Vqon0YIGUEpgiTYIgmtXGKB_gpEH_BwuuBCPDXRgDjDQ4NFsPKK257dWIqmMENP0VAAD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