llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.69k stars 11.86k forks source link

[clang++] Assertion `UserValue <= UserMaxValue && "value is too big"' failed. #112379

Open yijan4845 opened 1 week ago

yijan4845 commented 1 week ago

This testcase is generated by a fuzzer.

Compiler Explorer: https://godbolt.org/z/qcsh9qGrf

This valid code will crash on Clang Assertion Trunk, it seems that this goes back to clang-11:

typedef int __attribute__((ext_vector_type(4294967295))) type; 
void test() {
  type x;
}

Stack dump:

clang++: /root/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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.  <eof> parser at end of file
2.  <source>:2:6: LLVM IR generation of declaration 'test'
3.  <source>:2:6: Generating code for declaration 'test'
 #0 0x0000000003bae128 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bae128)
 #1 0x0000000003babdec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3babdec)
 #2 0x0000000003af9048 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007a6304c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007a6304c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007a6304c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007a6304c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007a6304c2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007a6304c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x00000000034cf4a8 llvm::AllocaInst::AllocaInst(llvm::Type*, unsigned int, llvm::Value*, llvm::Align, llvm::Twine const&, llvm::InsertPosition) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x34cf4a8)
#10 0x000000000435ebde clang::CodeGen::CodeGenFunction::CreateTempAlloca(llvm::Type*, llvm::Twine const&, llvm::Value*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x435ebde)
#11 0x000000000435ec2e clang::CodeGen::CodeGenFunction::CreateTempAllocaWithoutCast(llvm::Type*, clang::CharUnits, llvm::Twine const&, llvm::Value*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x435ec2e)
#12 0x0000000004365472 clang::CodeGen::CodeGenFunction::CreateTempAlloca(llvm::Type*, clang::CharUnits, llvm::Twine const&, llvm::Value*, clang::CodeGen::RawAddress*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4365472)
#13 0x00000000043393dc clang::CodeGen::CodeGenFunction::EmitAutoVarAlloca(clang::VarDecl const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43393dc)
#14 0x000000000433cfcb clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (.part.0) CGDecl.cpp:0:0
#15 0x000000000433d226 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x433d226)
#16 0x0000000003f02277 clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f02277)
#17 0x0000000003f18e79 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f18e79)
#18 0x0000000003f10b25 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f10b25)
#19 0x0000000003f18894 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f18894)
#20 0x0000000003f80d34 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f80d34)
#21 0x0000000003f92d1c clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f92d1c)
#22 0x0000000003ffbb0a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ffbb0a)
#23 0x0000000003ff6825 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ff6825)
#24 0x0000000003ff6ddb clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ff6ddb)
#25 0x0000000004001303 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#26 0x0000000004509516 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#27 0x00000000044fa0f8 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44fa0f8)
#28 0x0000000006646864 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6646864)
#29 0x0000000004507088 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4507088)
#30 0x00000000047c1509 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47c1509)
#31 0x000000000474008e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x474008e)
#32 0x00000000048a70de clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48a70de)
#33 0x0000000000cdc07f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcdc07f)
#34 0x0000000000cd3d8a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#35 0x000000000454ad99 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
#36 0x0000000003af94f4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3af94f4)
#37 0x000000000454b38f 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
#38 0x0000000004510c8d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4510c8d)
#39 0x0000000004511d7d 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+++0x4511d7d)
#40 0x00000000045196a5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45196a5)
#41 0x0000000000cd8f4f clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcd8f4f)
#42 0x0000000000ba8474 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xba8474)
#43 0x00007a6304c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#44 0x00007a6304c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#45 0x0000000000cd383e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcd383e)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
llvmbot commented 1 week ago

@llvm/issue-subscribers-clang-codegen

Author: Yihan Yang (yijan4845)

**This testcase is generated by a fuzzer.** Compiler Explorer: [https://godbolt.org/z/qcsh9qGrf](https://godbolt.org/z/qcsh9qGrf) This valid code will crash on Clang Assertion Trunk, it seems that this goes back to clang-11: ```cpp typedef int __attribute__((ext_vector_type(4294967295))) type; void test() { type x; } ``` Stack dump: ``` clang++: /root/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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source> 1. <eof> parser at end of file 2. <source>:2:6: LLVM IR generation of declaration 'test' 3. <source>:2:6: Generating code for declaration 'test' #0 0x0000000003bae128 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bae128) #1 0x0000000003babdec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3babdec) #2 0x0000000003af9048 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0 #3 0x00007a6304c42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #4 0x00007a6304c969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc) #5 0x00007a6304c42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476) #6 0x00007a6304c287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3) #7 0x00007a6304c2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b) #8 0x00007a6304c39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96) #9 0x00000000034cf4a8 llvm::AllocaInst::AllocaInst(llvm::Type*, unsigned int, llvm::Value*, llvm::Align, llvm::Twine const&, llvm::InsertPosition) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x34cf4a8) #10 0x000000000435ebde clang::CodeGen::CodeGenFunction::CreateTempAlloca(llvm::Type*, llvm::Twine const&, llvm::Value*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x435ebde) #11 0x000000000435ec2e clang::CodeGen::CodeGenFunction::CreateTempAllocaWithoutCast(llvm::Type*, clang::CharUnits, llvm::Twine const&, llvm::Value*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x435ec2e) #12 0x0000000004365472 clang::CodeGen::CodeGenFunction::CreateTempAlloca(llvm::Type*, clang::CharUnits, llvm::Twine const&, llvm::Value*, clang::CodeGen::RawAddress*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4365472) #13 0x00000000043393dc clang::CodeGen::CodeGenFunction::EmitAutoVarAlloca(clang::VarDecl const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43393dc) #14 0x000000000433cfcb clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&) (.part.0) CGDecl.cpp:0:0 #15 0x000000000433d226 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x433d226) #16 0x0000000003f02277 clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f02277) #17 0x0000000003f18e79 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f18e79) #18 0x0000000003f10b25 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f10b25) #19 0x0000000003f18894 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f18894) #20 0x0000000003f80d34 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f80d34) #21 0x0000000003f92d1c clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3f92d1c) #22 0x0000000003ffbb0a clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ffbb0a) #23 0x0000000003ff6825 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ff6825) #24 0x0000000003ff6ddb clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ff6ddb) #25 0x0000000004001303 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0 #26 0x0000000004509516 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0 #27 0x00000000044fa0f8 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x44fa0f8) #28 0x0000000006646864 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6646864) #29 0x0000000004507088 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4507088) #30 0x00000000047c1509 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47c1509) #31 0x000000000474008e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x474008e) #32 0x00000000048a70de clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48a70de) #33 0x0000000000cdc07f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcdc07f) #34 0x0000000000cd3d8a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0 #35 0x000000000454ad99 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 #36 0x0000000003af94f4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3af94f4) #37 0x000000000454b38f 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 #38 0x0000000004510c8d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4510c8d) #39 0x0000000004511d7d 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+++0x4511d7d) #40 0x00000000045196a5 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45196a5) #41 0x0000000000cd8f4f clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcd8f4f) #42 0x0000000000ba8474 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xba8474) #43 0x00007a6304c29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90) #44 0x00007a6304c29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40) #45 0x0000000000cd383e _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcd383e) clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation) Compiler returned: 134 ```