[PATCH] D81094: [FileCheck] Implement equality operators for ExpressionValue.
Paul Walker via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 3 09:53:23 PDT 2020
paulwalker-arm updated this revision to Diff 268240.
paulwalker-arm added a comment.
Added tests to protect against unintentional casts and mismatched binary encodings.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D81094/new/
https://reviews.llvm.org/D81094
Files:
llvm/lib/Support/FileCheckImpl.h
llvm/unittests/Support/FileCheckTest.cpp
Index: llvm/unittests/Support/FileCheckTest.cpp
===================================================================
--- llvm/unittests/Support/FileCheckTest.cpp
+++ llvm/unittests/Support/FileCheckTest.cpp
@@ -478,6 +478,46 @@
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;
Index: llvm/lib/Support/FileCheckImpl.h
===================================================================
--- llvm/lib/Support/FileCheckImpl.h
+++ llvm/lib/Support/FileCheckImpl.h
@@ -64,8 +64,8 @@
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 @@
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D81094.268240.patch
Type: text/x-patch
Size: 3610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200603/f405bb9f/attachment.bin>
More information about the llvm-commits
mailing list