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/ExprConstant.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/ExprConstant.cpp')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 6d1d150c1c..49cc3201db 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -508,8 +508,8 @@ public: private: bool HandleCast(CastExpr* E); - uint64_t GetAlignOfExpr(const Expr *E); - uint64_t GetAlignOfType(QualType T); + unsigned GetAlignOfExpr(const Expr *E); + unsigned GetAlignOfType(QualType T); }; } // end anonymous namespace @@ -844,7 +844,7 @@ bool IntExprEvaluator::VisitConditionalOperator(const ConditionalOperator *E) { return Visit(Cond ? E->getTrueExpr() : E->getFalseExpr()); } -uint64_t IntExprEvaluator::GetAlignOfType(QualType T) { +unsigned IntExprEvaluator::GetAlignOfType(QualType T) { const Type *Ty = Info.Ctx.getCanonicalType(T).getTypePtr(); // __alignof__(void) = 1 as a gcc extension. @@ -873,8 +873,17 @@ uint64_t IntExprEvaluator::GetAlignOfType(QualType T) { return Info.Ctx.getTypeAlign(Ty) / CharSize; } -uint64_t IntExprEvaluator::GetAlignOfExpr(const Expr *E) { - +unsigned IntExprEvaluator::GetAlignOfExpr(const Expr *E) { + E = E->IgnoreParens(); + + // alignof decl is always accepted, even if it doesn't make sense: we default + // to 1 in those cases. + if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) + return Info.Ctx.getDeclAlign(DRE->getDecl()); + + if (const MemberExpr *ME = dyn_cast<MemberExpr>(E)) + return Info.Ctx.getDeclAlign(ME->getMemberDecl()); + return GetAlignOfType(E->getType()); } |