<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63601>63601</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang: Assertion `SizeSoFar == Layout->getSizeInBytes() && "Layout of constant struct may be incorrect!"' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wierton
</td>
</tr>
</table>
<pre>
The testcase (compiled with `clang -O0 small.c`):
```
struct a {
int b;
} c;
struct a d[3141559492] = {4};
void e() {
d[-1] = c;
}
```
Compiler Explorer: https://gcc.godbolt.org/z/fadY3bjsE
clang's version:
```
$ clang --version
clang version 17.0.0 (https://github.com/llvm/llvm-project.git 36999318f09122fa41baff838f46c753db078275)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-assertions-trunk/bin
```
clang's full assertion message:
```
clang: /root/llvm-project/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:3303:
void emitGlobalConstantStruct(const llvm::DataLayout&, const llvm::ConstantStruct*,
llvm::AsmPrinter&, const llvm::Constant*, uint64_t, llvm::AsmPrinter::AliasMapTy*):
Assertion `SizeSoFar == Layout->getSizeInBytes() && "Layout of constant struct may be incorrect!"' failed.
```
clang's output (with stack backtrace)
```
<source>:6:3: warning: array index -1 is before the beginning of the array [-Warray-bounds]
6 | d[-1] = c;
| ^ ~~
<source>:4:1: note: array 'd' declared here
4 | struct a d[3141559492] = {4};
| ^
clang: /root/llvm-project/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:3303: void emitGlobalConstantStruct(const llvm::DataLayout&, const llvm::ConstantStruct*, llvm::AsmPrinter&, const llvm::Constant*, uint64_t, llvm::AsmPrinter::AliasMapTy*): Assertion `SizeSoFar == Layout->getSizeInBytes() && "Layout of constant struct may be incorrect!"' 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 -S --gcc-toolchain=/opt/compiler-explorer/gcc-9.2.0 -fcolor-diagnostics -fno-crash-diagnostics -O0 <source>
1. <eof> parser at end of file
2. Code generation
#0 0x000055e44e57d86f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3bf786f)
#1 0x000055e44e57b5dc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3bf55dc)
#2 0x000055e44e4c5e68 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f0f6f119420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007f0f6ebe600b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#5 0x00007f0f6ebc5859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#6 0x00007f0f6ebc5729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#7 0x00007f0f6ebd6fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#8 0x000055e44f3de142 emitGlobalConstantImpl(llvm::DataLayout const&, llvm::Constant const*, llvm::AsmPrinter&, llvm::Constant const*, unsigned long, llvm::DenseMap<unsigned long, llvm::SmallVector<llvm::GlobalAlias const*, 1u>, llvm::DenseMapInfo<unsigned long, void>, llvm::detail::DenseMapPair<unsigned long, llvm::SmallVector<llvm::GlobalAlias const*, 1u>>>*) AsmPrinter.cpp:0:0
#9 0x000055e44f3dee86 llvm::AsmPrinter::emitGlobalConstant(llvm::DataLayout const&, llvm::Constant const*, llvm::DenseMap<unsigned long, llvm::SmallVector<llvm::GlobalAlias const*, 1u>, llvm::DenseMapInfo<unsigned long, void>, llvm::detail::DenseMapPair<unsigned long, llvm::SmallVector<llvm::GlobalAlias const*, 1u>>>*) (.constprop.0) AsmPrinter.cpp:0:0
#10 0x000055e44f3e05cb llvm::AsmPrinter::emitGlobalVariable(llvm::GlobalVariable const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4a5a5cb)
#11 0x000055e44f3e23bb llvm::AsmPrinter::doFinalization(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4a5c3bb)
#12 0x000055e44dedb515 llvm::FPPassManager::doFinalization(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3555515)
#13 0x000055e44dee7ff6 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3561ff6)
#14 0x000055e44e7fca93 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3e76a93)
#15 0x000055e44f7fd76d clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4e7776d)
#16 0x000055e450cf8c99 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6372c99)
#17 0x000055e44f7fbf28 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4e75f28)
#18 0x000055e44f0406e9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x46ba6e9)
#19 0x000055e44efc6036 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4640036)
#20 0x000055e44f124e96 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x479ee96)
#21 0x000055e44ba71f54 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x10ebf54)
#22 0x000055e44ba6dc7a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#23 0x000055e44ee24cdd 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
#24 0x000055e44e4c6370 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b40370)
#25 0x000055e44ee252ff 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
#26 0x000055e44edec48c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x446648c)
#27 0x000055e44edecf1d 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+0x4466f1d)
#28 0x000055e44edf4ffd clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x446effd)
#29 0x000055e44ba701ca clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x10ea1ca)
#30 0x000055e44b976545 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xff0545)
#31 0x00007f0f6ebc7083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#32 0x000055e44ba68a5e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x10e2a5e)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWl1z2zaX_jXwDUYaEvy-8IUiW206ycQTe7uzVxoQOJDRUAAXAP3Ri_72HZCURMiynW7V9J1534xji-TBwXMenC-AotbKjQK4RNkHlF1d0M7da3P5KME4rS5qzZ8v7-4BO7COUQsYkZLpbSsb4PhRunuM8og1VG3w7EuE7ZY2zZyhPEKkQskCRVcoWvjL4ae_tM50zGGKUfFhuIOxVA7XKBmvUXGF2f5qL89R9iGJ0zjLqrQiKLvCKLnyWlJUXO3FH7TkGBApEammU_jRs3g3ik0nOwlz-L0cjDX4-qlttAGDkgW-d6613jyyQmS1YWy-0bzWjZtrs0Fk9TsiK0H5_yT1b_Z6qq1nCpHC4gcwVmr1GkeIpHikdbYTPWjYjcZxMY_mkV-UI0jS3Xf1nOktIqumedj9mbVG_wbMzTfS4SSvqiqJSxFVMSGCpnFNhSiTUqQ5K7KE11FRkiLzS9nPfUfNBpwn4KnM13k669Q3pR_VrJGqe5ptVDfK3RugHG81h8ZLt9rKp-HRR2UdbRrgV7JnEpGVbh0iq9GpzAx2PJNVb-uMWgvGSa3szJlOfUNkVUv1xpIdSBZd0-D9eLwFa-kGXuN8GDeAMlq7I84mTMoakdVSc_gJFCKrhd3eGKlcD_pwMWdti5JFkkTJfsrBObfS_dTomjZL7flQ7rZ38T62lHW4nydZoGRxRR39RJ915xDJEVniY4FjDQtElsNUB5kpvjeVDMNxJ5XL07Xzn09qGa4bSe1n2t4998MO4b7YE47y6Fb-Drd6RY2POh94gzUzlFxvwPmnH9WHZwd2F7AeYY4RIYMg1mKAS5XDYybY0mdcA5aKaWP6lYkRIYgUWFCfmObf5Ry6c23nfOz0ecw6yr7hmrJvzlAGe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