Clang-19 crash: const clang::FieldDecl* clang::APValue::getUnionField() const: Assertion `isUnion() && "Invalid accessor"' failed.
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
@llvm/issue-subscribers-clang-codegen
Author: Anonymous (iamanonymouscs)
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
Is this also from an old issue that you creduced? If that is the case you should post updates to that issue.
Yes, this piece of code also comes from a previous bug report, but this code is not from an LLVM issue in the past; it‘s from GCC, with the ID 102034, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102434.