Skip to content

clang: ICE in Bitfields.h when compiling large vector with designated initializer #170430

@AbyssStaror

Description

@AbyssStaror

Link for quick verification: https://godbolt.org/z/5nqd6d1cd

Reduced code:

#define LARGE_VECTOR_SIZE (1LU << 33)

typedef int  __attribute__((vector_size(LARGE_VECTOR_SIZE))) V;

int main() {
    volatile V a = { [0 ... ((LARGE_VECTOR_SIZE / sizeof(int)) - 1)] = 1 };
}

When compiling code containing a very large vector with GCC-style designated initializer, Clang triggers an internal compiler error with a bitfield assertion failure.

Stack dump

clang-21: /workspace/install/llvm/src/llvm-project/llvm/include/llvm/ADT/Bitfields.h:126: static T llvm::bitfields_details::Compressor<T, Bits, <anonymous> >::pack(T, T) [with T = unsigned int; unsigned int Bits = 6; bool <anonymous> = true]: Assertion `UserValue <= UserMaxValue && "value is too big"' 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: /workspace/install/llvm/build_21.1.4/bin/clang-21 -cc1 -triple x86_64-unknown-linux-gnu -O3 -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name 49025.fuzz -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/workspace/exps -fcoverage-compilation-dir=/workspace/exps -resource-dir /workspace/install/llvm/build_21.1.4/lib/clang/21 -internal-isystem /workspace/install/llvm/build_21.1.4/lib/clang/21/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -ferror-limit 19 -fmessage-length=167 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/49025-1c9e4d.o -x c /workspace/exps/featurefuzz/generate_feature_fine_tuning_qwen_4b_choose_3_1_exp/cases/49025.fuzz
1.      /workspace/exps/featurefuzz/generate_feature_fine_tuning_qwen_4b_choose_3_1_exp/cases/49025.fuzz:13:1: current parser token 'int'
2.      /workspace/exps/featurefuzz/generate_feature_fine_tuning_qwen_4b_choose_3_1_exp/cases/49025.fuzz:9:3: LLVM IR generation of declaration 'add_vectors'
3.      /workspace/exps/featurefuzz/generate_feature_fine_tuning_qwen_4b_choose_3_1_exp/cases/49025.fuzz:9:3: Generating code for declaration 'add_vectors'
 #0 0x0000654e3f843c2a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x9691c2a)
 #1 0x0000654e3f844457 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #2 0x0000654e3f83df57 llvm::sys::RunSignalHandlers() (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x968bf57)
 #3 0x0000654e3f83e1c7 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #4 0x000075ca4f009330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #5 0x000075ca4f062b2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x000075ca4f062b2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #7 0x000075ca4f062b2c pthread_kill ./nptl/pthread_kill.c:89:10
 #8 0x000075ca4f00927e raise ./signal/../sysdeps/posix/raise.c:27:6
 #9 0x000075ca4efec8ff abort ./stdlib/abort.c:81:7
#10 0x000075ca4efec81b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#11 0x000075ca4efff517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#12 0x0000654e3ed023ff llvm::AllocaInst::AllocaInst(llvm::Type*, unsigned int, llvm::Value*, llvm::Align, llvm::Twine const&, llvm::InsertPosition) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x8b503ff)
#13 0x0000654e3ed0250f llvm::AllocaInst::AllocaInst(llvm::Type*, unsigned int, llvm::Value*, llvm::Twine const&, llvm::InsertPosition) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x8b5050f)
#14 0x0000654e3fd6c480 clang::CodeGen::CodeGenFunction::CreateTempAlloca(llvm::Type*, llvm::Twine const&, llvm::Value*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x9bba480)
#15 0x0000654e3fd6c52a clang::CodeGen::CodeGenFunction::CreateTempAllocaWithoutCast(llvm::Type*, clang::CharUnits, llvm::Twine const&, llvm::Value*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x9bba52a)
#16 0x0000654e3fd6c733 clang::CodeGen::CodeGenFunction::CreateTempAlloca(llvm::Type*, clang::LangAS, clang::CharUnits, llvm::Twine const&, llvm::Value*, clang::CodeGen::RawAddress*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x9bba733)
#17 0x0000654e3fd6f882 clang::CodeGen::CodeGenFunction::CreateIRTemp(clang::QualType, llvm::Twine const&) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x9bbd882)
#18 0x0000654e40088f69 clang::CodeGen::CodeGenFunction::StartFunction(clang::GlobalDecl, clang::QualType, llvm::Function*, clang::CodeGen::CGFunctionInfo const&, clang::CodeGen::FunctionArgList const&, clang::SourceLocation, clang::SourceLocation) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x9ed6f69)
#19 0x0000654e4009311b clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x9ee111b)
#20 0x0000654e4013a5e5 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x9f885e5)
#21 0x0000654e4014007d clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x9f8e07d)
#22 0x0000654e40145278 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x9f93278)
#23 0x0000654e4014636a clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x9f9436a)
#24 0x0000654e4065fbe0 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#25 0x0000654e40649475 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xa497475)
#26 0x0000654e42d239b2 clang::ParseAST(clang::Sema&, bool, bool) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xcb719b2)
#27 0x0000654e40a6b92b clang::ASTFrontendAction::ExecuteAction() (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xa8b992b)
#28 0x0000654e40659360 clang::CodeGenAction::ExecuteAction() (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xa4a7360)
#29 0x0000654e40a739cf clang::FrontendAction::Execute() (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xa8c19cf)
#30 0x0000654e409b9f46 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xa807f46)
#31 0x0000654e40bfbf7b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0xaa49f7b)
#32 0x0000654e3a96a523 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x47b8523)
#33 0x0000654e3a95ac58 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#34 0x0000654e3a960b28 clang_main(int, char**, llvm::ToolContext const&) (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x47aeb28)
#35 0x0000654e3a7bbb4a main (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x4609b4a)
#36 0x000075ca4efee1ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#37 0x000075ca4efee28b call_init ./csu/../csu/libc-start.c:128:20
#38 0x000075ca4efee28b __libc_start_main ./csu/../csu/libc-start.c:347:5
#39 0x0000654e3a958f55 _start (/workspace/install/llvm/build_21.1.4/bin/clang-21+0x47a6f55)
clang: error: unable to execute command: Aborted (core dumped)

Clang version

clang version 21.1.4 (https://github.com/llvm/llvm-project.git 222fc11f2b8f25f6a0f4976272ef1bb7bf49521d)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /workspace/install/llvm/build_21.1.4/bin
Build config: +assertions
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/13
Candidate multilib: .;@m64
Selected multilib: .;@m64

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions