[PATCH] D68201: [Alignment][NFC] Adding a max function.
Guillaume Chatelet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 30 03:01:58 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373196: [Alignment][NFC] Adding a max function. (authored by gchatelet, committed by ).
Herald added a subscriber: kristina.
Changed prior to commit:
https://reviews.llvm.org/D68201?vs=222382&id=222383#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D68201/new/
https://reviews.llvm.org/D68201
Files:
llvm/trunk/include/llvm/Support/Alignment.h
llvm/trunk/unittests/Support/AlignmentTest.cpp
Index: llvm/trunk/unittests/Support/AlignmentTest.cpp
===================================================================
--- llvm/trunk/unittests/Support/AlignmentTest.cpp
+++ llvm/trunk/unittests/Support/AlignmentTest.cpp
@@ -227,6 +227,29 @@
}
}
+TEST(AlignmentTest, Max) {
+ // We introduce std::max here to test ADL.
+ using std::max;
+
+ // Uses llvm::max.
+ EXPECT_EQ(max(MaybeAlign(), Align(2)), Align(2));
+ EXPECT_EQ(max(Align(2), MaybeAlign()), Align(2));
+
+ EXPECT_EQ(max(MaybeAlign(1), Align(2)), Align(2));
+ EXPECT_EQ(max(Align(2), MaybeAlign(1)), Align(2));
+
+ EXPECT_EQ(max(MaybeAlign(2), Align(2)), Align(2));
+ EXPECT_EQ(max(Align(2), MaybeAlign(2)), Align(2));
+
+ EXPECT_EQ(max(MaybeAlign(4), Align(2)), Align(4));
+ EXPECT_EQ(max(Align(2), MaybeAlign(4)), Align(4));
+
+ // Uses std::max.
+ EXPECT_EQ(max(Align(2), Align(4)), Align(4));
+ EXPECT_EQ(max(MaybeAlign(2), MaybeAlign(4)), MaybeAlign(4));
+ EXPECT_EQ(max(MaybeAlign(), MaybeAlign()), MaybeAlign());
+}
+
TEST(AlignmentTest, AssumeAligned) {
EXPECT_EQ(assumeAligned(0), Align(1));
EXPECT_EQ(assumeAligned(0), Align());
Index: llvm/trunk/include/llvm/Support/Alignment.h
===================================================================
--- llvm/trunk/include/llvm/Support/Alignment.h
+++ llvm/trunk/include/llvm/Support/Alignment.h
@@ -333,6 +333,14 @@
return Lhs ? Lhs.getValue() / Divisor : MaybeAlign();
}
+inline Align max(MaybeAlign Lhs, Align Rhs) {
+ return Lhs && *Lhs > Rhs ? *Lhs : Rhs;
+}
+
+inline Align max(Align Lhs, MaybeAlign Rhs) {
+ return Rhs && *Rhs > Lhs ? *Rhs : Lhs;
+}
+
#undef ALIGN_CHECK_ISPOSITIVE
#undef ALIGN_CHECK_ISSET
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68201.222383.patch
Type: text/x-patch
Size: 1676 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190930/c051f878/attachment.bin>
More information about the llvm-commits
mailing list