diff options
| author | Charles Davis <cdavis@mines.edu> | 2010-02-23 04:52:00 +0000 |
|---|---|---|
| committer | Charles Davis <cdavis@mines.edu> | 2010-02-23 04:52:00 +0000 |
| commit | 3fc5107cd9ec7722140b98132f56c19c33824797 (patch) | |
| tree | 5378a33e76746d6e31947aa1b4ae91e12f881f7f /clang/lib/AST/ASTContext.cpp | |
| parent | a8796c692c7c4e49768466b6918084ceb1c3675e (diff) | |
| download | bcm5719-llvm-3fc5107cd9ec7722140b98132f56c19c33824797.tar.gz bcm5719-llvm-3fc5107cd9ec7722140b98132f56c19c33824797.zip | |
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.
llvm-svn: 96884
Diffstat (limited to 'clang/lib/AST/ASTContext.cpp')
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index c8caeb62b31..202e3370b67 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/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()); |

