diff options
author | John McCall <rjmccall@apple.com> | 2011-01-20 07:57:12 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-01-20 07:57:12 +0000 |
commit | ba4f5d5754c8291690d01ca9581926673d69b24c (patch) | |
tree | ba5c8463382801f9f2f55641e03278da8c565d69 /lib/AST/Decl.cpp | |
parent | 9eefa229dfb71400a6bbee326420a7f0e2e91f1f (diff) |
Fix the computation of alignment for fields of packed+aligned structs.
Part of the fix for PR8413.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123904 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r-- | lib/AST/Decl.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 9e2e8763f8..b1da849ae1 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -1881,6 +1881,25 @@ bool FieldDecl::isAnonymousStructOrUnion() const { return false; } +unsigned FieldDecl::getFieldIndex() const { + if (CachedFieldIndex) return CachedFieldIndex - 1; + + unsigned index = 0; + RecordDecl::field_iterator + i = getParent()->field_begin(), e = getParent()->field_end(); + while (true) { + assert(i != e && "failed to find field in parent!"); + if (*i == this) + break; + + ++i; + ++index; + } + + CachedFieldIndex = index + 1; + return index; +} + //===----------------------------------------------------------------------===// // TagDecl Implementation //===----------------------------------------------------------------------===// |