__alignof__ operator, make sure to take into account the packed alignment
of the struct/union/class itself. Matches GCC's behavior and fixes PR6362.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96884
91177308-0d34-0410-b5e6-
96231b3b80d8
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());
_Complex double g3;
short chk1[__alignof__(g3) == 8 ? 1 : -1];
short chk2[__alignof__(_Complex double) == 8 ? 1 : -1];
+
+// PR6362
+struct __attribute__((packed)) {unsigned int a} g4;
+short chk1[__alignof__(g4) == 1 ? 1 : -1];
+short chk2[__alignof__(g4.a) == 1 ? 1 : -1];
+