[PATCH] D67697: [Alignment] Add a None() member function
Guillaume Chatelet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 02:22:56 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL372207: [Alignment] Add a None() member function (authored by gchatelet, committed by ).
Herald added a subscriber: kristina.
Changed prior to commit:
https://reviews.llvm.org/D67697?vs=220630&id=220632#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D67697/new/
https://reviews.llvm.org/D67697
Files:
llvm/trunk/include/llvm/Support/Alignment.h
llvm/trunk/unittests/Support/AlignmentTest.cpp
Index: llvm/trunk/include/llvm/Support/Alignment.h
===================================================================
--- llvm/trunk/include/llvm/Support/Alignment.h
+++ llvm/trunk/include/llvm/Support/Alignment.h
@@ -55,7 +55,7 @@
public:
/// Default is byte-aligned.
- Align() = default;
+ constexpr Align() = default;
/// Do not perform checks in case of copy/move construct/assign, because the
/// checks have been performed when building `Other`.
Align(const Align &Other) = default;
@@ -73,6 +73,13 @@
/// This is a hole in the type system and should not be abused.
/// Needed to interact with C for instance.
uint64_t value() const { return uint64_t(1) << ShiftValue; }
+
+ /// Returns a default constructed Align which corresponds to no alignment.
+ /// This is useful to test for unalignment as it conveys clear semantic.
+ /// `if (A != llvm::Align::None())`
+ /// would be better than
+ /// `if (A > llvm::Align(1))`
+ constexpr static const Align None() { return llvm::Align(); }
};
/// Treats the value 0 as a 1, so Align is always at least 1.
Index: llvm/trunk/unittests/Support/AlignmentTest.cpp
===================================================================
--- llvm/trunk/unittests/Support/AlignmentTest.cpp
+++ llvm/trunk/unittests/Support/AlignmentTest.cpp
@@ -28,7 +28,10 @@
return Out;
}
-TEST(AlignmentTest, AlignDefaultCTor) { EXPECT_EQ(Align().value(), 1ULL); }
+TEST(AlignmentTest, AlignDefaultCTor) {
+ EXPECT_EQ(Align().value(), 1ULL);
+ EXPECT_EQ(Align::None().value(), 1ULL);
+}
TEST(AlignmentTest, MaybeAlignDefaultCTor) {
EXPECT_FALSE(MaybeAlign().hasValue());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67697.220632.patch
Type: text/x-patch
Size: 1648 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190918/3fe2fb06/attachment.bin>
More information about the llvm-commits
mailing list