[PATCH] MS ABI: Consider alignment attributes on typedefs for layout
Reid Kleckner
rnk at google.com
Tue Jul 29 16:00:52 PDT 2014
I'm skeptical that only one bit is enough information here...
================
Comment at: include/clang/AST/ASTContext.h:147
@@ +146,3 @@
+public:
+ struct TypeInfo {
+ uint64_t Width;
----------------
I'd rather just throw this in clang::. We can use it in record layout.
================
Comment at: include/clang/AST/ASTContext.h:1658-1663
@@ -1647,8 +1657,8 @@
/// bits.
unsigned getTypeAlign(QualType T) const {
- return getTypeInfo(T).second;
+ return getTypeInfo(T).Align;
}
unsigned getTypeAlign(const Type *T) const {
- return getTypeInfo(T).second;
+ return getTypeInfo(T).Align;
}
----------------
Grumble grumble these helpers are just asking you to do multiple hash table lookups.... Nothing to do here, though.
================
Comment at: test/Layout/ms-x86-pack-and-align.cpp:675
@@ -656,1 +674,3 @@
+// CHECK-NEXT: | [sizeof=16, align=8
+// CHECK-NEXT: | nvsize=12, nvalign=8]
----------------
Can you also add this test, just to satisfy my curiosity?
typedef int __declspec(align(2)) my_int_t;
#pragma pack(push, 1)
struct A {
char a;
my_int_t b;
};
#pragma pack(pop)
static_assert(sizeof(A) == 6, "");
I suspect because the required alignment is actually *lower* than the natural alignment of int, we will take the max alignment between the alignment attribute and the natural alignment get sizeof(A) == 8.
http://reviews.llvm.org/D4714
More information about the cfe-commits
mailing list