[clang] [clang][bytecode] Check isActive() in EvalEmitter::speculate() (PR #174183)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 2 00:01:49 PST 2026


https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/174183

If this opcode is being jumped-over, we have to ignore it.

Fixes #172191

>From 8fcc3bcd496b194abbdb34d701fad657a8f4104d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 2 Jan 2026 09:00:44 +0100
Subject: [PATCH] [clang][bytecode] Check isActive() in
 EvalEmitter::speculate()

If this opcode is being jumped-over, we have to ignore it.

Fixes #172191
---
 clang/lib/AST/ByteCode/EvalEmitter.cpp         |  2 ++
 clang/test/AST/ByteCode/builtin-constant-p.cpp | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index 2ed5147a15491..cf3cc1b17133c 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -155,6 +155,8 @@ bool EvalEmitter::fallthrough(const LabelTy &Label) {
 }
 
 bool EvalEmitter::speculate(const CallExpr *E, const LabelTy &EndLabel) {
+  if (!isActive())
+    return true;
   size_t StackSizeBefore = S.Stk.size();
   const Expr *Arg = E->getArg(0);
   if (!this->visit(Arg)) {
diff --git a/clang/test/AST/ByteCode/builtin-constant-p.cpp b/clang/test/AST/ByteCode/builtin-constant-p.cpp
index 315a907949c34..c6b074e403bed 100644
--- a/clang/test/AST/ByteCode/builtin-constant-p.cpp
+++ b/clang/test/AST/ByteCode/builtin-constant-p.cpp
@@ -148,3 +148,15 @@ static void foo(int i) __attribute__((__diagnose_if__(!__builtin_constant_p(i),
 static void bar(int i) {
   foo(15); // expected-error {{not constant}}
 }
+
+namespace Inactive {
+  int foo() {
+    if ((__extension__(
+            0 ? __extension__({ (1 ? 0 : (__builtin_constant_p("plane"))); })
+              : 0)) == 0) {
+    }
+
+    return 0;
+  }
+
+}



More information about the cfe-commits mailing list