llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> Remove unused functions and add tests for fixed-point to bool casts, which work. --- Full diff: https://github.com/llvm/llvm-project/pull/142580.diff 5 Files Affected: - (modified) clang/lib/AST/ByteCode/Boolean.h (-6) - (modified) clang/lib/AST/ByteCode/Floating.h (-1) - (modified) clang/lib/AST/ByteCode/Opcodes.td (+7-7) - (modified) clang/lib/AST/ByteCode/Source.h (-4) - (modified) clang/test/AST/ByteCode/fixed-point.cpp (+8) ``````````diff diff --git a/clang/lib/AST/ByteCode/Boolean.h b/clang/lib/AST/ByteCode/Boolean.h index 8380e85865ac5..fd8d546656881 100644 --- a/clang/lib/AST/ByteCode/Boolean.h +++ b/clang/lib/AST/ByteCode/Boolean.h @@ -30,16 +30,10 @@ class Boolean final { public: /// Zero-initializes a boolean. Boolean() : V(false) {} - Boolean(const llvm::APSInt &I) : V(!I.isZero()) {} explicit Boolean(bool V) : V(V) {} bool operator<(Boolean RHS) const { return V < RHS.V; } bool operator>(Boolean RHS) const { return V > RHS.V; } - bool operator<=(Boolean RHS) const { return V <= RHS.V; } - bool operator>=(Boolean RHS) const { return V >= RHS.V; } - bool operator==(Boolean RHS) const { return V == RHS.V; } - bool operator!=(Boolean RHS) const { return V != RHS.V; } - bool operator>(unsigned RHS) const { return static_cast<unsigned>(V) > RHS; } Boolean operator-() const { return Boolean(V); } diff --git a/clang/lib/AST/ByteCode/Floating.h b/clang/lib/AST/ByteCode/Floating.h index 3a874fc6f0b41..3750568fc23c7 100644 --- a/clang/lib/AST/ByteCode/Floating.h +++ b/clang/lib/AST/ByteCode/Floating.h @@ -87,7 +87,6 @@ class Floating final { bool isSigned() const { return true; } bool isNegative() const { return F.isNegative(); } - bool isPositive() const { return !F.isNegative(); } bool isZero() const { return F.isZero(); } bool isNonZero() const { return F.isNonZero(); } bool isMin() const { return F.isSmallest(); } diff --git a/clang/lib/AST/ByteCode/Opcodes.td b/clang/lib/AST/ByteCode/Opcodes.td index 7031d7026fac4..c76ac5f8ae868 100644 --- a/clang/lib/AST/ByteCode/Opcodes.td +++ b/clang/lib/AST/ByteCode/Opcodes.td @@ -93,6 +93,10 @@ def FixedSizeIntegralTypeClass : TypeClass { Uint32, Sint64, Uint64, Bool]; } +def FixedSizeIntegralNoBoolTypeClass : TypeClass { + let Types = [Sint8, Uint8, Sint16, Uint16, Sint32, Uint32, Sint64, Uint64]; +} + def NumberTypeClass : TypeClass { let Types = !listconcat(IntegerTypeClass.Types, [Float]); } @@ -650,10 +654,6 @@ def CastFixedPoint : Opcode { let Args = [ArgUint32]; } -def FixedSizeIntegralTypes : TypeClass { - let Types = [Uint8, Sint8, Uint16, Sint16, Uint32, Sint32, Uint64, Sint64, Bool]; -} - def CastAP : Opcode { let Types = [AluTypeClass]; let Args = [ArgUint32]; @@ -675,7 +675,7 @@ def CastIntegralFloating : Opcode { // Cast a floating to an integer type def CastFloatingIntegral : Opcode { - let Types = [FixedSizeIntegralTypes]; + let Types = [FixedSizeIntegralTypeClass]; let Args = [ArgUint32]; let HasGroup = 1; } @@ -699,7 +699,7 @@ def CastPointerIntegralAPS : Opcode { let Args = [ArgUint32]; } def CastIntegralFixedPoint : Opcode { - let Types = [FixedSizeIntegralTypes]; + let Types = [FixedSizeIntegralTypeClass]; let Args = [ArgUint32]; let HasGroup = 1; } @@ -710,7 +710,7 @@ def CastFixedPointFloating : Opcode { let Args = [ArgFltSemantics]; } def CastFixedPointIntegral : Opcode { - let Types = [FixedSizeIntegralTypes]; + let Types = [FixedSizeIntegralNoBoolTypeClass]; let HasGroup = 1; } def ShiftFixedPoint : Opcode { diff --git a/clang/lib/AST/ByteCode/Source.h b/clang/lib/AST/ByteCode/Source.h index c74cda919347c..d5d294e31d90c 100644 --- a/clang/lib/AST/ByteCode/Source.h +++ b/clang/lib/AST/ByteCode/Source.h @@ -45,10 +45,6 @@ class CodePtr final { assert(Ptr != nullptr && "Invalid code pointer"); return CodePtr(Ptr - RHS); } - CodePtr operator+(ssize_t RHS) const { - assert(Ptr != nullptr && "Invalid code pointer"); - return CodePtr(Ptr + RHS); - } bool operator!=(const CodePtr &RHS) const { return Ptr != RHS.Ptr; } const std::byte *operator*() const { return Ptr; } diff --git a/clang/test/AST/ByteCode/fixed-point.cpp b/clang/test/AST/ByteCode/fixed-point.cpp index 4bf80ba7c58f0..5237d758fa257 100644 --- a/clang/test/AST/ByteCode/fixed-point.cpp +++ b/clang/test/AST/ByteCode/fixed-point.cpp @@ -17,6 +17,14 @@ constexpr _Accum acc = (0.5r, 6.9k); constexpr _Accum A{}; static_assert(A == 0.0k); static_assert(A == 0); +static_assert(!A); + +constexpr bool toBool() { + if (A) + return true; + return false; +} +static_assert(!toBool()); namespace IntToFixedPointCast { constexpr _Accum B = 13; `````````` </details> https://github.com/llvm/llvm-project/pull/142580 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits