aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorCharles Davis <cdavis@mines.edu>2010-02-23 04:52:00 +0000
committerCharles Davis <cdavis@mines.edu>2010-02-23 04:52:00 +0000
commit05f62474dd2b0f1cb69adbe0787f2868788aa949 (patch)
tree871666d8384a86f6a30119c4ac87616fb2b9971e /lib
parent464c8f176b4590aa3cab643865ab985423063dd5 (diff)
When a reference to a field of a struct/union/class is passed to the
__alignof__ operator, make sure to take into account the packed alignment of the struct/union/class itself. Matches GCC's behavior and fixes PR6362. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96884 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/ASTContext.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index c8caeb62b3..202e3370b6 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -563,6 +563,12 @@ CharUnits ASTContext::getDeclAlign(const Decl *D, bool RefAsPointee) {
Align = std::max(Align, getPreferredTypeAlign(T.getTypePtr()));
}
+ if (const FieldDecl *FD = dyn_cast<FieldDecl>(VD)) {
+ // In the case of a field in a packed struct, we want the minimum
+ // of the alignment of the field and the alignment of the struct.
+ Align = std::min(Align,
+ getPreferredTypeAlign(FD->getParent()->getTypeForDecl()));
+ }
}
return CharUnits::fromQuantity(Align / Target.getCharWidth());