Properly compute the alignment of typedefs that make use of the
"aligned" attribute. Previously, we were skipping over these
attributes when we jumped directly to the canonical type. Now,
ASTContext::getTypeInfo walks through typedefs and other
"non-canonical" types manually, looking for "aligned" attributes on
typedefs.
As part of this change, I moved the GNU-specific logic (such as
determining the alignment of void or of a function pointer) out of the
expression evaluator and into ASTContext::getTypeInfo.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70497 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index fce5913..5d92e99 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -1021,32 +1021,11 @@
}
unsigned IntExprEvaluator::GetAlignOfType(QualType T) {
- const Type *Ty = Info.Ctx.getCanonicalType(T).getTypePtr();
-
- // __alignof__(void) = 1 as a gcc extension.
- if (Ty->isVoidType())
- return 1;
-
- // GCC extension: alignof(function) = 4.
- // FIXME: AlignOf shouldn't be unconditionally 4! It should listen to the
- // attribute(align) directive.
- if (Ty->isFunctionType())
- return 4;
-
- if (const ExtQualType *EXTQT = dyn_cast<ExtQualType>(Ty))
- return GetAlignOfType(QualType(EXTQT->getBaseType(), 0));
-
- // alignof VLA/incomplete array.
- if (const ArrayType *VAT = dyn_cast<ArrayType>(Ty))
- return GetAlignOfType(VAT->getElementType());
-
- // sizeof (objc class)?
- if (isa<ObjCInterfaceType>(Ty))
- return 1; // FIXME: This probably isn't right.
-
// Get information about the alignment.
unsigned CharSize = Info.Ctx.Target.getCharWidth();
- return Info.Ctx.getPreferredTypeAlign(Ty) / CharSize;
+
+ // FIXME: Why do we ask for the preferred alignment?
+ return Info.Ctx.getPreferredTypeAlign(T.getTypePtr()) / CharSize;
}
unsigned IntExprEvaluator::GetAlignOfExpr(const Expr *E) {