[clang] [clang][bytecode] Implement zero-init for fixed point types (PR #110257)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 27 05:52:06 PDT 2024
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/110257
None
>From 7f5e19784e83f28f54191377cf7b476e93453753 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 27 Sep 2024 14:51:12 +0200
Subject: [PATCH] [clang][bytecode] Implement zero-init for fixed point types
---
clang/lib/AST/ByteCode/Compiler.cpp | 5 ++++-
clang/lib/AST/ByteCode/FixedPoint.h | 4 ++++
clang/test/AST/ByteCode/fixed-point.cpp | 3 +++
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 78ba1a7eec6620..2520fe30547b23 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -3699,7 +3699,10 @@ bool Compiler<Emitter>::visitZeroInitializer(PrimType T, QualType QT,
return this->emitNullMemberPtr(nullptr, E);
case PT_Float:
return this->emitConstFloat(APFloat::getZero(Ctx.getFloatSemantics(QT)), E);
- case PT_FixedPoint:
+ case PT_FixedPoint: {
+ auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->getType());
+ return this->emitConstFixedPoint(FixedPoint::Zero(Sem), E);
+ }
llvm_unreachable("Implement");
}
llvm_unreachable("unknown primitive type");
diff --git a/clang/lib/AST/ByteCode/FixedPoint.h b/clang/lib/AST/ByteCode/FixedPoint.h
index fba793cd59e7e1..9dd300c3dbf6df 100644
--- a/clang/lib/AST/ByteCode/FixedPoint.h
+++ b/clang/lib/AST/ByteCode/FixedPoint.h
@@ -32,6 +32,10 @@ class FixedPoint final {
: V(APInt(0, 0ULL, false),
llvm::FixedPointSemantics(0, 0, false, false, false)) {}
+ static FixedPoint Zero(llvm::FixedPointSemantics Sem) {
+ return FixedPoint(APInt(Sem.getWidth(), 0ULL, Sem.isSigned()), Sem);
+ }
+
operator bool() const { return V.getBoolValue(); }
template <typename Ty, typename = std::enable_if_t<std::is_integral_v<Ty>>>
explicit operator Ty() const {
diff --git a/clang/test/AST/ByteCode/fixed-point.cpp b/clang/test/AST/ByteCode/fixed-point.cpp
index 42ebdf64e1a9fe..bf1bd41783448f 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -9,3 +9,6 @@ static_assert(1.0k == 1.0k);
static_assert(1.0k != 1.0k); // both-error {{failed due to requirement '1.0k != 1.0k'}}
static_assert(-12.0k == -(-(-12.0k)));
+/// Zero-init.
+constexpr _Accum A{};
+static_assert(A == 0.0k);
More information about the cfe-commits
mailing list