Skip to content

gcc/clang treat __attribute__((aligned())) differently #2376

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

Merged
merged 1 commit into from
Jun 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions regression/ansi-c/gcc_attributes5/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@

#ifdef __GNUC__

char __attribute__((aligned(8))) var1;
__attribute__((aligned(8))) char var2;
char var3 __attribute__((aligned(8)));
int (__attribute__((aligned(8))) var4);
int (__attribute__((aligned(8))) (var5));
int (__attribute__((aligned(8))) *var6);
int __attribute__((aligned(8))) *var7;
char __attribute__((aligned(16))) var1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand why various alignments are changed from 8 to 16? All I would have expected is the #ifdef __clang part below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason that the test has passed so far was a bit random: the default alignment of pointers on 64-bit machines is 8. Using 16 avoids that coincidence.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, could you please add that to the commit message?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

__attribute__((aligned(16))) char var2;
char var3 __attribute__((aligned(16)));
int (__attribute__((aligned(16))) var4);
int (__attribute__((aligned(16))) (var5));
int (__attribute__((aligned(16))) *var6);
int __attribute__((aligned(16))) *var7;
__attribute__((aligned(16))) int *var8;

STATIC_ASSERT(__alignof(var1)==8);
STATIC_ASSERT(__alignof(var2)==8);
STATIC_ASSERT(__alignof(var3)==8);
STATIC_ASSERT(__alignof(var4)==8);
STATIC_ASSERT(__alignof(var5)==8);
STATIC_ASSERT(__alignof(var1)==16);
STATIC_ASSERT(__alignof(var2)==16);
STATIC_ASSERT(__alignof(var3)==16);
STATIC_ASSERT(__alignof(var4)==16);
STATIC_ASSERT(__alignof(var5)==16);
#ifdef __clang__
STATIC_ASSERT(__alignof(var6)==16);
STATIC_ASSERT(__alignof(*var6)==__alignof(int));
#else
STATIC_ASSERT(__alignof(var6)==__alignof(void *));
STATIC_ASSERT(__alignof(var7)==8);
STATIC_ASSERT(__alignof(*var6)==16);
#endif
STATIC_ASSERT(__alignof(var7)==16);
STATIC_ASSERT(__alignof(var8)==16);

void (__attribute__((aligned)) *****f1)(void);
void (__attribute__((aligned)) f2)(void);
Expand Down
2 changes: 1 addition & 1 deletion regression/ansi-c/gcc_attributes5/test.desc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CORE gcc-only
KNOWNBUG gcc-only
main.c

^EXIT=0$
Expand Down