Skip to content

Commit c75acb6

Browse files
authored
[clang][bytecode] Remove some unused code (#142580)
Remove unused functions and add tests for fixed-point to bool casts, which work.
1 parent e97f42e commit c75acb6

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

clang/lib/AST/ByteCode/Boolean.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,10 @@ class Boolean final {
3030
public:
3131
/// Zero-initializes a boolean.
3232
Boolean() : V(false) {}
33-
Boolean(const llvm::APSInt &I) : V(!I.isZero()) {}
3433
explicit Boolean(bool V) : V(V) {}
3534

3635
bool operator<(Boolean RHS) const { return V < RHS.V; }
3736
bool operator>(Boolean RHS) const { return V > RHS.V; }
38-
bool operator<=(Boolean RHS) const { return V <= RHS.V; }
39-
bool operator>=(Boolean RHS) const { return V >= RHS.V; }
40-
bool operator==(Boolean RHS) const { return V == RHS.V; }
41-
bool operator!=(Boolean RHS) const { return V != RHS.V; }
42-
4337
bool operator>(unsigned RHS) const { return static_cast<unsigned>(V) > RHS; }
4438

4539
Boolean operator-() const { return Boolean(V); }

clang/lib/AST/ByteCode/Floating.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class Floating final {
8787

8888
bool isSigned() const { return true; }
8989
bool isNegative() const { return F.isNegative(); }
90-
bool isPositive() const { return !F.isNegative(); }
9190
bool isZero() const { return F.isZero(); }
9291
bool isNonZero() const { return F.isNonZero(); }
9392
bool isMin() const { return F.isSmallest(); }

clang/lib/AST/ByteCode/Opcodes.td

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def FixedSizeIntegralTypeClass : TypeClass {
9393
Uint32, Sint64, Uint64, Bool];
9494
}
9595

96+
def FixedSizeIntegralNoBoolTypeClass : TypeClass {
97+
let Types = [Sint8, Uint8, Sint16, Uint16, Sint32, Uint32, Sint64, Uint64];
98+
}
99+
96100
def NumberTypeClass : TypeClass {
97101
let Types = !listconcat(IntegerTypeClass.Types, [Float]);
98102
}
@@ -650,10 +654,6 @@ def CastFixedPoint : Opcode {
650654
let Args = [ArgUint32];
651655
}
652656

653-
def FixedSizeIntegralTypes : TypeClass {
654-
let Types = [Uint8, Sint8, Uint16, Sint16, Uint32, Sint32, Uint64, Sint64, Bool];
655-
}
656-
657657
def CastAP : Opcode {
658658
let Types = [AluTypeClass];
659659
let Args = [ArgUint32];
@@ -675,7 +675,7 @@ def CastIntegralFloating : Opcode {
675675

676676
// Cast a floating to an integer type
677677
def CastFloatingIntegral : Opcode {
678-
let Types = [FixedSizeIntegralTypes];
678+
let Types = [FixedSizeIntegralTypeClass];
679679
let Args = [ArgUint32];
680680
let HasGroup = 1;
681681
}
@@ -699,7 +699,7 @@ def CastPointerIntegralAPS : Opcode {
699699
let Args = [ArgUint32];
700700
}
701701
def CastIntegralFixedPoint : Opcode {
702-
let Types = [FixedSizeIntegralTypes];
702+
let Types = [FixedSizeIntegralTypeClass];
703703
let Args = [ArgUint32];
704704
let HasGroup = 1;
705705
}
@@ -710,7 +710,7 @@ def CastFixedPointFloating : Opcode {
710710
let Args = [ArgFltSemantics];
711711
}
712712
def CastFixedPointIntegral : Opcode {
713-
let Types = [FixedSizeIntegralTypes];
713+
let Types = [FixedSizeIntegralNoBoolTypeClass];
714714
let HasGroup = 1;
715715
}
716716
def ShiftFixedPoint : Opcode {

clang/lib/AST/ByteCode/Source.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ class CodePtr final {
4545
assert(Ptr != nullptr && "Invalid code pointer");
4646
return CodePtr(Ptr - RHS);
4747
}
48-
CodePtr operator+(ssize_t RHS) const {
49-
assert(Ptr != nullptr && "Invalid code pointer");
50-
return CodePtr(Ptr + RHS);
51-
}
5248

5349
bool operator!=(const CodePtr &RHS) const { return Ptr != RHS.Ptr; }
5450
const std::byte *operator*() const { return Ptr; }

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ constexpr _Accum acc = (0.5r, 6.9k);
1717
constexpr _Accum A{};
1818
static_assert(A == 0.0k);
1919
static_assert(A == 0);
20+
static_assert(!A);
21+
22+
constexpr bool toBool() {
23+
if (A)
24+
return true;
25+
return false;
26+
}
27+
static_assert(!toBool());
2028

2129
namespace IntToFixedPointCast {
2230
constexpr _Accum B = 13;

0 commit comments

Comments
 (0)