[PATCH] D67697: [Alignment] Add a None() member function

Guillaume Chatelet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 18 01:48:52 PDT 2019


gchatelet created this revision.
gchatelet added a reviewer: courbet.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
courbet accepted this revision.
This revision is now accepted and ready to land.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67697

Files:
  llvm/include/llvm/Support/Alignment.h
  llvm/unittests/Support/AlignmentTest.cpp


Index: llvm/unittests/Support/AlignmentTest.cpp
===================================================================
--- llvm/unittests/Support/AlignmentTest.cpp
+++ llvm/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());
Index: llvm/include/llvm/Support/Alignment.h
===================================================================
--- llvm/include/llvm/Support/Alignment.h
+++ llvm/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,8 @@
   /// 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; }
+
+  constexpr static const Align None() { return llvm::Align(); }
 };
 
 /// Treats the value 0 as a 1, so Align is always at least 1.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67697.220621.patch
Type: text/x-patch
Size: 1357 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190918/cdc82e9e/attachment.bin>


More information about the llvm-commits mailing list