[clang] 24e4414 - [clang][bytecode] Fix DiscardResult handling in fixed-point operations (#195013)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 30 00:08:22 PDT 2026
Author: Timm Baeder
Date: 2026-04-30T09:08:17+02:00
New Revision: 24e441428090d81ba8d9d163b65949d43f90e591
URL: https://github.com/llvm/llvm-project/commit/24e441428090d81ba8d9d163b65949d43f90e591
DIFF: https://github.com/llvm/llvm-project/commit/24e441428090d81ba8d9d163b65949d43f90e591.diff
LOG: [clang][bytecode] Fix DiscardResult handling in fixed-point operations (#195013)
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/fixed-point.cpp
Removed:
################################################################################
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