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

    <tr>
        <th>Summary</th>
        <td>
            [clang] CodeGen AggExprEmitter crash with clang modules and C++98
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:modules,
            clang:codegen,
            crash-on-valid
      </td>
    </tr>

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

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

<pre>
    repro: https://gcc.godbolt.org/z/sb8994Pjf
```C++
#pragma clang module build A
module A {}
#pragma clang module contents
#pragma clang module begin A

template<typename T> struct D : T {};

#pragma clang module end
#pragma clang module endbuild

#pragma clang module import A

struct Y {
  int value;
};

template<class T> void f() {
 (void)T().value;
}

template void f<D<Y> >();
```

Backtrace:
```
cannot perform hierarchy conversion in EmitAggExpr: should have been unpacked before we got here
UNREACHABLE executed at /root/llvm-project/llvm/tools/clang/lib/CodeGen/CGExprAgg.cpp:893!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++98 -fmodules <source>
1.      <source>:21:25: current parser token ';'
2.      <source>:17:24: instantiating function definition 'f<D<Y> >'
3.      <source>:17:24: LLVM IR generation of declaration 'f'
4.      <source>:17:24: Generating code for declaration 'f'
 #0 0x0000000003fbf178 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3fbf178)
 #1 0x0000000003fbce04 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3fbce04)
 #2 0x0000000003f01a38 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x0000781fb3e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x0000781fb3e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x0000781fb3e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x0000781fb3e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x0000000003f0d17a (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f0d17a)
 #8 0x0000000004345278 (anonymous namespace)::AggExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprAgg.cpp:0:0
 #9 0x000000000433fab1 (anonymous namespace)::AggExprEmitter::Visit(clang::Expr*) CGExprAgg.cpp:0:0
#10 0x00000000043407de clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43407de)
#11 0x0000000004302871 clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4302871)
#12 0x000000000432a13d clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x432a13d)
#13 0x000000000439b0d4 (anonymous namespace)::ScalarExprEmitter::VisitMemberExpr(clang::MemberExpr*) CGExprScalar.cpp:0:0
#14 0x000000000439293a clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#15 0x0000000004397edc clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4397edc)
#16 0x00000000043026ce clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43026ce)
#17 0x000000000432a13d clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x432a13d)
#18 0x000000000439beef (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
#19 0x0000000004391fd8 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#20 0x0000000004397edc clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4397edc)
#21 0x00000000043026ce clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43026ce)
#22 0x000000000432a13d clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x432a13d)
#23 0x00000000044a0bce clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44a0bce)
#24 0x00000000044a8b9c clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44a8b9c)
#25 0x000000000450ed16 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x450ed16)
#26 0x000000000452221b clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x452221b)
#27 0x000000000458c4cd clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x458c4cd)
#28 0x0000000004587684 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4587684)
#29 0x0000000004587a9b clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4587a9b)
#30 0x00000000045926c3 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#31 0x0000000004977c66 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#32 0x0000000004967744 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4967744)
#33 0x00000000072c202f clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x72c202f)
#34 0x00000000070cf581 clang::Sema::ActOnExplicitInstantiation(clang::Scope*, clang::SourceLocation, clang::SourceLocation, clang::Declarator&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x70cf581)
#35 0x000000000669ab3d clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x669ab3d)
#36 0x00000000066aa829 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66aa829)
#37 0x00000000067885a8 clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x67885a8)
#38 0x00000000067890f6 clang::Parser::ParseExplicitInstantiation(clang::DeclaratorContext, clang::SourceLocation, clang::SourceLocation, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x67890f6)
#39 0x0000000006796568 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6796568)
#40 0x00000000066b3b60 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66b3b60)
#41 0x000000000667056c clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x667056c)
#42 0x000000000667145d clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x667145d)
#43 0x000000000666382a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x666382a)
#44 0x0000000004973df8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4973df8)
#45 0x0000000004c6c5e5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c6c5e5)
#46 0x0000000004beaa2e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4beaa2e)
#47 0x0000000004d5ec49 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d5ec49)
#48 0x0000000000db329f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdb329f)
#49 0x0000000000da9eba ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#50 0x00000000049db229 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#51 0x0000000003f01ed4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f01ed4)
#52 0x00000000049db83f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#53 0x000000000499d60d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x499d60d)
#54 0x000000000499e69e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x499e69e)
#55 0x00000000049a6985 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49a6985)
#56 0x0000000000daf7af clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdaf7af)
#57 0x0000000000c34b94 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc34b94)
#58 0x0000781fb3e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#59 0x0000781fb3e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#60 0x0000000000da9965 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda9965)
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkW11z46i2_TXKC-WUhL4f8qA4SU-mem53dXL71jylECBZEwl0AaWT-fWnADkyiu3EOXGfMx-VmZFBbNZabDZbCCEpm5pReubF5158cYIGteLirGv-fKD3_OGk5OTpTNBecC8swEqpXnph4cErD17VGJ_WnJS8Vadc1B68-tODV7LM8jz6-kfl-YWX-PZv6cFz_ecXHgx7geoOAdwiVoOOk6GloByaloDC84uxoABeeu6lF7ubYM4UZUruMUrrhhmjnl8o2vUtUtQLl-qppwx1FNx64SWQSgxYgQugGd6uuw3PbbMdpikjeysNn70Wmq7nQq3RjSB-N937BQANU-ABtQMdkWxA2mCCWySlpfHAGwIqD2YezNdWPJjpYg_mt7bidGbSsbc2ES4vvHD5uzbqhZe24dhkPZ624TnC90ogTLVLuLUYMcYV6KmouOjAqqECCbx60qP2QIVsOAMNA5ddo4q6vnzshVZfrvjQErBCD3rwKAMD6xG-pwSUtOKCgh8U1FyBFRXU84v__Z9vl8Xyl-L88yWgjxQPihKAFPDgleBcefCqbR-6RS_4HxSvf3rwSnHeSg9emfHQxU3pwaslJ_QTZfrqkwZU1PUp7nsvLLI89GDg-cXXz5fFzSWQQ9k1CiBQDjUQ1Iyj4vPZ0ajVUJ5i3k0dz-A0Ug5UAwGIEdAw3A6EArWiAAskV6B81hcuQW9mIaZSUgIkH4Qt1i2RlBw3SLMXAwMSi6ZXp55f3CiE7wEZut6OkH_q-flXwWuBOoBEPXRmAoXa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