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

    <tr>
        <th>Summary</th>
        <td>
            [clang++] extremely slow when trying to use undeclared identifiers
        </td>
    </tr>

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

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

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

<pre>
    Given a program in the following format:
```cpp
void test() {
  int a11;
  [...]  // a bunch more  variable declarations not used afterwards
  
  if( a97 == a95 ) {}  // 
```

`clang++` can take up to 5 minutes compiling this or even crashes, while `clang` can compile it just fine.

<details>
<summary>Full code example</summary>

```cpp
void test() {
  int  a11;
  int a12;
  int  a13;
  int  a14;
  int* a15;
  int  a16;
  int a17;
  int  a18;
  int  a22;
  int  a24;
  int  a25;
  int a35;
  int  a36;
  int  a37;
  int  a38;
  int  a39;
  int a40;
  int  a42;
  int  a91;
  int  a92;
  int  a98;
  int a99;

  if(
    a97 == a95,
    a96 == a96,
    a97 == a96,
    a95 == a93,
    a96 == a105
  ) {}
}
```
</details>

The example above compiles for more than 5 minutes for me. Variants can be created by adding/removing more variable declarations, but the code is somehow very sensitive to working correctly (compiling in less than 0.1 second) again.

I'm not able to pinpoint what actually causes this to create an even more minimized example, but as it seems to be influenced by the variable names, I believe that the generator for "did you mean variable x instead?" is somehow at fault here.

Here's some other things I tried/observed:
- Running `time` on it shows that `user/sys` is really low, only `real` increases over time - meaning `clang++` doesn't actually take so long for compiling, but waits for the most time.
- Saving the code above as `test.c` and running `clang++ test.c` takes very long, while using `clang test.c` takes less than a second.
- Changing that single pointer to a normal `int` "fixes" it.
- Using standard assignments instead of `if` checks fixes it, but assigning it within the `if` clause also causes the issue.
- Changing the variable names too much results in taking less time, down to 0.1 seconds.
- The time it takes to finish "compiling" (display errors) varies with the number of declarations and comparisons, but removing the "wrong" ones can fix it again.
- When encountering it in my normal project, I first got some actual crashes from Clang - I cannot re-create those though, and they only occured after what felt like a timeout, when touching the file it read from (saving again)... I can't reproduce it though, so feel free to ignore this one and only focus on the long compile time.

After trying around with this for more than 3 hours without being able to further "destill" down the issue, let's hope someone else around here has a theory on why this occurs.

For experiments, feel free to test with this Godbolt:
[Godbolt](https://godbolt.org/z/rEEY9Tfjx)
- gcc: ~140 ms
- clang (any version): at least 25000 ms
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUV8mS47gR_RroklEKChS1HHSopTXugy_22A4fk0RSRDcIKLBIpTn42x0JaCup5zARClUJBDJfLu8liCHonSXaiOZNNB8TTHFwfvN3Z0Mk_-GTVjSbtE6dNr_pA1lA2Hu38ziCthAHgt4Z447a7qB3fsQo6ldRfYjqVSyq8un2-7JycFpBpBCFXAm5BrF8Kw8AtI2As5moryuieZtOp6L5ABByK-QWENpkuwFG5wnggF5jawgUdQY9Ru1sAOsipEAKsI_kj-hVuBq8uOqFXAGulyDqD1F_AK4buMBZ3tw9RHH-eVnsDNqdkG_8WVTQoYWIPwnSHqKDBkZtU6QAnRv32nB64qADOA_Eaew8hoGCkO9wHLQhuJo8GyvnCHSEHylE6LWl6RcM9buiiNoEUX-7LoU0juhPov62TcZA5xQBfeK4NyTqdyG3tw0PAf21Wj0Uq5RPPqwAzurnpfnXJSFfAWfN877Fk_3l86bV05J8RiHnz0uPDrF-hlA_QgCsnzHUzxjq9aP1efW0af4MdP2YU8D1L3Y9OsT1zd-XLr_8gId2F_L9_tHi9mjx8Gj554-a26P6Tw3OqubKvyvFzkiv_zxQLPfpU2_n79-HazsDtu5AF54EVp-iDHFAe0fAvE5T-DfrhY0hs6sl6DxhJAXtCVApzWTeehrdgbmaDf1SYZixbYpZ-jK7dIDgRhrcEQ7kTxDIBh31gVgHjs7_ZHud8566aE4g5OomCdqCoRAK5Go6g0Cds4ozhTvU9gvhvwu5HLPAZVDRwV7bveMGOA4YAbuY0JgTdJg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