r176655 - Add CharUnits::alignmentAtOffset.

John McCall rjmccall at apple.com
Thu Mar 7 13:37:02 PST 2013


Author: rjmccall
Date: Thu Mar  7 15:37:02 2013
New Revision: 176655

URL: http://llvm.org/viewvc/llvm-project?rev=176655&view=rev
Log:
Add CharUnits::alignmentAtOffset.

Modified:
    cfe/trunk/include/clang/AST/CharUnits.h

Modified: cfe/trunk/include/clang/AST/CharUnits.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/CharUnits.h?rev=176655&r1=176654&r2=176655&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/CharUnits.h (original)
+++ cfe/trunk/include/clang/AST/CharUnits.h Thu Mar  7 15:37:02 2013
@@ -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





More information about the cfe-commits mailing list