[clang] [clang][bytecode] Fix already initializing _Complex UO_Not (PR #181323)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 12 23:16:39 PST 2026


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

We'd accidentally leave the subexpr pointer on the stack.

>From 2f6eded087586ea66e88ec32cc06e0168570b2e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 13 Feb 2026 08:05:23 +0100
Subject: [PATCH] [clang][bytecode] Fix already initializing _Complex UO_Not

We'd accidentally leave the subexpr pointer on the stack.
---
 clang/lib/AST/ByteCode/Compiler.cpp | 4 ++--
 clang/test/AST/ByteCode/complex.cpp | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index dd10ad7d82653..16f339e4af816 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -6998,7 +6998,7 @@ bool Compiler<Emitter>::VisitComplexUnaryOperator(const UnaryOperator *E) {
   };
 
   switch (E->getOpcode()) {
-  case UO_Minus:
+  case UO_Minus: // -x
     if (!prepareResult())
       return false;
     if (!createTemp())
@@ -7047,7 +7047,7 @@ bool Compiler<Emitter>::VisitComplexUnaryOperator(const UnaryOperator *E) {
     return this->emitArrayElemPop(classifyPrim(E->getType()), 1, E);
 
   case UO_Not: // ~x
-    if (!this->visit(SubExpr))
+    if (!this->delegate(SubExpr))
       return false;
     // Negate the imaginary component.
     if (!this->emitArrayElem(ElemT, 1, E))
diff --git a/clang/test/AST/ByteCode/complex.cpp b/clang/test/AST/ByteCode/complex.cpp
index 783ea3f15de43..f0b86a968d492 100644
--- a/clang/test/AST/ByteCode/complex.cpp
+++ b/clang/test/AST/ByteCode/complex.cpp
@@ -162,6 +162,7 @@ static_assert(__real(Doubles[3]) == 0.0, "");
 static_assert(__imag(Doubles[3]) == 0.0, "");
 
 static_assert(~(0.5 + 1.5j) == (0.5 + -1.5j), "");
+int array[~(1i) == 2000.0];
 
 void func(void) {
   __complex__ int arr;



More information about the cfe-commits mailing list