-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attributes before declarations applied incorrectly. #367
Comments
$ arocc a.c --verbose-ast --target=x86_64-windows-msvc
struct_decl_two: 'struct (anonymous struct at a.c:1:30)'
record_field_decl: 'int'
name: a
typedef: 'attributed(struct (anonymous struct at a.c:1:30))'
attr: aligned alignment: Attribute.Alignment{ .node = Tree.NodeIndex.none, .requested = 2 }
name: X Looks fine to me? |
That would be it, the same happens if you put the __attribute__((aligned(2))) typedef struct { int a; } X; |
__declspec
?
So for GCC/Clang it looks like if the attribute is before the typedef, it's applied to the type, if it's after then it's a requested attribute to the struct, and the layout logic decides what to do with it : __attribute__((aligned(2))) typedef struct {
int a;
} X;
typedef struct {
int a;
} __attribute__((aligned(2))) Y;
_Static_assert(sizeof(X) == 4, "");
_Static_assert(_Alignof(X) == 2, "");
_Static_assert(sizeof(Y) == 4, "");
_Static_assert(_Alignof(Y) == 4, ""); For MSVC, it seems like either before, or after, it's applied to the struct and the layout code decides what to do with it: __declspec(align(2)) typedef struct {
int a;
} X;
typedef struct {
int a;
} __declspec(align(2)) Y;
_Static_assert(sizeof(X) == 4, "");
_Static_assert(_Alignof(X) == 4, "");
_Static_assert(sizeof(Y) == 4, "");
_Static_assert(_Alignof(Y) == 4, ""); |
for the following struct
ty.requestedAlignment()
returns null.The text was updated successfully, but these errors were encountered: