<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/69507>69507</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang: Assertion `isReg() && "Wrong MachineOperand accessor"' 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 crashed.

Bisected to 760e7d00d142ba85fcf48c00e0acc14a355da7c3, which was committed by @weiguozhi 

Compiler explorer: https://godbolt.org/z/4GbPGd1zz

```console
% cat a.c
short a[70];
char b, i;
short c;
int *d;
unsigned e;
static char *f = &b;
char *g;
static short h;
int j;
void k() {
  int l = 1;
  c = 5;
  for (; c;) {
    h = 0;
    for (; h <= 5; h++) {
      *f = l;
      char **m = &f;
      char **n[5];
 n[j] = m;
      e = 0;
      for (; e <= 2; e++)
        if (a[e * (h + 4)])
          break;
      i = *g;
    }
  }
  d = &l;
}
int main() {}
%
% clang -O3 a.c
clang-18: /tmp/tmp85p3naqm/tmpa6gf87vx/llvm/include/llvm/CodeGen/MachineOperand.h:375: unsigned int llvm::MachineOperand::getSubReg() const: Assertion `isReg() && "Wrong MachineOperand accessor"' 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_qmhX8Lp2 -fcoverage-compilation-dir=/zdata/shaoli/realsmith/watchdir/reduced/case_qmhX8Lp2 -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-cd53d8.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 '@k'
 #0 0x00007ff54fb3ef2f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libLLVM-18git.so+0x926f2f)
 #1 0x00007ff54fb3c494 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007ff54ee2d090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)
 #3 0x00007ff54ee2d00b raise /build/glibc-BHL3KM/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #4 0x00007ff54ee0c859 abort /build/glibc-BHL3KM/glibc-2.31/stdlib/abort.c:81:7
 #5 0x00007ff54ee0c729 get_sysdep_segment_value /build/glibc-BHL3KM/glibc-2.31/intl/loadmsgcat.c:509:8
 #6 0x00007ff54ee0c729 _nl_load_domain /build/glibc-BHL3KM/glibc-2.31/intl/loadmsgcat.c:970:34
 #7 0x00007ff54ee1dfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x00007f6cdef70355 (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 0x00007f6cdef70c4e (anonymous namespace)::PeepholeOptimizer::runOnMachineFunction(llvm::MachineFunction&) (.part.0) PeepholeOptimizer.cpp:0:0
#10 0x00007f6cdedf40c1 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#11 0x00007f6cdea53c51 llvm::FPPassManager::runOnFunction(llvm::Function&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libLLVM-18git.so+0xaeec51)
#12 0x00007f6cdea53e99 llvm::FPPassManager::runOnModule(llvm::Module&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libLLVM-18git.so+0xaeee99)
#13 0x00007f6cdea54722 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libLLVM-18git.so+0xaef722)
#14 0x00007f6ce51bc2ca (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 0x00007f6ce51bc7a9 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 0x00007f6ce567c7d7 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libclang-cpp.so.18git+0x25577d7)
#17 0x00007f6ce3b983a9 clang::ParseAST(clang::Sema&, bool, bool) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libclang-cpp.so.18git+0xa733a9)
#18 0x00007f6ce567b9b8 clang::CodeGenAction::ExecuteAction() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libclang-cpp.so.18git+0x25569b8)
#19 0x00007f6ce6315bb9 clang::FrontendAction::Execute() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libclang-cpp.so.18git+0x31f0bb9)
#20 0x00007f6ce629162e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libclang-cpp.so.18git+0x316c62e)
#21 0x00007f6ce63ae766 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/zdata/shaoli/compilers/ccbuilder-compilers/cla
ng-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/../lib/libclang-cpp.so.18git+0x3289766)
#22 0x000055732d0ffaa6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/zdata/shaoli/compilers/ccbuilder-compilers/clan
g-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/clang-18+0x15aa6)
#23 0x000055732d0f73da ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#24 0x000055732d0fc01c clang_main(int, char**, llvm::ToolContext const&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d
00d142ba85fcf48c00e0acc14a355da7c3/bin/clang-18+0x1201c)
#25 0x000055732d0f6e55 main (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/clang-
18+0xce55)
#26 0x00007f6cddb5b083 __libc_start_main /build/glibc-BHL3KM/glibc-2.31/csu/../csu/libc-start.c:342:3
#27 0x000055732d0f6e9e _start (/zdata/shaoli/compilers/ccbuilder-compilers/clang-760e7d00d142ba85fcf48c00e0acc14a355da7c3/bin/clan
g-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/a-18b4bf.c
clang: note: diagnostic msg: /tmp/a-18b4bf.sh
clang: note: diagnostic msg:

********************
%
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUOllv2zi3v4Z5IWRIlLU95MGx47a46U2QZGbum0GRRzKnEqkhqTTpr78gJS9y3K_NbO0HJLZ1xLNv3KgxopYAlyi5QsnqgvZ2q_Sl2VIVbHsaNOKiVPzlctlQWWNqcXAbY6ap2QKfoXCFwsXweSUMM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