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

    <tr>
        <th>Summary</th>
        <td>
            [C++][Modules] Assertion failure undeduced type in IR-generation
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Given the following valid translation units:

```c++
export module a;

export template<int>
struct a {
        static auto f() {
        }
};
```

```c++
export module b;

import a;

void b() {
        a<0> t;
}
```

```c++
export module c;

import a;

void c() {
        a<0>::f();
}
```

```c++
export module d;

import a;
import b;
import c;

struct d {
        static void g() {
                a<0>::f();
                a<1>::f();
        }
};
```

clang crashes with

```console
/opt/compiler-explorer/clang-assertions-trunk/bin/clang++ --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot   -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -MD -MT CMakeFiles/foo.dir/d.cpp.o -MF CMakeFiles/foo.dir/d.cpp.o.d @CMakeFiles/foo.dir/d.cpp.o.modmap -o CMakeFiles/foo.dir/d.cpp.o -c /app/d.cpp
undeduced type in IR-generation
UNREACHABLE executed at /root/llvm-project/clang/lib/CodeGen/CodeGenFunction.cpp:266!
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-20241217/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -clear-ast-before-backend -main-file-name d.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/app/build -fcoverage-compilation-dir=/app/build -resource-dir /opt/compiler-explorer/clang-assertions-trunk-20241217/lib/clang/20 -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fmodule-file=a=CMakeFiles/foo.dir/a.pcm -fmodule-file=b=CMakeFiles/foo.dir/b.pcm -fmodule-file=c=CMakeFiles/foo.dir/c.pcm -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o CMakeFiles/foo.dir/d.cpp.o -x pcm CMakeFiles/foo.dir/d.pcm
1.      <eof> parser at end of file
2.      /app/d.cpp:8:14: LLVM IR generation of declaration 'd::g'
3.      /app/d.cpp:8:14: Generating code for declaration 'd::g'
 #0 0x0000000003c58b18 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x3c58b18)
 #1 0x0000000003c5651c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007c2ac3c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007c2ac3c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007c2ac3c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007c2ac3c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x0000000003baf6ea (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x3baf6ea)
 #7 0x000000000403386a clang::CodeGen::CodeGenFunction::getEvaluationKind(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x403386a)
 #8 0x00000000041b6ccf clang::CodeGen::isAggregateTypeForABI(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x41b6ccf)
 #9 0x000000000419cd36 (anonymous namespace)::X86_64ABIInfo::getIndirectReturnResult(clang::QualType) const X86.cpp:0:0
#10 0x00000000041a698b (anonymous namespace)::X86_64ABIInfo::computeInfo(clang::CodeGen::CGFunctionInfo&) const X86.cpp:0:0
#11 0x00000000043b42d1 clang::CodeGen::CodeGenTypes::arrangeLLVMFunctionInfo(clang::CanQual<clang::Type>, clang::CodeGen::FnInfoOpts, llvm::ArrayRef<clang::CanQual<clang::Type>>, clang::FunctionType::ExtInfo, llvm::ArrayRef<clang::FunctionType::ExtParameterInfo>, clang::CodeGen::RequiredArgs) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x43b42d1)
#12 0x00000000043b6739 arrangeLLVMFunctionInfo(clang::CodeGen::CodeGenTypes&, bool, llvm::SmallVectorImpl<clang::CanQual<clang::Type>>&, clang::CanQual<clang::FunctionProtoType>) CGCall.cpp:0:0
#13 0x00000000043b6b3f clang::CodeGen::CodeGenTypes::arrangeFreeFunctionType(clang::CanQual<clang::FunctionProtoType>) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x43b6b3f)
#14 0x00000000041008f0 clang::CodeGen::CodeGenTypes::ConvertFunctionTypeInternal(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x41008f0)
#15 0x00000000041010e7 clang::CodeGen::CodeGenTypes::ConvertType(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x41010e7)
#16 0x00000000040af678 clang::CodeGen::CodeGenModule::GetAddrOfFunction(clang::GlobalDecl, llvm::Type*, bool, bool, clang::CodeGen::ForDefinition_t) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x40af678)
#17 0x000000000443aa3e clang::CodeGen::CodeGenModule::getRawFunctionPointer(clang::GlobalDecl, llvm::Type*) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x443aa3e)
#18 0x0000000004446d74 EmitDirectCallee(clang::CodeGen::CodeGenFunction&, clang::GlobalDecl) CGExpr.cpp:0:0
#19 0x0000000004462959 clang::CodeGen::CodeGenFunction::EmitCallee(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x4462959)
#20 0x0000000004462907 clang::CodeGen::CodeGenFunction::EmitCallee(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x4462907)
#21 0x0000000004464133 clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x4464133)
#22 0x00000000044bbae4 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
#23 0x00000000044b016b clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#24 0x00000000044b5dac clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x44b5dac)
#25 0x000000000443e7fe clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x443e7fe)
#26 0x00000000044626d5 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x44626d5)
#27 0x0000000003fc4275 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x3fc4275)
#28 0x0000000003fcbee4 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x3fcbee4)
#29 0x0000000004034eb4 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x4034eb4)
#30 0x0000000004047bf8 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x4047bf8)
#31 0x00000000040af96a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x40af96a)
#32 0x00000000040aac05 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x40aac05)
#33 0x00000000040aafdb clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x40aafdb)
#34 0x00000000040b57a3 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#35 0x00000000045e4b06 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#36 0x00000000045d679c clang::BackendConsumer::HandleInterestingDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x45d679c)
#37 0x0000000004a26b0e clang::ASTReader::PassInterestingDeclsToConsumer() (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x4a26b0e)
#38 0x000000000498a131 non-virtual thunk to clang::ASTReader::StartTranslationUnit(clang::ASTConsumer*) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x498a131)
#39 0x00000000065cd205 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x65cd205)
#40 0x00000000045e2668 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x45e2668)
#41 0x000000000489ba89 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x489ba89)
#42 0x000000000481e48e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x481e48e)
#43 0x00000000049882ce clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0x49882ce)
#44 0x0000000000ce254f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0xce254f)
#45 0x0000000000cd9fea ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#46 0x0000000000cde02e clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0xcde02e)
#47 0x0000000000bacc34 main (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0xbacc34)
#48 0x00007c2ac3c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#49 0x00007c2ac3c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#50 0x0000000000cd9a95 _start (/opt/compiler-explorer/clang-assertions-trunk-20241217/bin/clang-20+0xcd9a95)
clang++: error: unable to execute command: Aborted (core dumped)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
```

See it live: https://godbolt.org/z/vof49fdah
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMW19zozqW_zTkRSUXBozNQx6IHfdNbfdOb5LpmbeUkA5EE5BYSbjT--m3JOFgSBwnPeNbdypT1xbinN_v_NORrCZa80oAXAaLq2CxuSCdeZTqkpEdZ9pIAReFZL8uv_AdCGQeAZWyruVPLiq0IzVnyCgidE0MlwJ1ghsdxHkQur809H80iK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