[clang][bytecode] Remove some unused code (#142580)
Remove unused functions and add tests for fixed-point to bool casts,
which work.
diff --git a/clang/lib/AST/ByteCode/Boolean.h b/clang/lib/AST/ByteCode/Boolean.h
index 8380e85..fd8d546 100644
--- a/clang/lib/AST/ByteCode/Boolean.h
+++ b/clang/lib/AST/ByteCode/Boolean.h
@@ -30,16 +30,10 @@
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 3a874fc..3750568 100644
--- a/clang/lib/AST/ByteCode/Floating.h
+++ b/clang/lib/AST/ByteCode/Floating.h
@@ -87,7 +87,6 @@
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 7031d70..c76ac5f 100644
--- a/clang/lib/AST/ByteCode/Opcodes.td
+++ b/clang/lib/AST/ByteCode/Opcodes.td
@@ -93,6 +93,10 @@
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 @@
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 @@
// 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 @@
let Args = [ArgUint32];
}
def CastIntegralFixedPoint : Opcode {
- let Types = [FixedSizeIntegralTypes];
+ let Types = [FixedSizeIntegralTypeClass];
let Args = [ArgUint32];
let HasGroup = 1;
}
@@ -710,7 +710,7 @@
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 c74cda9..d5d294e 100644
--- a/clang/lib/AST/ByteCode/Source.h
+++ b/clang/lib/AST/ByteCode/Source.h
@@ -45,10 +45,6 @@
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 4bf80ba..5237d75 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -17,6 +17,14 @@
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;