<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/71250>71250</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang] Assertion in `getObjCEncodingForStructureImpl` with `[[no_unique_address]]` in Objective-C++ class
</td>
</tr>
<tr>
<th>Labels</th>
<td>
c++20,
clang:codegen,
crash-on-valid,
objective-c++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
BertalanD
</td>
</tr>
</table>
<pre>
When compiling the following Objective-C++ code with an asserts build of `main` (c7a7a43db):
```objc++
struct Empty {};
struct Foo {
[[no_unique_address]] Empty m_empty;
long m_a;
long m_b;
};
@interface Bar {
Foo m_foo;
}
@end
@implementation Bar
@end
```
The following assertion below is triggered:
```
void clang::ASTContext::getObjCEncodingForStructureImpl(clang::RecordDecl*, std::string&, const clang::FieldDecl*, bool, clang::QualType*) const: Assertion `CurOffs <= CurLayObj->first' failed.
```
<details>
<summary>Complete backtrace</summary>
```console
clang++: /root/llvm-project/clang/lib/AST/ASTContext.cpp:8598: void clang::ASTContext::getObjCEncodingForStructureImpl(clang::RecordDecl*, std::string&, const clang::FieldDecl*, bool, clang::QualType*) const: Assertion `CurOffs <= CurLayObj->first' 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 -x objective-c++ <source>
1. <eof> parser at end of file
2. <source>:11:17: LLVM IR generation of declaration 'Bar'
#0 0x0000000003778cf8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3778cf8)
#1 0x00000000037769bc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x37769bc)
#2 0x00000000036bf368 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007f7dbf9ec420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#4 0x00007f7dbf4af00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
#5 0x00007f7dbf48e859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
#6 0x00007f7dbf48e729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
#7 0x00007f7dbf49ffd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#8 0x0000000006de73e7 clang::ASTContext::getObjCEncodingForStructureImpl(clang::RecordDecl*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, clang::FieldDecl const*, bool, clang::QualType*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6de73e7)
#9 0x0000000006de807e clang::ASTContext::getObjCEncodingForTypeImpl(clang::QualType, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, clang::ASTContext::ObjCEncOptions, clang::FieldDecl const*, clang::QualType*) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6de807e)
#10 0x0000000003f2cb91 (anonymous namespace)::CGObjCGNU::GenerateClass(clang::ObjCImplementationDecl const*) CGObjCGNU.cpp:0:0
#11 0x0000000003b72f40 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#12 0x00000000049eb916 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#13 0x00000000049dc9d8 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49dc9d8)
#14 0x0000000005efdd54 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5efdd54)
#15 0x00000000049e9208 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49e9208)
#16 0x000000000424bdc9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x424bdc9)
#17 0x00000000041cc4be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x41cc4be)
#18 0x000000000432afce clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x432afce)
#19 0x0000000000bf5fd6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbf5fd6)
#20 0x0000000000bed89a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#21 0x0000000004027cc9 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 0x00000000036bf814 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x36bf814)
#23 0x00000000040282bf 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 0x0000000003ff0215 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ff0215)
#25 0x0000000003ff0c7d 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+++0x3ff0c7d)
#26 0x0000000003ff8ba5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ff8ba5)
#27 0x0000000000bf347c clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbf347c)
#28 0x0000000000aec0b1 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xaec0b1)
#29 0x00007f7dbf490083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#30 0x0000000000bed37e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbed37e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
```
</details>
Removing the two `long` member variables or moving the `[[no_unique_address]]` member from the C++ class to the ObjC class leads to successful compilation.
Godbolt link: https://godbolt.org/z/G35PvPP8j
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWl1z4yrS_jXkhlJKRrI-LnLhOPG8c2rOm-wke_bShQA5zCDQAso4--u3ANkWjpOTOZXMXpypiRMh1P300013I4yN4RvJ2AWYX4L51Rke7IPSF5dMWyywvDprFH26-NcDk5CorueCyw20Dwy2Sgj1w13dNN8YsfyRJUuALgG6hERRBn9w-wCxhNgYpq2BzcAFhaqFoEg7zCUoUghQRUpc4jyjDUA1yBYgvQLp7rNIw3_VfCNBdLhhrB6Ihdddb58gKC9BeQWy-N5KKX_Hj0Fv3KVU60Hyfw9sjSnVzBgwvwLzq1FOt2bu914QhELJDezW-PlQsx-aqgZ5yqVlusWEwUusJwA8nm7dKhU9uXuMSXoQ0fWCdUxabLmSTs6JaTtmpnTdR14JtDsJDRPqB-QGWs03G6YZfYnncPmoOIVEYLlx87LF4u5-qaRlWxuuN8zeNN-W15IoyuVmpfSd53zQ7HPXC-fTw8NfGVGaXjEiAFoAtITG0nDHWM3lBqDCjR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