[clang] Enable AST mutation in the constant evaluator (PR #115168)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 26 12:31:53 PST 2024


zygoloid wrote:

> I initially was of the same opinion as you, but I think we would have to modify most call sites

It seems to me that we'd need to modify those call sites that want to perform an evaluation of a "plainly constant-evaluated expression". Aren't those exactly the call sites we need to modify anyway, in order to enable the "plainly constant-evaluated" mode, as you mention:

> It's easy to check in `SemaProxyImpl` (or wherever it's called from ) that define class etc only happen in what P2996 calls a "plainly evaluated constant evaluated context" (constexpr initialization + consteval block as of the Poland meeting)

Yeah. So it seems like our options are:

1) All calls to the evaluator in this new mode are passed a new flag to say "this is a plainly constant-evaluated evaluation", and the code is broken if there's not a `SemaProxyImpl` stashed away, but we have no static checks for that. All `SemaProxyImpl` methods must check the corresponding state and we'll have subtle bugs if they don't, but we have no static checks for that either.
2) All calls to the evaluator in this new mode are passed a `SemaProxyImpl` which indicates that "this is a plainly constant-evaluated evaluation". All code that uses the proxy has to check that it's present.

In terms of changes to the caller, these seem the same to me. (The few "plainly constant-evaluated" cases -- all of which should be within `Sema` -- change. No other callers change.) But the latter seems to give us more static safety than the former. What am I missing?

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


More information about the cfe-commits mailing list