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

    <tr>
        <th>Summary</th>
        <td>
            Crash clang when dealing with VMT at the file scope
        </td>
    </tr>

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

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

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

<pre>
    Following C code causes clang to crash:

```
int foo(void);
__auto_type x = 0 ? 0 : (int(*)[foo()])0;

int main(void) {
    return sizeof *x;
}
```

The error report:
```
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-trunk-20220929/bin/clang-16 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name example.c -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 -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-trunk-20220929/lib/clang/16.0.0 -internal-isystem /opt/compiler-explorer/clang-trunk-20220929/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-9.2.0/lib/gcc/x86_64-linux-gnu/9.2.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/app -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/example-57dcc2.o -x c <source>
1.      <eof> parser at end of file
2.      <source>:4:5: LLVM IR generation of declaration 'main'
3.      <source>:4:5: Generating code for declaration 'main'
 #0 0x0000563ad36326e4 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x0000563ad362ff84 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f5d53ffe420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x0000563ad1e1e6d7 llvm::IRBuilderBase::CreateMul(llvm::Value*, llvm::Value*, llvm::Twine const&, bool, bool) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x22696d7)
 #4 0x0000563ad3e4bc69 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
 #5 0x0000563ad3e5095b (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
 #6 0x0000563ad3e4ab1f (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
 #7 0x0000563ad3e4bdf7 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x4296df7)
 #8 0x0000563ad3a7b304 clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3ec6304)
 #9 0x0000563ad3a7d235 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3ec8235)
#10 0x0000563ad3a8326a clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3ece26a)
#11 0x0000563ad3ae0a3d clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3f2ba3d)
#12 0x0000563ad3aebf86 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3f36f86)
#13 0x0000563ad3b42477 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3f8d477)
#14 0x0000563ad3b3ec25 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3f89c25)
#15 0x0000563ad3b3f113 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3f8a113)
#16 0x0000563ad3b46b18 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#17 0x0000563ad48a8981 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#18 0x0000563ad489c06d clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x4ce706d)
#19 0x0000563ad5a3d094 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x5e88094)
#20 0x0000563ad48a64e5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x4cf14e5)
#21 0x0000563ad41ad181 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x45f8181)
#22 0x0000563ad4132dd3 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x457ddd3)
#23 0x0000563ad42905ab clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x46db5ab)
#24 0x0000563ad0e4de54 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x1298e54)
#25 0x0000563ad0e4740b ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#26 0x0000563ad0e499f0 clang_main(int, char**) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x12949f0)
#27 0x00007f5d53aac083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#28 0x0000563ad0e4701e _start (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x129201e)
clang-16: error: unable to execute command: Segmentation fault (core dumped)
clang-16: error: clang frontend command failed due to signal (use -v to see invocation)
ASM generation compiler returned: 254
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-trunk-20220929/bin/clang-16 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name example.c -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 -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-trunk-20220929/lib/clang/16.0.0 -internal-isystem /opt/compiler-explorer/clang-trunk-20220929/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-9.2.0/lib/gcc/x86_64-linux-gnu/9.2.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/app -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/example-886ec3.o -x c <source>
1.      <eof> parser at end of file
2.      <source>:4:5: LLVM IR generation of declaration 'main'
3.      <source>:4:5: Generating code for declaration 'main'
 #0 0x000055d9180846e4 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x000055d918081f84 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fbcc6177420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x000055d9168706d7 llvm::IRBuilderBase::CreateMul(llvm::Value*, llvm::Value*, llvm::Twine const&, bool, bool) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x22696d7)
 #4 0x000055d91889dc69 (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
 #5 0x000055d9188a295b (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
 #6 0x000055d91889cb1f (anonymous namespace)::ScalarExprEmitter::Visit(clang::Expr*) CGExprScalar.cpp:0:0
 #7 0x000055d91889ddf7 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x4296df7)
 #8 0x000055d9184cd304 clang::CodeGen::CodeGenFunction::EmitReturnStmt(clang::ReturnStmt const&) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3ec6304)
 #9 0x000055d9184cf235 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3ec8235)
#10 0x000055d9184d526a clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3ece26a)
#11 0x000055d918532a3d clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3f2ba3d)
#12 0x000055d91853df86 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3f36f86)
#13 0x000055d918594477 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3f8d477)
#14 0x000055d918590c25 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3f89c25)
#15 0x000055d918591113 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x3f8a113)
#16 0x000055d918598b18 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#17 0x000055d9192fa981 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#18 0x000055d9192ee06d clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x4ce706d)
#19 0x000055d91a48f094 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x5e88094)
#20 0x000055d9192f84e5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x4cf14e5)
#21 0x000055d918bff181 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x45f8181)
#22 0x000055d918b84dd3 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x457ddd3)
#23 0x000055d918ce25ab clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x46db5ab)
#24 0x000055d91589fe54 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x1298e54)
#25 0x000055d91589940b ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#26 0x000055d91589b9f0 clang_main(int, char**) (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x12949f0)
#27 0x00007fbcc5c25083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#28 0x000055d91589901e _start (/opt/compiler-explorer/clang-trunk-20220929/bin/clang-16+0x129201e)
clang-16: error: unable to execute command: Segmentation fault (core dumped)
clang-16: error: clang frontend command failed due to signal (use -v to see invocation)
Execution build compiler returned: 254
```

Godbold: https://godbolt.org/z/WM9WWe1MY
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJztW1tv2zgT_TXOCyFD98tDHhw7yQZogKIJWnxPBkVSjrayKOiSuvvr95CUY8txkqZ1vk3aBLVsjajhOcPhDMlBU8m_H5_JopDf8nJBpoRJLgijXSMawgoKWSsJq2lzM_ImI3s2stfX0O7_6du8bEkm5ciNb2XOR24y8k7Mk_mcdq2ct98rQVZk5M2IjeuZvk4IXsCruI7ciXorODFa9O8Zrvadok1HS5qXm57IKOpbEPzVou3qkjT5P0JmUD9ZbRREs73YzfX6RhBR17KGikrW7YbvsPVVS9lXwrtlddfCHo_s5GMtFzVdElovuqUo28bQO5MV6J0xuazyQtSWWFWFrEWtZMq-Vlt35VfLtV3XTkDaPUsVuf6hExKLMYegVV4VMGAczkPfwhul_FZaRV52K2tRdsQSy7y1ZPo3sZa1KOjKokVBrPUNrpLRNpdlQyyeNzQthJXVQkB9IWht0aa1UpEBmZWCnyj5pl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