]> granicus.if.org Git - clang/commitdiff
Add CharUnits::alignmentAtOffset.
authorJohn McCall <rjmccall@apple.com>
Thu, 7 Mar 2013 21:37:02 +0000 (21:37 +0000)
committerJohn McCall <rjmccall@apple.com>
Thu, 7 Mar 2013 21:37:02 +0000 (21:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176655 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/CharUnits.h

index 12e74b32be8a85072e409f6820d917283bacbe29..082c672c21912ffe3a0c46aea1ceb68125e06985 100644 (file)
@@ -171,6 +171,17 @@ namespace clang {
                                                   Align.Quantity));
       }
 
+      /// Given that this is a non-zero alignment value, what is the
+      /// alignment at the given offset?
+      CharUnits alignmentAtOffset(CharUnits offset) {
+        // alignment: 0010000
+        // offset:    1011100
+        // lowBits:   0001011
+        // result:    0000100
+        QuantityType lowBits = (Quantity-1) & (offset.Quantity-1);
+        return CharUnits((lowBits + 1) & ~lowBits);
+      }
+
 
   }; // class CharUnit
 } // namespace clang