================
@@ -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;
+  }
----------------
cor3ntin wrote:

Ok, it took me a while, but iI think i got it... sorry for the brain fart.
Because the interpreter compile functions before they are evaluated (at least 
morally), we don't know in which context they are going to be executed.

This is somewhat confusing because that means which assume we can constant 
evaluate something that is not a constant expression, which i guess is true for 
constant folding. 

In that light the patch makes sense, I think

I still wants to make sure that we can recover nicely in the presence of things 
we can't evaluate, which seems to be the case https://godbolt.org/z/bofa9b8de


Do you do the same thing for `is_constant_evaluated`?

https://github.com/llvm/llvm-project/pull/104707
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to