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

    <tr>
        <th>Summary</th>
        <td>
            Clang codegen ICE: `Emitted constant has unexpected size` with large static array size and small initializer
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          langston-barrett
      </td>
    </tr>
</table>

<pre>
    ```c
// https://godbolt.org/z/cqxxvhhYq
char buffer[1196209283887] = "%";
```
```
clang++: /root/llvm-project/clang/lib/CodeGen/CodeGenModule.cpp:4936: void clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(const clang::VarDecl*, bool): Assertion `VarSize == CstSize && "Emitted constant has unexpected size"' failed.
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 -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -c -O0 -emit-llvm -Xclang -disable-llvm-passes <source>
1.      <eof> parser at end of file
2.      <source>:1:6: LLVM IR generation of declaration 'buffer'
3.      <source>:1:6: Generating code for declaration 'buffer'
 #0 0x0000557c6b9e307f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x401107f)
 #1 0x0000557c6b9e0dbc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x400edbc)
 #2 0x0000557c6b92e428 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007f088f1b5420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007f088ec8200b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #5 0x00007f088ec61859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #6 0x00007f088ec61729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #7 0x00007f088ec72fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x0000557c6bdb6eb6 clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43e4eb6)
 #9 0x0000557c6bdd98a1 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44078a1)
#10 0x0000557c6bdda508 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4408508)
#11 0x0000557c6bde3354 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#12 0x0000557c6cc0de49 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#13 0x0000557c6cbffc70 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x522dc70)
#14 0x0000557c6e0c7fa4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66f5fa4)
#15 0x0000557c6cc0ac48 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5238c48)
#16 0x0000557c6c46fcb9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a9dcb9)
#17 0x0000557c6c3f41e6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4a221e6)
#18 0x0000557c6c553e77 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b81e77)
#19 0x0000557c68f6a4c6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x15984c6)
#20 0x0000557c68f662ea ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#21 0x0000557c6c254cdd 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
#22 0x0000557c6b92e910 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f5c910)
#23 0x0000557c6c25559f 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
#24 0x0000557c6c21cddc clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x484addc)
#25 0x0000557c6c21d87d 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+++0x484b87d)
#26 0x0000557c6c22552d clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x485352d)
#27 0x0000557c68f68970 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x1596970)
#28 0x0000557c68e744d5 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x14a24d5)
#29 0x00007f088ec63083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#30 0x0000557c68f60ffe _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x158effe)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```

This is possibly a duplicate of #39290, though this program doesn't use an initializer list. Here's how I searched for duplicates: https://github.com/llvm/llvm-project/issues?q=is%3Aopen+is%3Aissue+label%3Aclang%3Acodegen+constant+has+unexpected+size
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWV9v27jy_TTMCyGDIvX3IQ-Ok3S76GKLpih-vyeDIkc2b2VRS1Kp009_QUpOTNfpZotkXy7QBhZFDs85HM4MRW6t2vQAlyi_Qvn1BR_dVpvLjvcb63SfNNwYcO6i0fLhEhVk-icQuUZkiegtord469xgEZsfN1o2unMLbTaI3n5H9Fb8td_fb7f__9c0Smy5wc3YtmBQfpWmdUFJTStWVSXKrzFi1xhRimju_7KrearD1GcfhceL6JX_x5YY0VujtUP0tuvud8lg9H9A-Me5322nGkRvV1rCO-iffv2h5djBQgwDYsusZoU3dq-VxNNAtkRseRh1_DANnJpudsq963TDuy_cXEOreuWU7hGthO6tOzYVOogO0SWiK9xo3SFa-zmX1oLxozAqyBdu7tR38MJ4bVbWTY-0QLTwUvkZHUgc7PPe4S23eOxhP4Dw7VZ9h6BoiVuuOpCLSbWPH26WdzfYjs1OOcxxM26wgUEbh50-XVXltmOzEHo3q_qjuMraEax3CN5LrHrRjRKw2wIWhtstbrj46gwX4MkOBgajBVjrAerRTM1-JLdWC8U9cjP22AqjBjdDvnNcfMVy3PkVmprIApH6o9Ebw3eYm824g97Z2Q30EJZd7wbVgUlgP3TagDm4QsIPQtvEmbH_iuhto_onT_EehZON_MZNm2Q42eBEe7t8GLz10Q2jW1ic7LwWOEn2VZFwu0vsQ-_4HrFr1T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