Skip to content
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

Example where sizeof differs between clang and gcc #6009

Closed
llvmbot opened this issue Nov 29, 2009 · 5 comments
Closed

Example where sizeof differs between clang and gcc #6009

llvmbot opened this issue Nov 29, 2009 · 5 comments
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"

Comments

@llvmbot
Copy link
Member

llvmbot commented Nov 29, 2009

Bugzilla Link 5637
Resolution FIXED
Resolved on Apr 26, 2011 16:06
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @akyrtzi,@lattner

Extended Description

Clang outputs 72 and gcc 80 on my x86-64 linux box. What's going on here
is that gcc does not round up the size of the type UINT192 to the alignment
the user specified, but it does use this alignment to round up the size of
the array of UINT192. I asked on #gcc whether this should be considered a
gcc bug, but richi thought it was "by design".

#include <stdio.h>

typedef attribute((aligned(16))) struct {
unsigned long long w[3];
} UINT192;

UINT192 ten2mk192M[] = {
{{0xcddd6e04c0592104ULL, 0x0fcf80dc33721d53ULL, 0xa7c5ac471b478423ULL}},
{{0xcddd6e04c0592104ULL, 0x0fcf80dc33721d53ULL, 0xa7c5ac471b478423ULL}},
{{0xcddd6e04c0592104ULL, 0x0fcf80dc33721d53ULL, 0xa7c5ac471b478423ULL}}
};

int main(void) {
printf("sizeof: %lu\n", sizeof(ten2mk192M));
return 0;
}

@akyrtzi
Copy link
Contributor

akyrtzi commented Jan 29, 2011

I'm not so sure that this is a clang bug.

I can't find any mention in the standards about padding in arrays. C++ 5.3.3p2 (expr.sizeof) says:
"When applied to an array, the result is the total number of bytes in the array. This implies that the size of an array of n elements is n times the size of an element."

C99 6.5.3.4p6 (sizeof) implies the same with "Another use of the sizeof operator is to compute the number of elements in an array: sizeof array / sizeof array[0]"

Note that in both standards, in those sections they specifically mention padding for classes/structures.

You lose the symmetry in multidimensional arrays:
sizeof(UINT192[2][3]) == 160
sizeof(UINT192[3][2]) == 144

Could someone let me know what is the justification for the padding in the array ?

@akyrtzi
Copy link
Contributor

akyrtzi commented Jan 31, 2011

Submitted http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47557 to get input from gcc developers.

@lattner
Copy link
Collaborator

lattner commented Mar 11, 2011

Reverified, amusingly llvm-gcc ICE's on this.

@llvmbot
Copy link
Member Author

llvmbot commented Mar 11, 2011

Dragonegg doesn't though :)

@akyrtzi
Copy link
Contributor

akyrtzi commented Apr 26, 2011

Fixed at r130242.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
Michael137 pushed a commit to Michael137/llvm-project that referenced this issue Jan 18, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Rename test
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:frontend Language frontend issues, e.g. anything involving "Sema"
Projects
None yet
Development

No branches or pull requests

3 participants