<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61917>61917</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
opt crash - assert failure in RewriteStatepointsForGC.cpp with simple example
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tatuylonen
</td>
</tr>
</table>
<pre>
The following crashes opt 17.0git (master branch, most recent commit 2e1b838a889f9793d4bcd5dbfe10db9796b77143, as of Apr 3, 2023) with "opt -S -passes='default<O0>',rewrite-statepoints-for-gc crashtest.ll". It also crashes with higher optimization levels. Linux Mint 20.2, x86_64, llvm compiled from github. opt-12 and opt-14 also crash, but with a different error. The crash goes away if I remove rewrite-statepoints-from-gc or gc "statepoint-example" or don't pass the result of addrspacecast to the function call. The crash appears to happen at RewriteStatepointsForGC.cpp:573.
The original version before minimizing the code tried to convert an integer to an atomic tagged cell via getelementptr(null base)+addrspacecast or inttoptr+addrspacecast (tried both, both crash opt). Originally the called function fn2 also had gc "statepoint-example" but the same crash happens also without it (there were also various attributes and calling conventions, but they had no impact on the crash). Please let me know if there is a different way of constructing atomic values for tagged garbage collected cells that works reliably.
-------------
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"
define void @fn1(i8* %x) gc "statepoint-example" {
%r28 = addrspacecast i8* %x to i8 addrspace(1)*
call void @fn2(i8 addrspace(1)* %r28)
ret void
}
declare void @fn2(i8 addrspace(1)*)
--------------
The error message is:
% opt -S -passes='default<O0>',rewrite-statepoints-for-gc bugpoint-reduced-simplified.ll
opt: /home/ylo/llvm-project/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp:573: llvm::Value* findBaseDefiningValue(llvm::Value*, {anonymous}::DefiningValueMapTy&, {anonymous}::IsKnownBaseMapTy&): Assertion `cast<PointerType>(Def->getType())->getAddressSpace() == cast<PointerType>(CI->getType())->getAddressSpace() && "unsupported addrspacecast"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: opt -S -passes=default<O0>,rewrite-statepoints-for-gc bugpoint-reduced-simplified.ll
#0 0x0000561944eba0d6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/ylo/llvm-project/llvm/lib/Support/Unix/Signals.inc:602:22
#1 0x0000561944eba4a1 PrintStackTraceSignalHandler(void*) /home/ylo/llvm-project/llvm/lib/Support/Unix/Signals.inc:676:1
#2 0x0000561944eb7ca0 llvm::sys::RunSignalHandlers() /home/ylo/llvm-project/llvm/lib/Support/Signals.cpp:104:20
#3 0x0000561944eb9a0a SignalHandler(int) /home/ylo/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
#4 0x00007f4a43ec1420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#5 0x00007f4a4395e00b raise /build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#6 0x00007f4a4393d859 abort /build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:81:7
#7 0x00007f4a4393d729 get_sysdep_segment_value /build/glibc-SzIz7B/glibc-2.31/intl/loadmsgcat.c:509:8
#8 0x00007f4a4393d729 _nl_load_domain /build/glibc-SzIz7B/glibc-2.31/intl/loadmsgcat.c:970:34
#9 0x00007f4a4394efd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#10 0x0000561944d737fc findBaseDefiningValue(llvm::Value*, llvm::MapVector<llvm::Value*, llvm::Value*, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, llvm::Value*>, std::allocator<std::pair<llvm::Value*, llvm::Value*>>>>&, llvm::MapVector<llvm::Value*, bool, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, bool>, std::allocator<std::pair<llvm::Value*, bool>>>>&) /home/ylo/llvm-project/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp:573:5
#11 0x0000561944d73e24 findBaseDefiningValueCached(llvm::Value*, llvm::MapVector<llvm::Value*, llvm::Value*, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, llvm::Value*>, std::allocator<std::pair<llvm::Value*, llvm::Value*>>>>&, llvm::MapVector<llvm::Value*, bool, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, bool>, std::allocator<std::pair<llvm::Value*, bool>>>>&) /home/ylo/llvm-project/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp:699:38
#12 0x0000561944d74019 findBaseOrBDV(llvm::Value*, llvm::MapVector<llvm::Value*, llvm::Value*, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, llvm::Value*>, std::allocator<std::pair<llvm::Value*, llvm::Value*>>>>&, llvm::MapVector<llvm::Value*, bool, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, bool>, std::allocator<std::pair<llvm::Value*, bool>>>>&) /home/ylo/llvm-project/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp:715:64
#13 0x0000561944d7587f findBasePointer(llvm::Value*, llvm::MapVector<llvm::Value*, llvm::Value*, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, llvm::Value*>, std::allocator<std::pair<llvm::Value*, llvm::Value*>>>>&, llvm::MapVector<llvm::Value*, bool, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, bool>, std::allocator<std::pair<llvm::Value*, bool>>>>&) /home/ylo/llvm-project/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp:879:50
#14 0x0000561944d77655 findBasePointers(llvm::SetVector<llvm::Value*, std::vector<llvm::Value*, std::allocator<llvm::Value*>>, llvm::DenseSet<llvm::Value*, llvm::DenseMapInfo<llvm::Value*, void>>> const&, llvm::MapVector<llvm::Value*, llvm::Value*, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, llvm::Value*>, std::allocator<std::pair<llvm::Value*, llvm::Value*>>>>&, llvm::DominatorTree*, llvm::MapVector<llvm::Value*, llvm::Value*, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, llvm::Value*>, std::allocator<std::pair<llvm::Value*, llvm::Value*>>>>&, llvm::MapVector<llvm::Value*, bool, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, bool>, std::allocator<std::pair<llvm::Value*, bool>>>>&) /home/ylo/llvm-project/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp:1352:59
#15 0x0000561944d778c9 findBasePointers(llvm::DominatorTree&, llvm::MapVector<llvm::Value*, llvm::Value*, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, llvm::Value*>, std::allocator<std::pair<llvm::Value*, llvm::Value*>>>>&, llvm::CallBase*, (anonymous namespace)::PartiallyConstructedSafepointRecord&, llvm::MapVector<llvm::Value*, llvm::Value*, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, llvm::Value*>, std::allocator<std::pair<llvm::Value*, llvm::Value*>>>>&, llvm::MapVector<llvm::Value*, bool, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, bool>, std::allocator<std::pair<llvm::Value*, bool>>>>&) /home/ylo/llvm-project/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp:1369:59
#16 0x0000561944d7e57d insertParsePoints(llvm::Function&, llvm::DominatorTree&, llvm::TargetTransformInfo&, llvm::SmallVectorImpl<llvm::CallBase*>&, llvm::MapVector<llvm::Value*, llvm::Value*, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, llvm::Value*>, std::allocator<std::pair<llvm::Value*, llvm::Value*>>>>&, llvm::MapVector<llvm::Value*, bool, llvm::DenseMap<llvm::Value*, unsigned int, llvm::DenseMapInfo<llvm::Value*, void>, llvm::detail::DenseMapPair<llvm::Value*, unsigned int>>, std::vector<std::pair<llvm::Value*, bool>, std::allocator<std::pair<llvm::Value*, bool>>>>&) /home/ylo/llvm-project/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp:2748:3
#17 0x0000561944d80666 llvm::RewriteStatepointsForGC::runOnFunction(llvm::Function&, llvm::DominatorTree&, llvm::TargetTransformInfo&, llvm::TargetLibraryInfo const&) /home/ylo/llvm-project/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp:3219:16
#18 0x0000561944d725dc llvm::RewriteStatepointsForGC::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/ylo/llvm-project/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp:151:13
#19 0x00005619451e4563 llvm::detail::PassModel<llvm::Module, llvm::RewriteStatepointsForGC, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/ylo/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:90:3
#20 0x000056194454c107 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/ylo/llvm-project/llvm/include/llvm/IR/PassManager.h:521:7
#21 0x0000561941387947 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) /home/ylo/llvm-project/llvm/tools/opt/NewPMDriver.cpp:522:10
#22 0x00005619413b7dc5 main /home/ylo/llvm-project/llvm/tools/opt/opt.cpp:716:27
#23 0x00007f4a4393f083 __libc_start_main /build/glibc-SzIz7B/glibc-2.31/csu/../csu/libc-start.c:342:3
#24 0x000056194137ef2e _start (/usr/local/bin/opt+0x1ce7f2e)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsW9ty2ziTfhr4BiUVCZ4vfCHb0a7rH29ccXZuVSDZlLABARYA2tY8_VaD1IGyndjJ7OyfxCmVTOLQx6-7EarJrRVrBXBOkguSXJ3x3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