From b1b5d0b1e817219d40617cd3b9e63b17139c2c68 Mon Sep 17 00:00:00 2001 From: John McCall Date: Thu, 7 Mar 2013 21:37:02 +0000 Subject: [PATCH] Add CharUnits::alignmentAtOffset. llvm-svn: 176655 --- clang/include/clang/AST/CharUnits.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/clang/include/clang/AST/CharUnits.h b/clang/include/clang/AST/CharUnits.h index 12e74b3..082c672 100644 --- a/clang/include/clang/AST/CharUnits.h +++ b/clang/include/clang/AST/CharUnits.h @@ -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 -- 2.7.4