[clang] [clang][bytecode] Remove an incorrect assertion (PR #179644)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 4 03:47:31 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/179644.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (-2)
- (modified) clang/test/AST/ByteCode/complex.cpp (+6-1)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/179644
More information about the cfe-commits
mailing list