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

    <tr>
        <th>Summary</th>
        <td>
            Crash in sinkCommonCodeFromPredecessors(llvm::BasicBlock*, llvm::DomTreeUpdater*) lib/Transforms/Utils/SimplifyCFG.cpp:2475:20
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          hiraditya
      </td>
    </tr>
</table>

<pre>
    Encountered this while debugging a pending issue in #103688. I modified llvm a bit 
```diff
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 509b6d622655..c5d4ee453184 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -871,6 +871,7 @@ static bool
 CanPropagatePredecessorsForPHIs(BasicBlock *BB, BasicBlock *Succ,
 const SmallPtrSetImpl<BasicBlock *> &BBPreds) {
 assert(*succ_begin(BB) == Succ && "Succ is not successor of BB!");
+ return false;
 
   LLVM_DEBUG(dbgs() << "Looking to fold " << BB->getName() << " into "
                     << Succ->getName() << "\n");
```

With this patch the following testcase fails
```cpp
#include<stdio.h>
__attribute__((noinline))
int foo(int state) {
  void* bytecode[2];
  bytecode[0] = &&VM__OP_1;
  bytecode[1] = &&VM__TERMINATE;

  //int state = 0;
  int index = 0;

  while (1) {
 if (state==0) {
      goto *bytecode[index];
    }
    if (state == 1) {
      //printf("Unreachable\n");
      // NOTE: THIS IS ONLY REACHABLE VIA INDIRECT GOTOS
    VM__OP_1:
      printf("VM__OP_1\n");
 state = 2;
    }
    else if (state== 2) {
 printf("OP_1:(instruction=%d)\n", index);
      index++;
      goto *bytecode[index];
    }
  }

VM__TERMINATE:
 printf("TERMINATE:(instruction=%d)\n", index);
  return 0;
}

int main() {
  foo(0);
  return 0;
}
```

$ ./bin/clang++ noswitch.cpp -O3

```
4.      Running pass "simplifycfg<bonus-inst-threshold=1;forward-switch-cond;switch-range-to-icmp;switch-to-lookup;no-keep-loops;hoist-common-insts;no-hoist-loads-stores-with-cond-faulting;sink-common-insts;speculate-blocks;simplify-cond-branch;no-speculate-unpredictables>" on function "_Z3fooi"
 #0 0x000055810039ca2c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/local/user/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:22
 #1 0x000055810039ce6a PrintStackTraceSignalHandler(void*) /usr/local/user/llvm-project/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x000055810039a5f0 llvm::sys::RunSignalHandlers() /usr/local/user/llvm-project/llvm/lib/Support/Signals.cpp:105:20
 #3 0x000055810039c408 SignalHandler(int) /usr/local/user/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007fc55eb74590 (/lib/x86_64-linux-gnu/libc.so.6+0x3f590)
 #5 0x00005580fd9a2bd0 llvm::Use::operator llvm::Value*() const /usr/local/user/llvm-project/llvm/include/llvm/IR/Use.h:65:37
 #6 0x000055810057bc10 sinkCommonCodeFromPredecessors(llvm::BasicBlock*, llvm::DomTreeUpdater*) /usr/local/user/llvm-project/llvm/lib/Transforms/Utils/SimplifyCFG.cpp:2475:20
 #7 0x0000558100595ea8 (anonymous namespace)::SimplifyCFGOpt::simplifyOnce(llvm::BasicBlock*) /usr/local/user/llvm-project/llvm/lib/Transforms/Utils/SimplifyCFG.cpp:8323:49
 #8 0x0000558100596209 (anonymous namespace)::SimplifyCFGOpt::run(llvm::BasicBlock*) /usr/local/user/llvm-project/llvm/lib/Transforms/Utils/SimplifyCFG.cpp:8381:13
 #9 0x0000558100596298 llvm::simplifyCFG(llvm::BasicBlock*, llvm::TargetTransformInfo const&, llvm::DomTreeUpdater*, llvm::SimplifyCFGOptions const&, llvm::ArrayRef<llvm::WeakVH>) /usr/local/user/llvm-project/llvm/lib/Transforms/Utils/SimplifyCFG.cpp:8393:1
#10 0x000055810025ab74 iterativelySimplifyCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DomTreeUpdater*, llvm::SimplifyCFGOptions const&) /usr/local/user/llvm-project/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp:264:7
#11 0x000055810025acf9 simplifyFunctionCFGImpl(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) /usr/local/user/llvm-project/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp:282:15
#12 0x000055810025ae87 simplifyFunctionCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) /usr/local/user/llvm-project/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp:310:41
#13 0x000055810025b4d9 llvm::SimplifyCFGPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /usr/local/user/llvm-project/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp:381:7
#14 0x00005581022921a6 llvm::detail::PassModel<llvm::Function, llvm::SimplifyCFGPass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /usr/local/user/llvm-project/llvm/include/llvm/IR/PassManagerInternal.h:91:3
#15 0x00005580ffc5a1fb llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /usr/local/user/llvm-project/llvm/include/llvm/IR/PassManagerImpl.h:85:18
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWU1v4zjS_jXMhZBBkfo8-CA7dreBdCeIkx6878WgKErmRiYFkuok_35BSk5kJz07nZ2eHewGBkQXWVVPPSwWywo1RjSS8zmIFyC-vKC93Ss93wtNK2Gf6UWpquf5SjLVS8s1r6DdCwMf96LlsOJl3zRCNpDCjsvKjYQxPYdCQoBJiEiSZTO4gQdViVrwC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