<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/95495>95495</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang-19 crash: const clang::FieldDecl* clang::APValue::getUnionField() const: Assertion `isUnion() && "Invalid accessor"' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
iamanonymouscs
</td>
</tr>
</table>
<pre>
### Description:
I encountered an internal compiler error (ICE) while compiling a C++ code snippet using Clang++ version 19.0.0 on Ubuntu Linux.
Below are the details of the environment, code, and command lines used.
Also ICE on trunk, compiler explorer:https:https://godbolt.org/z/oxWoW4q5T
### OS and Platform:
```
# uname -a
Linux ubuntu 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
```
### Program:
```
# cat z1.cpp
using size_t = decltype(sizeof 0);
namespace std {
template<typename T> union initializer_list {
const T *ptr;
size_t n;
};
}
template<typename T>
void Task() {}
auto b = { &Task<int> };
```
### Command Lines:
```
# clang++ z1.cpp -Wall -Wextra -Werror -std=c++17 -O2 -fno-strict-aliasing -fstack-protector-strong -fno-rtti -fno-exceptions -Wno-unused-function -Wno-unused-parameter -Wno-unused-variable -Wno-vla -Wno-gnu-zero-variadic-macro-arguments -Wno-vla -Wno-gnu-zero-variadic-macro-arguments -Werror=array-bounds -Werror=sizeof-pointer-div -Werror=unused -Werror=volatile-register-var -c -o z1.o
clang++: /root/llvm-project/clang/include/clang/AST/APValue.h:564: const clang::FieldDecl* clang::APValue::getUnionField() const: Assertion `isUnion() && "Invalid accessor"' 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 -Wall -Wextra -Werror -std=c++17 -O2 -fno-strict-aliasing -fstack-protector-strong -fno-rtti -fno-exceptions -Wno-unused-function -Wno-unused-parameter -Wno-unused-variable -Wno-vla -Wno-gnu-zero-variadic-macro-arguments -Wno-vla -Wno-gnu-zero-variadic-macro-arguments -Werror=array-bounds -Werror=sizeof-pointer-div -Werror=unused -Werror=volatile-register-var -c <source>
1. <eof> parser at end of file
2. <source>:10:6: LLVM IR generation of declaration 'b'
3. <source>:10:6: Generating code for declaration 'b'
#0 0x0000000003a094d8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a094d8)
#1 0x0000000003a071bc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a071bc)
#2 0x000000000394fbd8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x000072238ba42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x000072238ba969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x000072238ba42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x000072238ba287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x000072238ba2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x000072238ba39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x0000000003d2a769 (anonymous namespace)::ConstStructBuilder::Build(clang::APValue const&, clang::RecordDecl const*, bool, clang::CXXRecordDecl const*, clang::CharUnits) (.constprop.0) CGExprConstant.cpp:0:0
#10 0x0000000003d2b1be clang::CodeGen::ConstantEmitter::tryEmitPrivate(clang::APValue const&, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d2b1be)
#11 0x0000000003d3051c clang::CodeGen::ConstantEmitter::tryEmitPrivateForVarInit(clang::VarDecl const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d3051c)
#12 0x0000000003d30892 clang::CodeGen::ConstantEmitter::tryEmitForInitializer(clang::VarDecl const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3d30892)
#13 0x0000000003e0ad7c clang::CodeGen::CodeGenModule::EmitGlobalVarDefinition(clang::VarDecl const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e0ad7c)
#14 0x0000000003e2d3d9 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e2d3d9)
#15 0x0000000003e2da5b clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3e2da5b)
#16 0x0000000003e37c3b clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#17 0x00000000042e96c6 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#18 0x00000000042d9c48 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42d9c48)
#19 0x000000000635e724 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x635e724)
#20 0x00000000042e7248 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42e7248)
#21 0x000000000456c079 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x456c079)
#22 0x00000000044f2e9e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44f2e9e)
#23 0x000000000465354e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x465354e)
#24 0x0000000000c6adcc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc6adcc)
#25 0x0000000000c6412a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#26 0x000000000432a679 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
#27 0x0000000003950084 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3950084)
#28 0x000000000432ac6f 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
#29 0x00000000042f0b15 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42f0b15)
#30 0x00000000042f157d 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+++0x42f157d)
#31 0x00000000042f9275 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42f9275)
#32 0x0000000000c682d5 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc682d5)
#33 0x0000000000b41d14 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb41d14)
#34 0x000072238ba29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#35 0x000072238ba29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#36 0x0000000000c63bde _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc63bde)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWt1y2ziyfhr4BkUVCVCkeOELWbZynErO-IydZO5UIAhKOIYALgAqcp5-CyAkE4rtWWft2a3ancpYIn4a39fd6G6AIsbwtWTsHEwvwPTyjPR2o_Q5J1silXzYqt5Qc1ar5uEcIDz8g5fMUM07y5UEeA7SS5DOryGTVPXSMs0aSCTk7qskAlK17bhgGjKtlYYAza4XVwBV8PuGCxa6uVxDAhcAXQB0AalqGDSSdx2zsDeucyGIXIfuHdOGKwmzapJOUqgk_FL30vbwE5f9fgIHRBdMqO-QaAbthsGGWcKFgar1j0zuuFZyy6QFaOEXdJ9ENg7Q1n0KLpmBvWHNZBA4F0bB68WVW9DqXt4PMw_s9p1QmmmA5xtrOzP6BGgJ0HKtmloJO1F6DdDyB0BLtf-mvuV_m94N8sPfo5p_u_V4bgSxrdLbo6pBkYZ_hwmwl2TLYEKGFq8G2A86ySfZdJImKMPJmkmmOYUAYYTyJCjt9vMN_Kwk_Ng7jcIMAzzHKcDzDMEvdwuIUoThflasivzk48P_fgFo6Vd7GtkJoRut1pq8SIQSC39kE9p1YxGDCxj-g60sBPgSNowK-9AxgGauVbUwBagC-GIY77RhOkIZNLaBoAzNEFq27QSxDOCFm-61dgfwFeylcyguueVE8B9MrwQ3djwVQqqksfAOAjTvrD4u5roCNPnYCMrL44P77r88t_zQu1O8gXfE3AM0c_vDLX6YSXqrYO25g_ICAlT4gXjBpXX4o-VetsIi-Pcn598v2mK05QabwOQbEQIm39jeauI-_ZZOjG0AvqTD2KyEyW8IJq1UibGaU5sQ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