llvm / llvm/llvm-project

[VectorCombine] Assertion `is_contained(ToFreeze->users(), &UserI) && "UserI must be a user of ToFreeze"' failed.

Open
#213,423 0 comments 0 reactions 0 assignees View on GitHub
confirmed crash-on-valid generated by fuzzer llvm:vectorcombine
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Reproducer: https://godbolt.org/z/jEca9MWvf
Testcase:
```c
#include
typedef uint16_t v2u16 __attribute__((vector_size(4)));
static uint32_t g2 = 0U;
static uint32_t g9 = 3683323801U;
static v2u16 g17;
static uint16_t g20 = 48141;
static uint16_t g27 = 23163;
void f22(v2u16 a4)
{
uint32_t bb7 = __builtin_parity(__builtin_popcount(g2));
g20 = (g17 <= a4)[bb7];
}
void f32(uint8_t a0)
{
do
{
g27 = ~g20;
g2 = 3561532384U & g9;
if (a0 == 82) g17 = ~g17;
g9 = 0;
f22(g17);
} while (g27 == -25483LL);
}
```

Dump at -O1:
```
clang: /root/llvm-project/llvm/lib/Transforms/Vectorize/VectorCombine.cpp:1883: void {anonymous}::ScalarizationResult::freeze(llvm::IRBuilderBase&, llvm::Instruction&): Assertion `is_contained(ToFreeze->users(), &UserI) && "UserI must be a user of ToFreeze"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang -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 -O1
1. parser at end of file
2. Optimizer
3. Running pass "function(drop-unnecessary-assumes,float2int,lower-constant-intrinsics,loop(loop-rotate,loop-deletion),loop-distribute,inject-tli-mappings,loop-vectorize,drop-unnecessary-assumes,infer-alignment,loop-load-elim,instcombine,simplifycfg,vector-combine,instcombine,loop-unroll,transform-warning,sroa,infer-alignment,instcombine,loop-mssa(licm),alignment-from-assumptions,loop-sink,instsimplify,div-rem-pairs,mergeicmps,expand-memcmp,tailcallelim,simplifycfg)" on module ""
4. Running pass "vector-combine" on function "f32"
#0 0x000000000441d908 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x441d908)
#1 0x000000000441a7b4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x441a7b4)
#2 0x000000000441adec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x441adec)
#3 0x0000000004359dc8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x0000713523045330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x000071352309eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
#6 0x000071352304527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
#7 0x00007135230288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
#8 0x000071352302881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
#9 0x000071352303b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#10 0x00000000062d873f (anonymous namespace)::ScalarizationResult::freeze(llvm::IRBuilderBase&, llvm::Instruction&) VectorCombine.cpp:0:0
#11 0x00000000062e6177 (anonymous namespace)::VectorCombine::scalarizeLoadExtract(llvm::LoadInst*, llvm::VectorType*, llvm::Value*) VectorCombine.cpp:0:0
#12 0x000000000630b256 (anonymous namespace)::VectorCombine::run()::'lambda'(llvm::Instruction&)::operator()(llvm::Instruction&) const (.isra.0) VectorCombine.cpp:0:0
#13 0x000000000630c146 llvm::VectorCombinePass::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x630c146)
#14 0x00000000057c3ece llvm::detail::PassModel>::runImpl(llvm::detail::PassConcept>&, llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x57c3ece)
#15 0x0000000003d55ad4 llvm::PassManager>::run(llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3d55ad4)
#16 0x000000000128c33e llvm::detail::PassModel>, llvm::AnalysisManager>::runImpl(llvm::detail::PassConcept>&, llvm::Function&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x128c33e)
#17 0x0000000003d54533 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3d54533)
#18 0x000000000128c3de llvm::detail::PassModel>::runImpl(llvm::detail::PassConcept>&, llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x128c3de)
#19 0x0000000003d53b84 llvm::PassManager>::run(llvm::Module&, llvm::AnalysisManager&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x3d53b84)
#20 0x0000000004848e2c (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr>&, std::unique_ptr>&, clang::BackendConsumer*) BackendUtil.cpp:0:0
#21 0x000000000484af93 (anonymous namespace)::EmitAssemblyHelper::emitAssembly(clang::BackendAction, std::unique_ptr>, clang::BackendConsumer*) BackendUtil.cpp:0:0
#22 0x000000000484dc03 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr, std::unique_ptr>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x484dc03)
#23 0x0000000004f2008c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f2008c)
#24 0x0000000006d2371d clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6d2371d)
#25 0x0000000004f204b8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f204b8)
#26 0x000000000524e328 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x524e328)
#27 0x00000000051daeed clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x51daeed)
#28 0x0000000005322cbd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x5322cbd)
#29 0x0000000000da984c cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xda984c)
#30 0x0000000000da046a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#31 0x0000000000da05ed int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#32 0x0000000004f97f79 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#33 0x000000000435a204 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x435a204)
#34 0x0000000004f98ae5 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#35 0x0000000004f50d92 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f50d92)
#36 0x0000000004f555c7 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f555c7)
#37 0x0000000004f5fb25 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f5fb25)
#38 0x0000000000da5d4a clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xda5d4a)
#39 0x0000000000cc1c2a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xcc1c2a)
#40 0x000071352302a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#41 0x000071352302a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#42 0x0000000000d9fe15 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xd9fe15)
clang: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the crash with the C testcase from the issue and clang at -O1. Then inspect VectorCombine.cpp, especially ScalarizationResult::freeze and VectorCombine::scalarizeLoadExtract; done means the reproducer no longer aborts on the assertion and the relevant behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.