Fix PR9253, allowing attribute(aligned) to reduce the alignment of

a typedef.

llvm-svn: 126059
This commit is contained in:
Chris Lattner 2011-02-19 22:55:41 +00:00
parent ef200db4fd
commit 29eb47bd68
2 changed files with 22 additions and 1 deletions

View File

@ -882,7 +882,13 @@ ASTContext::getTypeInfo(const Type *T) const {
const TypedefDecl *Typedef = cast<TypedefType>(T)->getDecl(); const TypedefDecl *Typedef = cast<TypedefType>(T)->getDecl();
std::pair<uint64_t, unsigned> Info std::pair<uint64_t, unsigned> Info
= getTypeInfo(Typedef->getUnderlyingType().getTypePtr()); = getTypeInfo(Typedef->getUnderlyingType().getTypePtr());
Align = std::max(Typedef->getMaxAlignment(), Info.second); // If the typedef has an aligned attribute on it, it overrides any computed
// alignment we have. This violates the GCC documentation (which says that
// attribute(aligned) can only round up) but matches its implementation.
if (unsigned AttrAlign = Typedef->getMaxAlignment())
Align = AttrAlign;
else
Align = Info.second;
Width = Info.first; Width = Info.first;
break; break;
} }

View File

@ -117,3 +117,18 @@ struct packed_fas2 {
extern int m1[sizeof(struct packed_fas2) == 1 ? 1 : -1]; extern int m1[sizeof(struct packed_fas2) == 1 ? 1 : -1];
extern int m2[__alignof(struct packed_fas2) == 1 ? 1 : -1]; extern int m2[__alignof(struct packed_fas2) == 1 ? 1 : -1];
// Attribute aligned can round down typedefs. PR9253
typedef long long __attribute__((aligned(1))) nt;
struct nS {
char buf_nr;
nt start_lba;
};
extern int n1[sizeof(struct nS) == 9 ? 1 : -1];
extern int n2[__alignof(struct nS) == 1 ? 1 : -1];