llvm / llvm/llvm-project

Clang ICE in SelectionDAG when indexing extremely large vector_size type

Open
#173,829 1 comment 0 reactions 0 assignees View on GitHub
backend:X86 crash-on-invalid llvm:SelectionDAG
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

### Link for quick verification: https://godbolt.org/z/ncTPnj3f9
```c
typedef int v4si __attribute__ ((vector_size (1 << 29)));
void foo(v4si x) {
x[0] = 1;
}
```
Go back to `clang 11.0.0 (assertions)`.
Using an extremely large GCC-style vector type (e.g. `__attribute__((vector_size(1<<29)))`) and performing a simple element access
(`x[0] = 1`) triggers an ICE, which indicates a mismatch between the computed memory access size for vector element indexing and the associated `MachineMemOperand` size when handling vectors with extremely large total sizes.
## Stack dump
```console
clang++: /root/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:13105: llvm::MemSDNode::MemSDNode(unsigned int, unsigned int, const llvm::DebugLoc&, llvm::SDVTList, llvm::EVT, llvm::MachineMemOperand*): Assertion `(!MMO->getType().isValid() || TypeSize::isKnownLE(memvt.getStoreSize(), MMO->getSize().getValue())) && "Size mismatch!"' 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++ -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
1. parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module ''.
4. Running pass 'X86 DAG->DAG Instruction Selection' on function '@_Z3fooDv134217728_i'
#0 0x0000000004301458 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4301458)
#1 0x00000000042fe884 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x42fe884)
#2 0x0000000004243628 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x0000726a02a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x0000726a02a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x0000726a02a42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x0000726a02a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x0000726a02a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x0000726a02a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x00000000058dcb9c llvm::MemSDNode::MemSDNode(unsigned int, unsigned int, llvm::DebugLoc const&, llvm::SDVTList, llvm::EVT, llvm::MachineMemOperand*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x58dcb9c)
#10 0x00000000058eca01 llvm::SelectionDAG::getLoad(llvm::ISD::MemIndexedMode, llvm::ISD::LoadExtType, llvm::EVT, llvm::SDLoc const&, llvm::SDValue, llvm::SDValue, llvm::SDValue, llvm::EVT, llvm::MachineMemOperand*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x58eca01)
#11 0x0000000005901f9d llvm::SelectionDAG::getLoad(llvm::ISD::MemIndexedMode, llvm::ISD::LoadExtType, llvm::EVT, llvm::SDLoc const&, llvm::SDValue, llvm::SDValue, llvm::SDValue, llvm::MachinePointerInfo, llvm::EVT, llvm::Align, llvm::MachineMemOperand::Flags, llvm::AAMDNodes const&, llvm::MDNode const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5901f9d)
#12 0x000000000590283f llvm::SelectionDAG::getLoad(llvm::EVT, llvm::SDLoc const&, llvm::SDValue, llvm::SDValue, llvm::MachinePointerInfo, llvm::MaybeAlign, llvm::MachineMemOperand::Flags, llvm::AAMDNodes const&, llvm::MDNode const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x590283f)
#13 0x00000000058bd985 llvm::SelectionDAGBuilder::visitLoad(llvm::LoadInst const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x58bd985)
#14 0x00000000058d0502 llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x58d0502)
#15 0x0000000005962fcd llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator_w_bits, false, true>, llvm::ilist_iterator_w_bits, false, true>, bool&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5962fcd)
#16 0x0000000005963a38 llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5963a38)
#17 0x000000000596556c llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x596556c)
#18 0x0000000005950dff llvm::SelectionDAGISelLegacy::runOnMachineFunction(llvm::MachineFunction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5950dff)
#19 0x0000000003598cf9 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#20 0x0000000003bef316 llvm::FPPassManager::runOnFunction(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bef316)
#21 0x0000000003bef6c1 llvm::FPPassManager::runOnModule(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bef6c1)
#22 0x0000000003beff2f llvm::legacy::PassManagerImpl::run(llvm::Module&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3beff2f)
#23 0x00000000045c2e3c (anonymous namespace)::EmitAssemblyHelper::RunCodegenPipeline(clang::BackendAction, std::unique_ptr>&, std::unique_ptr>&) BackendUtil.cpp:0:0
#24 0x00000000045c3770 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+++0x45c3770)
#25 0x0000000004c62327 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c62327)
#26 0x0000000006a1e5ac clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a1e5ac)
#27 0x0000000004c62788 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c62788)
#28 0x0000000004f58e05 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f58e05)
#29 0x0000000004ed909e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ed909e)
#30 0x000000000505318d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x505318d)
#31 0x0000000000de63ec cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde63ec)
#32 0x0000000000ddce3a ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#33 0x0000000000ddcfbd int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#34 0x0000000004cd4e59 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#35 0x0000000004243ac4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4243ac4)
#36 0x0000000004cd546f clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#37 0x0000000004c95f52 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c95f52)
#38 0x0000000004c96efe clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c96efe)
#39 0x0000000004c9e355 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c9e355)
#40 0x0000000000de27e1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde27e1)
#41 0x0000000000c8d114 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc8d114)
#42 0x0000726a02a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#43 0x0000726a02a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#44 0x0000000000ddc8d5 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddc8d5)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the crash with the provided C vector example, then inspect llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp around MemSDNode and SelectionDAG::getLoad, along with SelectionDAGBuilder::visitLoad from the stack trace. Done means the reproducer no longer triggers the assertion and regression coverage verifies the behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.