diff options
author | Chris Lattner <sabre@nondot.org> | 2009-01-24 21:53:27 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-01-24 21:53:27 +0000 |
commit | af707ab8fbb9451e8febb8d766f6c043628125c4 (patch) | |
tree | fabcc17e795c47c3e68c1dc2e5d34b1b610be7a9 /lib/AST/ASTContext.cpp | |
parent | b9037594f5e02f66c4fa697d9dec2359faba1bc3 (diff) |
add initial support for the gcc "alignof(decl) is the alignment of the decl
not the type" semantics. This can definitely be improved, but is better than
what we had.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62939 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/ASTContext.cpp')
-rw-r--r-- | lib/AST/ASTContext.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index f3243c25ae..63e4ccc241 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -260,6 +260,26 @@ const llvm::fltSemantics &ASTContext::getFloatTypeSemantics(QualType T) const { } } +/// getDeclAlign - Return a conservative estimate of the alignment of the +/// specified decl. Note that bitfields do not have a valid alignment, so +/// this method will assert on them. +unsigned ASTContext::getDeclAlign(const Decl *D) { + // FIXME: If attribute(align) is specified on the decl, round up to it. + + if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) { + QualType T = VD->getType(); + // Incomplete or function types default to 1. + if (T->isIncompleteType() || T->isFunctionType()) + return 1; + + while (isa<VariableArrayType>(T) || isa<IncompleteArrayType>(T)) + T = cast<ArrayType>(T)->getElementType(); + + return getTypeAlign(T); + } + + return 1; +} /// getTypeSize - Return the size of the specified type, in bits. This method /// does not work on incomplete types. |