<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/69777>69777</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 -O2 crashed.

Bisected to 760e7d00d142ba85fcf48c00e0acc14a355da7c3, which was committed by @weiguozhi 

Compiler explorer: https://godbolt.org/z/sMW5hr1a9

```console
% cat a.c
long a;
char b;
static char *c = &b;
int d, e;
int *f;
long g(long h[]) {
  h[1] += h[1];
  return h[1];
}
static int *n();
static int *o() {
  int i[1][6][1];
  int j;
  d = 0;
 for (; d < 3; d++) {
    e = 0;
    for (; e < 6; e++) {
      j = 0;
      for (; (8 << a) + 6 + j < 1; j++) {
        long k[] = {3, 61};
        long l = g(k);
        i[0][*c + e - 23][(int)(l + *c + 2955120606988730223) + j] = 7;
      }
    }
    char **m[2] = {&c, &c};
  }
  return i[0][0];
}
void p() { n(); }
int *n() {
 b = 23;
  f = o();
  return 0;
}
int main() {}
% clang -O2 a.c
a.c:27:14: warning: address of stack memory associated with local variable 'i' returned [-Wreturn-stack-address]
   27 |       return i[0][0];
      |              ^
clang-18: /tmp/tmp4rmktvza/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-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/clang-18 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name a.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_mksSyAd1 -fcoverage-compilation-dir=/zdata/shaoli/realsmith/watchdir/reduced/case_mksSyAd1 -resource-dir /zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/lib/clang/18 -internal-isystem /zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/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 -O2 -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/a-dfec10.o -x c a.c
1.      <eof> parser at end of file
2.      Code generation
3. Running pass 'Function Pass Manager' on module 'a.c'.
4.      Running pass 'Peephole Optimizations' on function '@p'
 #0 0x00007fa9a1ed2ecf llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/../lib/libLLVM-18git.so+0x927ecf)
 #1 0x00007fa9a1ed0434 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fa9a11c0090 (/lib/x86_64-linux-gnu/libc.so.6+0x43090)
 #3 0x00007fa9a11c000b raise /build/glibc-BHL3KM/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #4 0x00007fa9a119f859 abort /build/glibc-BHL3KM/glibc-2.31/stdlib/abort.c:81:7
 #5 0x00007fa9a119f729 get_sysdep_segment_value /build/glibc-BHL3KM/glibc-2.31/intl/loadmsgcat.c:509:8
 #6 0x00007fa9a119f729 _nl_load_domain /build/glibc-BHL3KM/glibc-2.31/intl/loadmsgcat.c:970:34
 #7 0x00007fa9a11b0fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x00007fa9a25b7df5 (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 0x00007fa9a25b86ee (anonymous namespace)::PeepholeOptimizer::runOnMachineFunction(llvm::MachineFunction&) (.part.0) PeepholeOptimizer.cpp:0:0
#10 0x00007fa9a243b301 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (.part.0) MachineFunctionPass.cpp:0:0
#11 0x00007fa9a209ac81 llvm::FPPassManager::runOnFunction(llvm::Function&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/../lib/libLLVM-18git.so+0xaefc81)
#12 0x00007fa9a209aec9 llvm::FPPassManager::runOnModule(llvm::Module&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/../lib/libLLVM-18git.so+0xaefec9)
#13 0x00007fa9a209b752 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/../lib/libLLVM-18git.so+0xaf0752)
#14 0x00007fa9a880c14a (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 0x00007fa9a880c629 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-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/../lib/libclang-cpp.so.18git+0x20a3629)
#16 0x00007fa9a8ccd0b7 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/../lib/libclang-cpp.so.18git+0x25640b7)
#17 0x00007fa9a71e55f9 clang::ParseAST(clang::Sema&, bool, bool) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/../lib/libclang-cpp.so.18git+0xa7c5f9)
#18 0x00007fa9a8ccc298 clang::CodeGenAction::ExecuteAction() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/../lib/libclang-cpp.so.18git+0x2563298)
#19 0x00007fa9a99669b9 clang::FrontendAction::Execute() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/../lib/libclang-cpp.so.18git+0x31fd9b9)
#20 0x00007fa9a98e242e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/../lib/libclang-cpp.so.18git+0x317942e)
#21 0x00007fa9a99ff566 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/../lib/libclang-cpp.so.18git+0x3296566)
#22 0x000055d031d26aa6 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/clang-18+0x15aa6)
#23 0x000055d031d1e3da ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#24 0x000055d031d2301c clang_main(int, char**, llvm::ToolContext const&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/clang-18+0x1201c)
#25 0x000055d031d1de55 main (/zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/bin/clang-18+0xce55)
#26 0x00007fa9a11a1083 __libc_start_main /build/glibc-BHL3KM/glibc-2.31/csu/../csu/libc-start.c:342:3
#27 0x000055d031d1de9e _start (/zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/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 08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /zdata/shaoli/compilers/ccbuilder-compilers/clang-08d7d1ef9a1049b0fb97c2c0999f3b42c08edd40/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-cf9380.c
clang: note: diagnostic msg: /tmp/a-cf9380.sh
clang: note: diagnostic msg:

********************
%
```
</pre>
<img width="1px"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