https://github.com/FYLGQ updated 
https://github.com/llvm/llvm-project/pull/177731

>From 128f0bf6edc86c0f1c1fd279466afccc95e1ebfc Mon Sep 17 00:00:00 2001
From: FYLGQ <[email protected]>
Date: Sat, 24 Jan 2026 10:58:51 +0800
Subject: [PATCH 1/3] fix-constant-eval-complex-discard

---
 clang/lib/AST/ByteCode/Compiler.cpp                    | 3 ++-
 clang/lib/AST/ByteCode/constant-eval-complex-discard.c | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 clang/lib/AST/ByteCode/constant-eval-complex-discard.c

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 272d08f5e455c..d864fdc5d7e6d 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -7406,7 +7406,8 @@ bool Compiler<Emitter>::emitComplexComparison(const Expr 
*LHS, const Expr *RHS,
                                               const BinaryOperator *E) {
   assert(E->isComparisonOp());
   assert(!Initializing);
-  assert(!DiscardResult);
+  if (DiscardResult)
+    return true;
 
   PrimType ElemT;
   bool LHSIsComplex;
diff --git a/clang/lib/AST/ByteCode/constant-eval-complex-discard.c 
b/clang/lib/AST/ByteCode/constant-eval-complex-discard.c
new file mode 100644
index 0000000000000..1d111fc049cc1
--- /dev/null
+++ b/clang/lib/AST/ByteCode/constant-eval-complex-discard.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -std=c11 -fsyntax-only 
-fexperimental-new-constant-interpreter %s
+
+void foo(void) {
+  // Complex comparison evaluated in a discarded context.
+  (void)(0 && (1i == 1i));
+}

>From b71ec175022ef25291c4bffb5bea65748730c430 Mon Sep 17 00:00:00 2001
From: FYLGQ <[email protected]>
Date: Sat, 24 Jan 2026 12:36:01 +0800
Subject: [PATCH 2/3] Move test file constant-eval-complex-discard.c to
 clang/test/AST/ByteCode

---
 clang/{lib => test}/AST/ByteCode/constant-eval-complex-discard.c | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename clang/{lib => test}/AST/ByteCode/constant-eval-complex-discard.c (100%)

diff --git a/clang/lib/AST/ByteCode/constant-eval-complex-discard.c 
b/clang/test/AST/ByteCode/constant-eval-complex-discard.c
similarity index 100%
rename from clang/lib/AST/ByteCode/constant-eval-complex-discard.c
rename to clang/test/AST/ByteCode/constant-eval-complex-discard.c

>From ca0d29573e2182cc78f0036f17542a94b8231c50 Mon Sep 17 00:00:00 2001
From: FYLGQ <[email protected]>
Date: Sun, 25 Jan 2026 17:47:25 +0800
Subject: [PATCH 3/3] [clang][bytecode] Fix crash on discarded complex
 comparison

---
 clang/lib/AST/ByteCode/Compiler.cpp              |  7 ++++++-
 .../AST/ByteCode/constant-eval-complex-discard.c |  6 ------
 .../ByteCode/constant-eval-complex-discard.cpp   | 16 ++++++++++++++++
 3 files changed, 22 insertions(+), 7 deletions(-)
 delete mode 100644 clang/test/AST/ByteCode/constant-eval-complex-discard.c
 create mode 100644 clang/test/AST/ByteCode/constant-eval-complex-discard.cpp

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index d864fdc5d7e6d..5db454c797565 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -7406,8 +7406,13 @@ bool Compiler<Emitter>::emitComplexComparison(const Expr 
*LHS, const Expr *RHS,
                                               const BinaryOperator *E) {
   assert(E->isComparisonOp());
   assert(!Initializing);
-  if (DiscardResult)
+if (DiscardResult) {
+    if (!this->discard(LHS))
+        return false;
+    if (!this->discard(RHS))
+        return false;
     return true;
+}
 
   PrimType ElemT;
   bool LHSIsComplex;
diff --git a/clang/test/AST/ByteCode/constant-eval-complex-discard.c 
b/clang/test/AST/ByteCode/constant-eval-complex-discard.c
deleted file mode 100644
index 1d111fc049cc1..0000000000000
--- a/clang/test/AST/ByteCode/constant-eval-complex-discard.c
+++ /dev/null
@@ -1,6 +0,0 @@
-// RUN: %clang_cc1 -std=c11 -fsyntax-only 
-fexperimental-new-constant-interpreter %s
-
-void foo(void) {
-  // Complex comparison evaluated in a discarded context.
-  (void)(0 && (1i == 1i));
-}
diff --git a/clang/test/AST/ByteCode/constant-eval-complex-discard.cpp 
b/clang/test/AST/ByteCode/constant-eval-complex-discard.cpp
new file mode 100644
index 0000000000000..6c2cf5739ba13
--- /dev/null
+++ b/clang/test/AST/ByteCode/constant-eval-complex-discard.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify 
-fexperimental-new-constant-interpreter %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// expected-no-diagnostics   
+
+void test_no_crash() {
+  _Complex int x = 1i;
+  (void)(x == 1i);
+}
+
+constexpr int test_side_effect() {
+  int k = 0;
+  (void)(1i == (++k, 1i));
+  return k;
+}
+static_assert(test_side_effect() == 1);
\ No newline at end of file

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to