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

    <tr>
        <th>Summary</th>
        <td>
            clang-17 crashes at llvm::isPotentiallyReachable
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    I've encountered a crash that cannot be reproduced on gcc.godbolt.org, but it consistently occurs on my local machine. I'd like to provide more information on the compilation steps that I used with clang-17.

Before that, let me share the bug-triggering test case:
```
#include <stdlib.h>
int d;
int e;
float **f;
int main() {
  const int N = 32;
  float **g;
  float *h;
  int i;
  g = (float **)malloc(N * sizeof(float *));
  f = (float **)malloc(N * sizeof(float *));
  h = (float *)malloc(N * sizeof(float));
  i = 0;

  for (i; i < N; i++) {
 g[i] = (float *)(0);
    f[i] = (float *)malloc(N >> sizeof(float));
 }
  for (i = 0; i < N; i++) {
    for (e = 0; e < N; e++) {
 g[i][e] = 2.0f;
      f[i][e] = 1.5f;
    }
    h[i] = 0.0f;
 }
  {
    float **a = g;
    float **b = f;
    float *c = h;
 int n = N;
    int l = N;

    float p;
    float o;
 int i, j, k;
    float s;
    for (i = 0; i < l; i++)
      for (j = 0; j < n; j++)
        for (k = 0; k < d; k++) {
          p = a[i][k] * b[k][j];
          c[i] += o;
        }
  }
  for (i = 0; i < N; i++)
    if (h[i] != 3072.0f)
      abort();
  for (i = 0; i < N; i++)
    h[i] = 0.0f;
  for (i = 0; i < N; i++) {
    h[i] != 0.0f;
    abort();
  }
  return 0;
}
```

