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

    <tr>
        <th>Summary</th>
        <td>
            clang seems provide invalid optimize for C++, empty while(true) loop and -O1
        </td>
    </tr>

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

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

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

<pre>
    The code looks like the below, compile it as `C++` with `-O1` or `-O3`, it should output `aaa` for 100 times and loop forever, but infact, it output `aaa` forever

```c++
#include <stdio.h>
#include <stdbool.h>
 
int main() {
    for (int i = 0; i < 100; ++i)
    {
 printf("aaa\n");
    }
    while(true){}
  return 0;
}
```

https://godbolt.org/z/r5W1vf6Pc


It works with `-O0`
It works when compile the code as `C` code instead of `C++`
It also works with `gcc/g++`
According to godbolt.org, it used to works with clang `<=12.0.1`, and not work for `>=13.0.0`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx0U0Fv8jgQ_TXOZUTkjJMAhxwKFGlP3cNKe3biCXHrxJHtgOivXzmBQtF-UmQznjfP84Zn6b0-DUQVK3asOCRyCp111fX6qchQoKS26lr90xE0VhEYa788GP1FEDqCmoy9MNxDY_tRGwIdQHpgJd8z3MWv5HDRoYtHq48shtYtgWAlj6U6gO_sZBTYKYxTiFkpZYS21kHGOQTdkwc5qHj_GI_pTC4W11MAPbSyCTeq_-OYwfzA-NttLfnyNbcml1MUemjMpAiY2PugtE07Jt7_kK2tNU95WDY9BOilHhhuGG6BrW_kADCrYbiJEA1MHIAzsZt_7qPKGCz9aIbbR9mDY3R6CO1MjVFdsR8YYgSL3TP-8AgunTbEcBPcRBG43j2lHYXJDXMbN5H33M-EnsfWhTB6Jt4YHhkeT1bV1oTUuhPD4zfDoyv-zc5t-Xfza9bz-leAi3Vf_skLD_ZHsqPhx0nhbrm7n0q-xHrwgaQC2_722Q-ZNN6-XHdqmtjyC_ataaxTejhBsPBLz2ylyZOKmSeqxsjhFAmZ2DNxyDDlaXbzcbTnYBcty38dYe8RJlKeRr2JqoTaiq1MqMrW2XZdcNxg0lV52apWFtSUeaFkLjjfcNpIbFVTNDmKRFfIMeel4BlinmOaC17IfL0pszpbl5lkOadeapMac-6jiER7P1G1XWOWJUbWZPz9jbsqglb1dPIs50b74B9lQQdD1SLUE_UeRmfPeh78WRqtwI5B9_qbZpH3-eMeqB_D9dVxy4uNs1l9ZMnkTPViIx26qU4b2zM8xiZu22p09pPisz7OQjzD46LlXOF_AQAA__80RF3Z">