mirror of
https://github.com/RPCS3/llvm.git
synced 2025-05-13 08:56:04 +00:00
[Alignment] Add a None() member function
Summary: This will allow writing `if(A != llvm::Align::None())` which is clearer than `if(A > llvm::Align(1))` This is patch is part of a series to introduce an Alignment type. See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html See this patch for the introduction of the type: https://reviews.llvm.org/D64790 Reviewers: courbet Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67697 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372207 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1348de6c20
commit
b908f329d0
@ -55,7 +55,7 @@ private:
|
||||
|
||||
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 @@ public:
|
||||
/// 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.
|
||||
|
@ -28,7 +28,10 @@ std::vector<uint64_t> getValidAlignments() {
|
||||
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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user