[clang] [clang][bytecode] Fix 'if consteval' in non-constant contexts (PR #104707)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 21 21:31:49 PDT 2024
================
@@ -4368,8 +4363,19 @@ template <class Emitter> bool Compiler<Emitter>::visitIfStmt(const IfStmt *IS) {
if (!visitDeclStmt(CondDecl))
return false;
- if (!this->visitBool(IS->getCond()))
- return false;
+ // Compile condition.
+ if (IS->isNonNegatedConsteval()) {
+ if (!this->emitIsConstantContext(IS))
+ return false;
+ } else if (IS->isNegatedConsteval()) {
+ if (!this->emitIsConstantContext(IS))
+ return false;
+ if (!this->emitInv(IS))
+ return false;
+ } else {
+ if (!this->visitBool(IS->getCond()))
+ return false;
+ }
----------------
tbaederr wrote:
Stuff like that _needs_ to be "implemented" in the interpreter. It must be, because it must be rejected as well. It's the same example as the `goto` statement above. It needs to be compiled to bytecode, somehow. If it isn't then using it in a constexpr function (without the `if consteval` will also fail).
Again, this is no different than any other if statement. I could imagine compiling two different versions of functions (one for consteval = true, one for =false), but we have the same problem with other if statements. This is just a difference between the interpreting and compiling approach.
https://github.com/llvm/llvm-project/pull/104707
More information about the cfe-commits
mailing list