<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/116978>116978</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang crashes on x86_64-linux-gnu: const: Assertion `!NumChars.isZero() && "Empty byte arrays aren't allowed."' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bi6c
</td>
</tr>
</table>
<pre>
Compiler Expoloer: https://godbolt.org/z/qzox44G4e
```console
clang: /root/llvm-project/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp:140: llvm::Type* {anonymous}::CGRecordLowering::getByteArrayType(clang::CharUnits) const: Assertion `!NumChars.isZero() && "Empty byte arrays aren't allowed."' 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 -fno-verbose-asm -c --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1. <eof> parser at end of file
2. <source>:6:1: LLVM IR generation of declaration 'foo'
3. <source>:6:1: Generating code for declaration 'foo'
#0 0x0000000003bf2338 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3bf2338)
#1 0x0000000003bf003c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3bf003c)
#2 0x0000000003b3d728 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x0000771fefe42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x0000771fefe969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x0000771fefe42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x0000771fefe287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x0000771fefe2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x0000771fefe39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x0000000003f3c8a3 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f3c8a3)
#10 0x0000000003f3ef0f (anonymous namespace)::CGRecordLowering::lowerUnion(bool) CGRecordLayoutBuilder.cpp:0:0
#11 0x0000000003f4450b (anonymous namespace)::CGRecordLowering::lower(bool) CGRecordLayoutBuilder.cpp:0:0
#12 0x0000000003f46e19 clang::CodeGen::CodeGenTypes::ComputeRecordLayout(clang::RecordDecl const*, llvm::StructType*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f46e19)
#13 0x00000000040955a5 clang::CodeGen::CodeGenTypes::ConvertRecordDeclType(clang::RecordDecl const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x40955a5)
#14 0x000000000409724b clang::CodeGen::CodeGenTypes::ConvertType(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x409724b)
#15 0x0000000004098cc5 clang::CodeGen::CodeGenTypes::ConvertTypeForMem(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4098cc5)
#16 0x00000000043a5b0d clang::CodeGen::CodeGenFunction::EmitAutoVarAlloca(clang::VarDecl const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43a5b0d)
#17 0x00000000043ab3eb clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (.part.0) CGDecl.cpp:0:0
#18 0x00000000043ab646 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x43ab646)
#19 0x0000000003f4c967 clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f4c967)
#20 0x0000000003f638b9 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f638b9)
#21 0x0000000003f5b525 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f5b525)
#22 0x0000000003f632d4 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3f632d4)
#23 0x0000000003fcc674 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fcc674)
#24 0x0000000003fde518 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3fde518)
#25 0x000000000404744a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x404744a)
#26 0x0000000004042695 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4042695)
#27 0x0000000004042a7b clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4042a7b)
#28 0x000000000404cc63 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#29 0x0000000004577286 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#30 0x0000000004567fb8 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4567fb8)
#31 0x000000000650e344 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x650e344)
#32 0x0000000004574e38 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4574e38)
#33 0x000000000482f739 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x482f739)
#34 0x00000000047af62e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47af62e)
#35 0x000000000491a47e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x491a47e)
#36 0x0000000000ca87a7 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xca87a7)
#37 0x0000000000ca036a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#38 0x00000000045b8039 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
#39 0x0000000003b3dbd4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3b3dbd4)
#40 0x00000000045b862f 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
#41 0x000000000457e91d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x457e91d)
#42 0x000000000457fa0d 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+0x457fa0d)
#43 0x0000000004586dc5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4586dc5)
#44 0x0000000000ca5613 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xca5613)
#45 0x0000000000b7c224 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xb7c224)
#46 0x0000771fefe29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#47 0x0000771fefe29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#48 0x0000000000c9fe1e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc9fe1e)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
```c
union S { short a; char b[~(__SIZE_TYPE__)0 / __CHAR_BIT__ - 1]; long double __added_field__;
};
void bar (union S *);
void
foo (void)
{
union S s = { 5 };
bar (&s);
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWl1v2zjW_jXMDWFDor4vcuE4caaDzvt262wXOzcCRVG2thKpJak0mYv97QuSsi3KTlJn3GKADVrAoshznufw6JzDDyxlvWGUXoPoBkS3V7hXWy6uizomVwUvn6-XvO3qhgp499TxhlMBggXcKtVJECwAWgG02vCy4I2ac7EBaPUHQKt__8GfwvA-pMC7Bd4CxJ79RziTvBlaSYPZRksDaCU4VwCtmuaxnXWC_4sS_Wh7oFVTFwCtlryk95TpX_efKeGi_Iifea9u-ropqZiTrgPBwg89LVNL0gCDxcNzRwFaQJDcYMbZc8t7CZJb-3IviX-jojZwQLDYUHXzrOhCCPxsh6c7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