[clang] [clang][bytecode] Fix DiscardResult handling in fixed-point operations (PR #195013)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 29 23:25:26 PDT 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/195013
None
>From 751656f0a10de6d0d892f53a5bd83e9377c34cc2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Thu, 30 Apr 2026 08:24:37 +0200
Subject: [PATCH] [clang][bytecode] Fix DiscardResult handling in fixed-point
operations
---
clang/lib/AST/ByteCode/Compiler.cpp | 39 ++++++++++++++++++++-----
clang/test/AST/ByteCode/fixed-point.cpp | 1 +
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 349bbed6830ba..626068ce9eee5 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -773,8 +773,12 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *E) {
auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->getType()).toOpaqueInt();
- return this->emitCastIntegralFixedPoint(classifyPrim(SubExpr->getType()),
- Sem, E);
+ if (!this->emitCastIntegralFixedPoint(classifyPrim(SubExpr->getType()), Sem,
+ E))
+ return false;
+ if (DiscardResult)
+ return this->emitPopFixedPoint(E);
+ return true;
}
case CK_FloatingToFixedPoint: {
if (!this->visit(SubExpr))
@@ -782,25 +786,42 @@ bool Compiler<Emitter>::VisitCastExpr(const CastExpr *E) {
auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->getType()).toOpaqueInt();
- return this->emitCastFloatingFixedPoint(Sem, E);
+ if (!this->emitCastFloatingFixedPoint(Sem, E))
+ return false;
+ if (DiscardResult)
+ return this->emitPopFixedPoint(E);
+ return true;
}
case CK_FixedPointToFloating: {
if (!this->visit(SubExpr))
return false;
const auto *TargetSemantics = &Ctx.getFloatSemantics(E->getType());
- return this->emitCastFixedPointFloating(TargetSemantics, E);
+ if (!this->emitCastFixedPointFloating(TargetSemantics, E))
+ return false;
+ if (DiscardResult)
+ return this->emitPopFloat(E);
+ return true;
}
case CK_FixedPointToIntegral: {
if (!this->visit(SubExpr))
return false;
- return this->emitCastFixedPointIntegral(classifyPrim(E->getType()), E);
+ PrimType IntegralT = classifyPrim(E->getType());
+ if (!this->emitCastFixedPointIntegral(IntegralT, E))
+ return false;
+ if (DiscardResult)
+ return this->emitPop(IntegralT, E);
+ return true;
}
case CK_FixedPointCast: {
if (!this->visit(SubExpr))
return false;
auto Sem =
Ctx.getASTContext().getFixedPointSemantics(E->getType()).toOpaqueInt();
- return this->emitCastFixedPoint(Sem, E);
+ if (!this->emitCastFixedPoint(Sem, E))
+ return false;
+ if (DiscardResult)
+ return this->emitPopFixedPoint(E);
+ return true;
}
case CK_ToVoid:
@@ -1902,7 +1923,11 @@ bool Compiler<Emitter>::VisitFixedPointUnaryOperator(const UnaryOperator *E) {
case UO_Minus:
if (!this->visit(SubExpr))
return false;
- return this->emitNegFixedPoint(E);
+ if (!this->emitNegFixedPoint(E))
+ return false;
+ if (DiscardResult)
+ return this->emitPopFixedPoint(E);
+ return true;
default:
return false;
}
diff --git a/clang/test/AST/ByteCode/fixed-point.cpp b/clang/test/AST/ByteCode/fixed-point.cpp
index 5237d758fa257..c8baa1972536a 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -12,6 +12,7 @@ static_assert(1.0k != 1); // both-error {{failed due to requirement '1.0k != 1'}
static_assert(-12.0k == -(-(-12.0k)));
constexpr _Accum acc = (0.5r, 6.9k);
+constexpr _Accum acc2 = (-1e+00r, 2.3);
/// Zero-init.
constexpr _Accum A{};
More information about the cfe-commits
mailing list