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

    <tr>
        <th>Summary</th>
        <td>
            [clang] Break statements with unknown named loops should interrupt constant evaluation
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend,
            constexpr
      </td>
    </tr>

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

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

<pre>
    For this code:
```c++
constexpr int f1() {
  a: for (;;) {
    break azzz;
 }
  return 1;
}
static_assert(f1() == 1);
```

we currently emit:
```console
array.cpp:102:11: error: 'break' label does not name an enclosing loop or 'switch'
  102 |     break azzz;
      | ^
array.cpp:106:15: error: static assertion expression is not an integral constant expression
  106 | static_assert(f1() == 1);
      | ^~~~~~~~~
array.cpp:101:15: note: constexpr evaluation hit maximum step limit; possible infinite loop?
  101 |   a: for (;;) {
      | ^
array.cpp:106:15: note: in call to 'f1()'
  106 | static_assert(f1() == 1);
      |               ^~~~
```
(No godbolt link as it doesn't work there yet)

We emit an error for the break statement, but when evaluating the function call at compile time, we completely ignore the break statement altogether. We could handle it like a regular `break;` which would work in this case, but not for nested loops. We should simply interrupt constant evaluation of this function completely since we have already emitted an error for it.

CC @Sirraide 
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVU-vozYQ_zTmMtrImL85cEhemmMvPeyxMjABN8ZG9vCy2UM_e2VDNi-7q3ZVhAiysef3zxPpvRoMYsOKIytOiVxotK6hVmKPziWt7e_N2TqgUXnobI8sOzB-YCVf746JY7j5obPGE36ZHShDcEmZqJnYA6vCJIBk2QEu1kEYz47h_jAL0DqUV5Bfv34NU_wArDrFKYe0OAPpOryOepKkuj-l9-iIifpZLTux7AQpE_vt-wfQ8M4PN4RucQ4N6TvgpOh7OtZ4q5Hxg3RO3nfdPLPskHIRnmmggM5ZF16YqCJmJirQskU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