<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/122797>122797</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang crash initializing invalid C union with an empty struct
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
justincady
</td>
</tr>
</table>
<pre>
Tested with clang 19. Here's the reproducer:
```
typedef union {
struct {} first;
struct { int x; } second;
} foo;
void bar() {
foo f = {};
}
```
[Compiler Explorer](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,selection:(endColumn:2,endLineNumber:8,positionColumn:1,positionLineNumber:1,selectionStartColumn:2,selectionStartLineNumber:8,startColumn:1,startLineNumber:1),source:'typedef+union+%7B%0A++++struct+%7B%7D+first%3B%0A++++struct+%7B+int+x%3B+%7D+second%3B%0A%7D+foo%3B%0A%0Avoid+bar()+%7B%0A++++foo+f+%3D+%7B%7D%3B%0A%7D'),l:'5',n:'0',o:'C+source+%231',t:'0')),k:33.333333333333336,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:cclang1910,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'1',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,libs:!(),options:'',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+x86-64+clang+19.1.0+(Editor+%231)',t:'0')),k:33.333333333333336,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'x86-64+clang+19.1.0',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+clang+19.1.0+(Compiler+%231)',t:'0')),k:33.33333333333333,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)
Note that `first` is an empty struct, which I understand to be UB:
> The presence of a struct-declaration-list in a struct-or-union-specifier declares a new type,
within a translation unit. The struct-declaration-list is a sequence of declarations for the
members of the structure or union. If the struct-declaration-list does not contain any
named members, either directly or via an anonymous structure or anonymous union, the
behavior is undefined. The type is incomplete until immediately after the } that
terminates the list, and complete thereafter.
>
> https://www.open-std.org/JTC1/SC22/WG14/www/docs/n1570.pdf
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMV19v2zgS_zT0C2FDoizLfvCDJdd3PRyaA9rePhaUOLLYpUgtSdnxfvrFUIpjOUnbLfqwgRCD85_D3wyH3Dl51ABbkuYk3c947xtjt19756WuuLjMSiMu20_gPAh6lr6hleL6SOPNgv4bLBCWOeoboBY6a0RfgSXJjkThW0XjF-38pQMBNe21NJqSLCfRjlJKnbd95QMh29NaWudJ8pJJpfb0kSQ5RTEHldFikAtqxoyLaHcyUtCSW8LWhG1uPNXG0JqSZD86u6rfRYpfmhem7aQCS989dspYsCTdE7ZuvO8cbpAdCDscjSiN8gtjj4GQHAMrDr7Xby8akuwqI-CdkN5YwgoZuOtaKtC8hbDKYsIyworaaP-x4gqp8XIkfHbwv8dBLBrEviKbsAJPhyS7L1--VIQVDhRUXho9OAAtCqP6FpeMsAK0-K_U8KFvy3Bua8KKzjiJGlfB-IY4kY5vHXz03PqJ8SnrhR83UYifKPceNsgwva3GrIxAIiwPUCIsJyzN8F-0C4vxG7Bzw872hOUDwFiafF8hlxpXj6P01cQIvhsbo2ljJsQBioTlVzC-GWtQzeuBn-zvgr5zlA05UUM60uH09QQLZlgVGO2QumCRJSOk_K30ZrD3O0l2SbJIJn-rZ0fLbzgaFlgX0SvWi9fhP9TXM_ivlGRXhR4Tb2I0V0vlwQ5Fty4n7kupub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