<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69907>69907</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
SelectionDag Assert (w/ asserts) / backend crash (w/o asserts) with Stack MTE + AFDO
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hctim
</td>
</tr>
</table>
<pre>
This backend crash was noticed when building the Android source tree with `-fsanitize=memtag-stack`. I have reduced the input test case using creduce, as it's a combination of a few key conditions:
1. `-fsanitize=memtag-stack`,
2. An AFDO profile that's only available in the internal branches of Android (but is added here and doesn't contain any confidential information),
3. Exceptions, stack protector, and hot-cold splitting.
You can see a [workaround](https://android-review.git.corp.google.com/c/platform/art/+/2796073) (from a different source file than the one that's attached below) in the Android tree, but we'd like to see if this miscompile can be debugged.
I've also reproduced this on a tip-of-tree build of LLVM (at cbbb545c4618969850d88bb008ab7f1c2918d5c3) and looks like it fails with a SelectionDAG assert. The Android toolchain is built without asserts, so that results in a backend crash.
The three files (script, cpp, afdo) are attached: [backend-crash.zip](https://github.com/llvm/llvm-project/files/13068367/backend-crash.zip). You'll need to comment out the Android-compiler part of the shell script and point to your own tip-of-tree compiler.
My runlogs below for your convenience:
```
Local LLVM tip-of-tree compiler with assertions at cbbb545c4618969850d88bb008ab7f1c2918d5c3:
clang++: /usr/local/google/home/mitchp/llvm/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:1205: bool llvm::SelectionDAG::RemoveNodeFromCSEMaps(SDNode *): Assertion `N->getOpcode() != ISD::EntryToken && "EntryToken in CSEMap!"' 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: /usr/local/google/home/mitchp/llvm-build/opt/bin/clang++ -cc1 -triple aarch64-unknown-linux-android10000 -emit-obj -target-feature +mte -O2 -fsanitize=memtag-stack,memtag-heap,memtag-globals -stack-protector 2 -fprofile-sample-use=libhwui.afdo -fexceptions -mllvm -hot-cold-split=true -x c++ GrVkGpu-9be5c5.cpp
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module 'GrVkGpu-9be5c5.cpp'.
4. Running pass 'AArch64 Instruction Selection' on function '@_ZN7GrVkGpu4MakeERK18GrVkBackendContextRK16GrContextOptionsP15GrDirectContext'
#0 0x000056119ec38fa8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x7c3dfa8)
#1 0x000056119ec36b3e llvm::sys::RunSignalHandlers() (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x7c3bb3e)
#2 0x000056119ec39658 SignalHandler(int) Signals.cpp:0:0
#3 0x00007f634725a510 (/lib/x86_64-linux-gnu/libc.so.6+0x3c510)
#4 0x00007f63472a80fc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007f634725a472 raise ./signal/../sysdeps/posix/raise.c:27:6
#6 0x00007f63472444b2 abort ./stdlib/abort.c:81:7
#7 0x00007f63472443d5 _nl_load_domain ./intl/loadmsgcat.c:1177:9
#8 0x00007f63472533a2 (/lib/x86_64-linux-gnu/libc.so.6+0x353a2)
#9 0x000056119fd48a71 llvm::SelectionDAG::RemoveNodeFromCSEMaps(llvm::SDNode*) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x8d4da71)
#10 0x000056119fd48e8f llvm::SelectionDAG::DeleteNode(llvm::SDNode*) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x8d4de8f)
#11 0x000056119fc0382a (anonymous namespace)::DAGCombiner::recursivelyDeleteUnusedNodes(llvm::SDNode*) DAGCombiner.cpp:0:0
#12 0x000056119fc04288 llvm::SelectionDAG::Combine(llvm::CombineLevel, llvm::AAResults*, llvm::CodeGenOptLevel) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x8c09288)
#13 0x000056119fda5f3a llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x8daaf3a)
#14 0x000056119fda4b9f llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x8da9b9f)
#15 0x000056119fda1942 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x8da6942)
#16 0x000056119e12c8c9 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x71318c9)
#17 0x000056119e647387 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x764c387)
#18 0x000056119e64f962 llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x7654962)
#19 0x000056119e647ea7 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x764cea7)
#20 0x000056119f3d6b15 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x83dbb15)
#21 0x000056119f8c97e1 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) CodeGenAction.cpp:0:0
#22 0x00005611a100ec26 clang::ParseAST(clang::Sema&, bool, bool) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0xa013c26)
#23 0x000056119f7e066f clang::FrontendAction::Execute() (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x87e566f)
#24 0x000056119f7518dd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x87568dd)
#25 0x000056119f8c1d27 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x88c6d27)
#26 0x000056119c6f7b42 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x56fcb42)
#27 0x000056119c6f3f3e ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#28 0x000056119c6f2c2d clang_main(int, char**, llvm::ToolContext const&) (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x56f7c2d)
#29 0x000056119c704541 main (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x5709541)
#30 0x00007f63472456ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#31 0x00007f6347245785 call_init ./csu/../csu/libc-start.c:128:20
#32 0x00007f6347245785 __libc_start_main ./csu/../csu/libc-start.c:347:5
#33 0x000056119c6f0421 _start (/usr/local/google/home/mitchp/llvm-build/opt/bin/clang+++0x56f5421)
./GrVkGpu-9be5c5.sh: line 15: 192788 Aborted /usr/local/google/home/mitchp/llvm-build/opt/bin/clang++ $ARGS
```
```
Android compiler built without assertions:
fatal error: error in backend: Cannot select: 0x558cc61b0e40: ch,glue = <<Unknown DAG Node>>
In function: _ZN7GrVkGpu4MakeERK18GrVkBackendContextRK16GrContextOptionsP15GrDirectContext
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWt1u4ziyfhrmhrAhUf8XuVDsONvY7ulGkhlgz41BkSWbG4rUIan87NMfkJJjy52e2R6MBwfoji2KLNZX9VWxSJpaK3YK4BplNyhbX9HB7bW53jMnuqtG87frx72wuKHsCRTHzFC7xy_UYqWdYMDxy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