Skip to content

Commit ff466ce

Browse files
tbaederrSterling-Augustine
authored andcommitted
[clang][bytecode] Implement zero-init for fixed point types (llvm#110257)
1 parent 0a81ecd commit ff466ce

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3699,7 +3699,10 @@ bool Compiler<Emitter>::visitZeroInitializer(PrimType T, QualType QT,
36993699
return this->emitNullMemberPtr(nullptr, E);
37003700
case PT_Float:
37013701
return this->emitConstFloat(APFloat::getZero(Ctx.getFloatSemantics(QT)), E);
3702-
case PT_FixedPoint:
3702+
case PT_FixedPoint: {
3703+
auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->getType());
3704+
return this->emitConstFixedPoint(FixedPoint::Zero(Sem), E);
3705+
}
37033706
llvm_unreachable("Implement");
37043707
}
37053708
llvm_unreachable("unknown primitive type");

clang/lib/AST/ByteCode/FixedPoint.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ class FixedPoint final {
3232
: V(APInt(0, 0ULL, false),
3333
llvm::FixedPointSemantics(0, 0, false, false, false)) {}
3434

35+
static FixedPoint Zero(llvm::FixedPointSemantics Sem) {
36+
return FixedPoint(APInt(Sem.getWidth(), 0ULL, Sem.isSigned()), Sem);
37+
}
38+
3539
operator bool() const { return V.getBoolValue(); }
3640
template <typename Ty, typename = std::enable_if_t<std::is_integral_v<Ty>>>
3741
explicit operator Ty() const {

clang/test/AST/ByteCode/fixed-point.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ static_assert(1.0k == 1.0k);
99
static_assert(1.0k != 1.0k); // both-error {{failed due to requirement '1.0k != 1.0k'}}
1010
static_assert(-12.0k == -(-(-12.0k)));
1111

12+
/// Zero-init.
13+
constexpr _Accum A{};
14+
static_assert(A == 0.0k);

0 commit comments

Comments
 (0)