When compile it using my `clang-17` with option `-O3`, it outputs:
```
$ clang-17 -O3 small.c
small.c:50:10: warning: inequality comparison result unused [-Wunused-comparison]
   50 |     h[i] != 0.0f;
      | ~~~~~^~~~~~~
small.c:50:10: note: use '|=' to turn this inequality comparison into an or-assignment
   50 |     h[i] != 0.0f;
      | ^~
      |          |=
small.c:15:8: warning: expression result unused [-Wunused-value]
   15 |   for (i; i < N; i++) {
      | ^
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: /home/xfou/disk/llvm-project-trunk.obj.release+assertion/bin/clang-17 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name small.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=/home/xfou/bugs/21 -resource-dir /home/xfou/disk/llvm-project-trunk.obj.release+assertion/lib/clang/17 -internal-isystem /home/xfou/disk/llvm-project-trunk.obj.release+assertion/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -fdebug-compilation-dir=/home/xfou/bugs/21 -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/small-4a0367.o -x c small.c
1.      <eof> parser at end of file
2.      Optimizer
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 libLLVMSupport.so.17git       0x00007f0d0a9350df llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 63
1 libLLVMSupport.so.17git       0x00007f0d0a9326ce
2  libc.so.6 0x00007f0d0a35f520
3  libLLVMAnalysis.so.17git 0x00007f0d0b986d53 llvm::isPotentiallyReachable(llvm::Instruction const*, llvm::Instruction const*, llvm::SmallPtrSetImpl<llvm::BasicBlock*> const*, llvm::DominatorTree const*, llvm::LoopInfo const*) + 51
4 libLLVMAnalysis.so.17git      0x00007f0d0b950fc3 llvm::EarliestEscapeInfo::isNotCapturedBeforeOrAt(llvm::Value const*, llvm::Instruction const*) + 275
5  libLLVMAnalysis.so.17git 0x00007f0d0b94b187 llvm::BasicAAResult::getModRefInfo(llvm::CallBase const*, llvm::MemoryLocation const&, llvm::AAQueryInfo&) + 247
6 libLLVMAnalysis.so.17git      0x00007f0d0b925fdb llvm::AAResults::getModRefInfo(llvm::CallBase const*, llvm::MemoryLocation const&, llvm::AAQueryInfo&) + 107
7  libLLVMAnalysis.so.17git 0x00007f0d0b927ac9 llvm::AAResults::getModRefInfo(llvm::Instruction const*, std::optional<llvm::MemoryLocation> const&, llvm::AAQueryInfo&) + 409
8 libLLVMScalarOpts.so.17git    0x00007f0d0c54f6c0
9 libLLVMScalarOpts.so.17git    0x00007f0d0c550bdd
10 libLLVMScalarOpts.so.17git    0x00007f0d0c556b9d
11 libLLVMScalarOpts.so.17git    0x00007f0d0c558acf llvm::DSEPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) + 511
12 libLLVMPasses.so.17git        0x00007f0d098142e6
13 libLLVMAMDGPUCodeGen.so.17git 0x00007f0d13151a55
14 libLLVMAnalysis.so.17git      0x00007f0d0b9a802b llvm::CGSCCToFunctionPassAdaptor::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) + 1835
15 libLLVMAMDGPUCodeGen.so.17git 0x00007f0d13136576
16 libLLVMAnalysis.so.17git      0x00007f0d0b99fa4c llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) + 364
17 libLLVMipo.so.17git           0x00007f0d0d625bc6
18 libLLVMAnalysis.so.17git      0x00007f0d0b9a3e3e llvm::DevirtSCCRepeatedPass::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) + 494
19 libLLVMipo.so.17git           0x00007f0d0d625b76
20 libLLVMAnalysis.so.17git      0x00007f0d0b9a1a02 llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 3010
21 libLLVMipo.so.17git 0x00007f0d0d62ca6f llvm::ModuleInlinerWrapperPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 1327
22 libLLVMPasses.so.17git 0x00007f0d098112a6
23 libLLVMCore.so.17git          0x00007f0d0b3e9376 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) + 1222
24 libclangCodeGen.so.17git 0x00007f0d0e424ecd
25 libclangCodeGen.so.17git      0x00007f0d0e428438 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>>) + 3432
26 libclangCodeGen.so.17git      0x00007f0d0e8a74e5
27 libclangParse.so.17git 0x00007f0d07c87ba9 clang::ParseAST(clang::Sema&, bool, bool) + 1145
28 libclangFrontend.so.17git     0x00007f0d0d0bb249 clang::FrontendAction::Execute() + 201
29 libclangFrontend.so.17git 0x00007f0d0d031806 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 342
30 libclangFrontendTool.so.17git 0x00007f0d0fab608c clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 460
31 clang-17                      0x000055fddf9545c5 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 2549
32 clang-17 0x000055fddf950293
33 clang-17                      0x000055fddf95193e clang_main(int, char**, llvm::ToolContext const&) + 5374
34 clang-17 0x000055fddf94a9e3 main + 51
35 libc.so.6 0x00007f0d0a346d90
36 libc.so.6                     0x00007f0d0a346e40 __libc_start_main + 128
37 clang-17 0x000055fddf94aa25 _start + 37
clang-17: error: unable to execute command: Segmentation fault
clang-17: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 17.0.0 (wierton@114.212.81.121:~/llvm-project-trunk ff75a2be34fd76350216c36b7ea4c3f338df6215)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang-17: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-17: note: diagnostic msg: /tmp/small-4366b3.c
clang-17: note: diagnostic msg: /tmp/small-4366b3.sh
clang-17: note: diagnostic msg:

********************
```

The preprocessed source and associated run script mentioned in clang-17's diagnostic message:

[attachments.zip](https://github.com/llvm/llvm-project/files/11644808/attachments.zip)

Here are the configuration and compilation steps I used for my `clang-17`:
```
$ cmake ~/llvm-project-trunk/llvm -DLLVM_TOOL_CLANG_BUILD=ON -DLLVM_ENABLE_PROJECTS=clang -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE="Release" -DLLVM_BUILD_LLVM_DYLIB=ON -DCMAKE_C_FLAGS=-O2 -DLLVM_ENABLE_ASSERTIONS=ON
$ make clang
```

My clang's version (with commit hash):
```
clang-17 --version
clang version 17.0.0 (git@github.com:llvm/llvm-project ff75a2be34fd76350216c36b7ea4c3f338df6215)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcOl1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