[llvm] ed9df86 - [FileCheck] Implement equality operators for ExpressionValue.
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 4 04:19:49 PDT 2020
Author: Paul Walker
Date: 2020-06-04T11:18:35Z
New Revision: ed9df8621a85329d9cb607e982a6efb2d9c670f5
URL: https://github.com/llvm/llvm-project/commit/ed9df8621a85329d9cb607e982a6efb2d9c670f5
DIFF: https://github.com/llvm/llvm-project/commit/ed9df8621a85329d9cb607e982a6efb2d9c670f5.diff
LOG: [FileCheck] Implement equality operators for ExpressionValue.
Subscribers: hiraditya, thopre, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D81094
Added:
Modified:
llvm/lib/Support/FileCheckImpl.h
llvm/unittests/Support/FileCheckTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/FileCheckImpl.h b/llvm/lib/Support/FileCheckImpl.h
index 068de3da1c69..6998df3d6d8d 100644
--- a/llvm/lib/Support/FileCheckImpl.h
+++ b/llvm/lib/Support/FileCheckImpl.h
@@ -64,8 +64,8 @@ struct ExpressionFormat {
return Value != Kind::NoFormat && Value == Other.Value;
}
- bool operator!=(const ExpressionFormat &other) const {
- return !(*this == other);
+ bool operator!=(const ExpressionFormat &Other) const {
+ return !(*this == Other);
}
bool operator==(Kind OtherValue) const { return Value == OtherValue; }
@@ -119,8 +119,19 @@ class ExpressionValue {
template <class T>
explicit ExpressionValue(T Val) : Value(Val), Negative(Val < 0) {}
+ bool operator==(const ExpressionValue &Other) const {
+ return Value == Other.Value && isNegative() == Other.isNegative();
+ }
+
+ bool operator!=(const ExpressionValue &Other) const {
+ return !(*this == Other);
+ }
+
/// Returns true if value is signed and negative, false otherwise.
- bool isNegative() const { return Negative; }
+ bool isNegative() const {
+ assert((Value != 0 || !Negative) && "Unexpected negative zero!");
+ return Negative;
+ }
/// \returns the value as a signed integer or an error if the value is out of
/// range.
diff --git a/llvm/unittests/Support/FileCheckTest.cpp b/llvm/unittests/Support/FileCheckTest.cpp
index 54646a036f73..c549991d6619 100644
--- a/llvm/unittests/Support/FileCheckTest.cpp
+++ b/llvm/unittests/Support/FileCheckTest.cpp
@@ -478,6 +478,46 @@ TEST_F(FileCheckTest, ExpressionValueSubtraction) {
expectOperationValueResult(operator-, 10, 11, -1);
}
+TEST_F(FileCheckTest, ExpressionValueEquality) {
+ // Test negative and positive value.
+ EXPECT_FALSE(ExpressionValue(5) == ExpressionValue(-3));
+ EXPECT_TRUE(ExpressionValue(5) != ExpressionValue(-3));
+ EXPECT_FALSE(ExpressionValue(-2) == ExpressionValue(6));
+ EXPECT_TRUE(ExpressionValue(-2) != ExpressionValue(6));
+ EXPECT_FALSE(ExpressionValue(-7) == ExpressionValue(7));
+ EXPECT_TRUE(ExpressionValue(-7) != ExpressionValue(7));
+ EXPECT_FALSE(ExpressionValue(4) == ExpressionValue(-4));
+ EXPECT_TRUE(ExpressionValue(4) != ExpressionValue(-4));
+ EXPECT_FALSE(ExpressionValue(MaxUint64) == ExpressionValue(-1));
+ EXPECT_TRUE(ExpressionValue(MaxUint64) != ExpressionValue(-1));
+
+ // Test both negative values.
+ EXPECT_FALSE(ExpressionValue(-2) == ExpressionValue(-7));
+ EXPECT_TRUE(ExpressionValue(-2) != ExpressionValue(-7));
+ EXPECT_TRUE(ExpressionValue(-3) == ExpressionValue(-3));
+ EXPECT_FALSE(ExpressionValue(-3) != ExpressionValue(-3));
+ EXPECT_FALSE(ExpressionValue(MinInt64) == ExpressionValue(-1));
+ EXPECT_TRUE(ExpressionValue(MinInt64) != ExpressionValue(-1));
+ EXPECT_FALSE(ExpressionValue(MinInt64) == ExpressionValue(-0));
+ EXPECT_TRUE(ExpressionValue(MinInt64) != ExpressionValue(-0));
+
+ // Test both positive values.
+ EXPECT_FALSE(ExpressionValue(8) == ExpressionValue(9));
+ EXPECT_TRUE(ExpressionValue(8) != ExpressionValue(9));
+ EXPECT_TRUE(ExpressionValue(1) == ExpressionValue(1));
+ EXPECT_FALSE(ExpressionValue(1) != ExpressionValue(1));
+
+ // Check the signedness of zero doesn't affect equality.
+ EXPECT_TRUE(ExpressionValue(0) == ExpressionValue(0));
+ EXPECT_FALSE(ExpressionValue(0) != ExpressionValue(0));
+ EXPECT_TRUE(ExpressionValue(0) == ExpressionValue(-0));
+ EXPECT_FALSE(ExpressionValue(0) != ExpressionValue(-0));
+ EXPECT_TRUE(ExpressionValue(-0) == ExpressionValue(0));
+ EXPECT_FALSE(ExpressionValue(-0) != ExpressionValue(0));
+ EXPECT_TRUE(ExpressionValue(-0) == ExpressionValue(-0));
+ EXPECT_FALSE(ExpressionValue(-0) != ExpressionValue(-0));
+}
+
TEST_F(FileCheckTest, Literal) {
SourceMgr SM;
More information about the llvm-commits
mailing list