[clang] [clang][bytecode] Fix 'if consteval' in non-constant contexts (PR #104707)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 22 09:37:12 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:

> Do you do the same thing for `is_constant_evaluated`?

Yes:
https://github.com/llvm/llvm-project/blob/933f72217e4584db03f945a3b30e8c04537f4dab/clang/lib/AST/ByteCode/InterpBuiltin.cpp#L162

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


More information about the cfe-commits mailing list