aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2013-03-07 21:37:02 +0000
committerJohn McCall <rjmccall@apple.com>2013-03-07 21:37:02 +0000
commit372fe788f8ea815071d0ddffe46dd3abc397106e (patch)
tree1fbfcf11e9c82b8742a549f57d0b66e9b9029586
parent1723f6398ea8aa8d602a478f47695bf3b0374d35 (diff)
Add CharUnits::alignmentAtOffset.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176655 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/AST/CharUnits.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/clang/AST/CharUnits.h b/include/clang/AST/CharUnits.h
index 12e74b32be..082c672c21 100644
--- a/include/clang/AST/CharUnits.h
+++ b/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