[clang] [clang][bytecode] Remove an incorrect assertion (PR #179644)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 4 03:46:56 PST 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/179644
There are situations where DiscardResult is set, but we still wish to emit a float value, e.g. when we will discard the result of an operation involving such a float value.
>From 41b99cbf97b9776d13ed755a8cceafbf92038fd7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Wed, 4 Feb 2026 12:44:54 +0100
Subject: [PATCH] [clang][bytecode] Remove an incorrect assertion
There are situations where DiscardResult is set, but we still wish to
emit a float value, e.g. when we will discard the result of an operation
involving such a float value.
---
clang/lib/AST/ByteCode/Compiler.cpp | 2 --
clang/test/AST/ByteCode/complex.cpp | 7 ++++++-
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index af076f90733df..43b4af4e4f33a 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -7580,8 +7580,6 @@ bool Compiler<Emitter>::emitDummyPtr(const DeclTy &D, const Expr *E) {
template <class Emitter>
bool Compiler<Emitter>::emitFloat(const APFloat &F, const Expr *E) {
- assert(!DiscardResult && "Should've been checked before");
-
if (Floating::singleWord(F.getSemantics()))
return this->emitConstFloat(Floating(F), E);
diff --git a/clang/test/AST/ByteCode/complex.cpp b/clang/test/AST/ByteCode/complex.cpp
index 9bf000d65466c..68a8e78d5b25b 100644
--- a/clang/test/AST/ByteCode/complex.cpp
+++ b/clang/test/AST/ByteCode/complex.cpp
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -verify=both,expected -Wno-unused-value %s
-// RUN: %clang_cc1 -verify=both,ref -Wno-unused-value %s
+// RUN: %clang_cc1 -verify=both,ref -Wno-unused-value %s
constexpr _Complex double z1 = {1.0, 2.0};
static_assert(__real(z1) == 1.0, "");
@@ -131,6 +131,11 @@ static_assert(ignored() == 0, "");
static_assert((int)I1 == 1, "");
static_assert((float)D == 1.0f, "");
+
+void ignoredEmitFloat() {
+ (1.f / (2.f + 3i), 4.f);
+}
+
static_assert(__real((_Complex unsigned)5) == 5);
static_assert(__imag((_Complex unsigned)5) == 0);
More information about the cfe-commits
mailing list