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

    <tr>
        <th>Summary</th>
        <td>
            Crashed when dumpping CFG 
        </td>
    </tr>

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

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

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

<pre>
    I am using llvm14.0.6 version and encountered a crash problem. It seems to work fine when only one file is processed, but as soon as there is more than one file, the program crashes.

My process is as follows:

1. I constructed a ClangTool instance with std::vecotr<std::string> args, and registered an ASTMather;
2. In the callback of ASTMatcher, after obtaining the Body of a function, call CFG::buildCFG to construct the control flow chart, and save the returned unique_ptr to the global variable;
3. When I did all the work to free the smart pointer, the program crashed.

I used gdb to view the debug information, the crash code is as follows:

> void destroyAll() {
    if (getNumBuckets() == 0) // Nothing to do.
      return;
    const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
    for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P) {
      if (!KeyInfoT::isEqual(**P->getFirst()**, EmptyKey) &&
          !KeyInfoT::isEqual(P->getFirst(), TombstoneKey))
        P->getSecond().~ValueT();
      P->getFirst().~KeyT();
    }
  }

The issue is:
getBuckets() returns nullptr, and getBucketsEnd() returns not nullptr because getNumBuckets() has a non-zero value. So, calling P->getFirst() after entering the for loop causes problems.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx9VduO4jgQ_ZrwUuooJM3tIQ80DSu0mtFIjXYeV07sJN52bMYXepmv3yqHAD2LBpnEl6pTp25OZfi53APrITipW1Dq1E-f0yydw0lYJ40GpjkIXZugvbCCA4PaMtfB0ZpKiT6FvQcnRO_AG_gw9h0aqQV8dEKD0eqMD4FbSoB0pFQL5wRP8g1UwQNz4AxZQfUO8UmoN_j2HdNXVZLGY1JvLZK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