Re: Forward declarations and variable alignment weirdness
2010/8/21 Paul Brook p...@codesourcery.com: I have run into variable alignment issues, which turned out to be caused by forward declaration w/o the aligned attribute repeated. Could someone explain this please? If it's a bug to not include the aligned attribute in the forward declaration, would it be hard to add a warning for that? Also the difference between 4.4.4 and 4.5.1 is interesting. PR45112. See also http://gcc.gnu.org/ml/gcc-patches/2010-08/msg00283.html Thanks a lot for info. If I got the discussion right, it's ok for the definition to use more strict alignment than the declaration. And a declaration without the aligned attribute implies alignment of __alignof__(type)? So in testcase #3 the alignment of 16 is coming from some other optimization and the fixed bug was preventing the definition for making it go down to 8. Anyway, I think a warning in the case when the aligned attribute of the definition cannot be satisfied because of some earlier declaration would be a good idea. -- Best Regards Piotr Jaroszyński
Forward declarations and variable alignment weirdness
Hello, I have run into variable alignment issues, which turned out to be caused by forward declaration w/o the aligned attribute repeated. Let me walk you through simple testcases showing different alignments I see for misaligned on gcc 4.4.4 and 4.5.1. Common type definition: struct foo { char* a; char b; }; testcase #1: struct foo misaligned = { 0, 1 }; struct foo *ptr = misaligned; 4.4.4: 16 4.5.1: 16 No surprise here. testcase #2: struct foo misaligned __attribute__((aligned(2))) = { 0, 1 }; struct foo *ptr = misaligned; 4.4.4: 2 4.5.1: 2 Also all good. testcase #3: struct foo misaligned; struct foo misaligned __attribute__((aligned(2))) = { 0, 1 }; struct foo *ptr = misaligned; 4.4.4: 8 4.5.1: 16 Could someone explain this please? If it's a bug to not include the aligned attribute in the forward declaration, would it be hard to add a warning for that? Also the difference between 4.4.4 and 4.5.1 is interesting. -- Best Regards Piotr Jaroszyński
Re: Forward declarations and variable alignment weirdness
2010/8/20 Piotr Jaroszyński p.jaroszyn...@gmail.com: Let me walk you through simple testcases showing different alignments I see for misaligned on gcc 4.4.4 and 4.5.1. Forgot to mention the results are for x86_64. -- Best Regards Piotr Jaroszyński