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

    <tr>
        <th>Summary</th>
        <td>
            Clang crash: UNREACHABLE executed at /llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:1102!
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          shao-hua-li
      </td>
    </tr>
</table>

<pre>
    Clang at -O2 crash on the following test case.

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

```console
% cat a.c
int b, k, c;
static int j = 4;
static int l = 4;
short m, o;
static int n = -1020499714;
static int *p = &l, *s = &k;
long r;
static long t;
int u() {
  b = b & 3;
  if (b)
    return 4;
  return 8;
}
int w(int e) {
  int f[] = {e, 66, e, e, 9, e};
  int g, h, a = 0, i;
  h = 1;
  for (; h < 41; g++, h *= 2) {
    if (f[g] > 0) {
      a += f[g];
      if (a > 2)
        i = a;
    }
 if (a == 41)
      break;
  }
  return i;
}
static long x(unsigned v) {
  if (v)
    for (;;)
      for (; u() + n + *s - 1020499706 + r;) {
        o = 2;
        for (; w(*s - 41) + n + *s - -1020499635 + o >= 0; o--)
          for (; t <= 2; t++)
 ;
        for (; m;) {
          char *q;
          ++*q++;
 }
      }
  n = 6;
  return 1;
}
void y() {
  int *d = &j;
  s = d;
  c = *p;
  x(c);
}
int main() {}
%
% clang-tk -O2 a.c
Got unexpected user - out of sync with canFreelyInvertAllUsersOf() ?
UNREACHABLE executed at /zdata/shaoli/compilers/ccbuilder-repos/llvm-project/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:1102!
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-assertion/bin/clang-17 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name crash_0_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 -fcoverage-compilation-dir=/zdata/shaoli/realsmith -resource-dir /zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/lib/clang/17 -internal-isystem /zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/lib/clang/17/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 -fdebug-compilation-dir=/zdata/shaoli/realsmith -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/crash_0_reduced-e1a63c.o -x c work115/work/wrong/crash_0_reduced.c
1.      <eof> parser at end of file
2.      Optimizer
 #0 0x000055e1e9e07b1f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x3ba9b1f)
 #1 0x000055e1e9e05274 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f2f28f06420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f2f2895700b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f2f28936859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x000055e1e9d5b34e (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x3afd34e)
 #6 0x000055e1e992d789 llvm::InstCombinerImpl::freelyInvertAllUsersOf(llvm::Value*, llvm::Value*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x36cf789)
 #7 0x000055e1e996bcf1 llvm::InstCombinerImpl::sinkNotIntoLogicalOp(llvm::Instruction&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x370dcf1)
 #8 0x000055e1e99763cd llvm::InstCombinerImpl::foldNot(llvm::BinaryOperator&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x37183cd)
 #9 0x000055e1e99827b4 llvm::InstCombinerImpl::visitXor(llvm::BinaryOperator&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x37247b4)
#10 0x000055e1e993f510 llvm::InstCombinerImpl::run() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x36e1510)
#11 0x000055e1e9941f1b combineInstructionsOverFunction(llvm::Function&, llvm::InstructionWorklist&, llvm::AAResults*, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::TargetTransformInfo&, llvm::DominatorTree&, llvm::OptimizationRemarkEmitter&, llvm::BlockFrequencyInfo*, llvm::ProfileSummaryInfo*, unsigned int, llvm::LoopInfo*) InstructionCombining.cpp:0:0
#12 0x000055e1e9942dae llvm::InstCombinePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x36e4dae)
#13 0x000055e1ea073e46 llvm::detail::PassModel<llvm::Function, llvm::InstCombinePass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x3e15e46)
#14 0x000055e1e769056d llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x143256d)
#15 0x000055e1e97b638d llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x355838d)
#16 0x000055e1e7674006 llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x1416006)
#17 0x000055e1e97b430d llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x355630d)
#18 0x000055e1ea084ff6 (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&) BackendUtil.cpp:0:0
#19 0x000055e1ea088069 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-assertion/bin/clang-17+0x3e2a069)
#20 0x000055e1eb090a6d clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x4e32a6d)
#21 0x000055e1ec23c419 clang::ParseAST(clang::Sema&, bool, bool) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x5fde419)
#22 0x000055e1eb08f228 clang::CodeGenAction::ExecuteAction() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x4e31228)
#23 0x000055e1ea8d1979 clang::FrontendAction::Execute() (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x4673979)
#24 0x000055e1ea856906 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x45f8906)
#25 0x000055e1ea9b6ae6 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x4758ae6)
#26 0x000055e1e72dcae4 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x107eae4)
#27 0x000055e1e72d880a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#28 0x000055e1e72d9ddc clang_main(int, char**, llvm::ToolContext const&) (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x107bddc)
#29 0x000055e1e71ee1d5 main (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0xf901d5)
#30 0x00007f2f28938083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#31 0x000055e1e72d35ee _start (/zdata/shaoli/compilers/ccbuilder-compilers/clang-assertion/bin/clang-17+0x10755ee)
clang-tk: error: unable to execute command: Aborted
clang-tk: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 17.0.0 (https://github.com/llvm/llvm-project.git 99074aafc31593c9935da483edab1333d6ce5a5b)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /zdata/shaoli/compilers/ccbuilder-compilers
%
```
</pre>
<img width="1px" height="1px" alt="" src="http://email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