[clang] [clang][bytecode] Implement zero-init for fixed point types (PR #110257)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 27 05:52:39 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/110257.diff
3 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+4-1)
- (modified) clang/lib/AST/ByteCode/FixedPoint.h (+4)
- (modified) clang/test/AST/ByteCode/fixed-point.cpp (+3)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/110257
More information about the cfe-commits
mailing list