<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69880>69880</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang: Assertion `SrcSubReg == PrevCopy->getOperand(1).getSubReg() && "Unexpected mismatching subreg!"' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
shao-hua-li
</td>
</tr>
</table>
<pre>
Clang at -O3 crashes on the following test case.
Bisected to 760e7d00d142ba85fcf48c00e0acc14a355da7c3, which was committed by @weiguozhi
Compiler explorer: https://godbolt.org/z/Yz1M9hKv8
```console
% cat a.c
int a, b, c, d, j;
static int *e = &d, *h;
static int **f = &e;
int *g;
int *i;
long l;
void m() { int ***k[2] = {&f, &f}; }
int* n() {return i;}
void o() {
int *p = &c;
int q = 5;
int r;
for (; j;)
s:;
for (;;) {
*p = q;
**f = 0 >= b;
if (a << **f) {
i = &r;
for (;;)
;
}
int *t = &q;
h = t;
if (c)
goto s;
if (l)
g = n();
}
}
int main() {}
% clang -O3 a.c
clang-18: /tmp/tmp85p3naqm/tmpa6gf87vx/llvm/lib/CodeGen/PeepholeOptimizer.cpp:1451: bool {anonymous}::PeepholeOptimizer::foldRedundantCopy(llvm::MachineInstr&, llvm::DenseMap<llvm::TargetInstrInfo::RegSubRegPair, llvm::MachineInstr*>&, llvm::SmallPtrSetImpl<llvm::MachineInstr*>&): Assertion `SrcSubReg == PrevCopy->getOperand(1).getSubReg() && "Unexpected mismatching subreg!"' 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: /zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/clang-18 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name reduced.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/zdata/shaoli/realsmith/watchdir/reduced/case_pMV4NNXz -fcoverage-compilation-dir=/zdata/shaoli/realsmith/watchdir/reduced/case_pMV4NNXz -resource-dir /zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/lib/clang/18 -internal-isystem /zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/11/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/reduced-17f42f.o -x c reduced.c
1. <eof> parser at end of file
2. Code generation
3. Running pass 'Function Pass Manager' on module 'reduced.c'.
4. Running pass 'Peephole Optimizations' on function '@o'
#0 0x00007f1154c42f2f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libLLVM-18git.so+0x926f2f)
#1 0x00007f1154c40494 SignalHandler(int) Signals.cpp:0:0
#2 0x00007f1153f31090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)
#3 0x00007f1153f3100b raise /build/glibc-BHL3KM/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#4 0x00007f1153f10859 abort /build/glibc-BHL3KM/glibc-2.31/stdlib/abort.c:81:7
#5 0x00007f1153f10729 get_sysdep_segment_value /build/glibc-BHL3KM/glibc-2.31/intl/loadmsgcat.c:509:8
#6 0x00007f1153f10729 _nl_load_domain /build/glibc-BHL3KM/glibc-2.31/intl/loadmsgcat.c:970:34
#7 0x00007f1153f21fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#8 0x00007f1155327336 (anonymous namespace)::PeepholeOptimizer::foldRedundantCopy(llvm::MachineInstr&, llvm::DenseMap<llvm::TargetInstrInfo::RegSubRegPair, llvm::MachineInstr*, llvm::DenseMapInfo<llvm::TargetInstrInfo::RegSubRegPair, void>, llvm::detail::DenseMapPair<llvm::TargetInstrInfo::RegSubRegPair, llvm::MachineInstr*>>&, llvm::SmallPtrSetImpl<llvm::MachineInstr*>&) (.isra.0) PeepholeOptimizer.cpp:0:0
#9 0x00007f1155327c4e (anonymous namespace)::PeepholeOptimizer::runOnMachineFunction(llvm::MachineFunction&) (.part.0) PeepholeOptimizer.cpp:0:0
#10 0x00007f11551ab0c1 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#11 0x00007f1154e0ac51 llvm::FPPassManager::runOnFunction(llvm::Function&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libLLVM-18git.so+0xaeec51)
#12 0x00007f1154e0ae99 llvm::FPPassManager::runOnModule(llvm::Module&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libLLVM-18git.so+0xaeee99)
#13 0x00007f1154e0b722 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libLLVM-18git.so+0xaef722)
#14 0x00007f115b5732ca (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>) BackendUtil.cpp:0:0
#15 0x00007f115b5737a9 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>>) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libclang-cpp.so.18git+0x20977a9)
#16 0x00007f115ba337d7 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libclang-cpp.so.18git+0x25577d7)
#17 0x00007f1159f4f3a9 clang::ParseAST(clang::Sema&, bool, bool) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libclang-cpp.so.18git+0xa733a9)
#18 0x00007f115ba329b8 clang::CodeGenAction::ExecuteAction() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libclang-cpp.so.18git+0x25569b8)
#19 0x00007f115c6ccbb9 clang::FrontendAction::Execute() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libclang-cpp.so.18git+0x31f0bb9)
#20 0x00007f115c64862e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libclang-cpp.so.18git+0x316c62e)
#21 0x00007f115c765766 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libclang-cpp.so.18git+0x3289766)
#22 0x0000564f16109aa6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/clang-18+0x15aa6)
#23 0x0000564f161013da ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#24 0x0000564f1610601c clang_main(int, char**, llvm::ToolContext const&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/clang-18+0x1201c)
#25 0x0000564f16100e55 main (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/clang-18+0xce55)
#26 0x00007f1153f12083 __libc_start_main /build/glibc-BHL3KM/glibc-2.31/csu/../csu/libc-start.c:342:3
#27 0x0000564f16100e9e _start (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/clang-18+0xce9e)
clang: error: unable to execute command: Aborted
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 760e7d00d142ba85fcf48c00e0acc14a355da7c3)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin
clang: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/reduced-55cf75.c
clang: note: diagnostic msg: /tmp/reduced-55cf75.sh
clang: note: diagnostic msg:
********************
%
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUOtty27a2XwO_YKghQfH24AdZtprMTmqP7Xaf86QBwUUKLQiwACjb-fozAKkLZXkn6elu3IxDSQsL64Z1AwhqDG8kwCVKrlByfUF7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