[clang] [clang] Avoid stack exhaustion in recursive `constexpr` calls (PR #201706)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 1 06:14:03 PDT 2026


AaronBallman wrote:

> @AaronBallman @erichkeane do we really want stack exhaustion tests?

Generally, we don't want those kinds of tests because they tend to be flaky (for example, the template depth exhaustion tests cause problems by failing inconsistently).

The tests are invalid, they're not testing that you get stack exhaustion warnings (in fact, it silences the very diagnostics you'd expect to be tested) and if you look at the behavior in the wild, it's reporting the same issue multiple times which is not a good QoI: https://godbolt.org/z/PWr4EMPeo
```
<source>:5:24: warning: stack nearly exhausted; compilation time may suffer, and crashes due to stack overflow are likely [-Wstack-exhausted]
    5 |     (100000000001024 ^ a(0) * 0 ? 2147483647 : rand()) ? 2147483647 : 1;
      |                        ^
<source>:5:24: warning: stack nearly exhausted; compilation time may suffer, and crashes due to stack overflow are likely [-Wstack-exhausted]
<source>:5:24: warning: stack nearly exhausted; compilation time may suffer, and crashes due to stack overflow are likely [-Wstack-exhausted]
<source>:5:24: warning: stack nearly exhausted; compilation time may suffer, and crashes due to stack overflow are likely [-Wstack-exhausted]
<source>:5:71: warning: expression result unused [-Wunused-value]
    5 |     (100000000001024 ^ a(0) * 0 ? 2147483647 : rand()) ? 2147483647 : 1;
      |                                                                       ^
5 warnings generated.
Compiler returned: 0
```
Further, the new experimental constexpr interpreter has no diagnostics but can still be made to crash: https://godbolt.org/z/Ejo3EehWr

I think this should probably be reverted so these kinds of issues can be addressed as part of the same commit.

https://github.com/llvm/llvm-project/pull/201706


More information about the cfe-commits mailing list