Summary: | Inconsistent __alignof__(long long) | ||
---|---|---|---|
Product: | gcc | Reporter: | Keith Thompson <Keith.S.Thompson> |
Component: | c | Assignee: | Not yet assigned to anyone <unassigned> |
Status: | RESOLVED DUPLICATE | ||
Severity: | minor | CC: | rth |
Priority: | P3 | ||
Version: | 4.7.0 | ||
Target Milestone: | --- | ||
Host: | Target: | ||
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: |
Description
Keith Thompson
2012-08-06 09:32:38 UTC
Forgot to mention: I compiled and executed the demo program as follows: gcc alignof_bug.c -o alignof_bug && ./alignof_bug Because the ABI says so and __alignof__ does not return the minimum but the recommended alignment. Really a dup of 10360. *** This bug has been marked as a duplicate of bug 10360 *** The results of the _Alignof operator (new in the 2011 ISO C standard) are the same as for the __alignof__ operator (not surprisingly). N1370 (C11 draft) 6.5.3.4 paragraph 3 says: The _Alignof operator yields the alignment requirement of its operand type. Richard Guenther: You say it's "Because the ABI says so". Do you have a reference to the ABI, particularly to a statement that a structure should have a smaller alignment than its member? You also say __alignof__ "does not return the minimum but the recommended alignment". That seems inconsistent with the use of the word "required" in C11. I just grabbed a copy of http://www.uclibc.org/docs/psABI-i386.pdf; is that the ABI you're referring to? Figure 3-1 covers alignment for scalar types. It says 8-byte floating-point has an alignment of 4 bytes, but it doesn't mention 8-byte integers. Furthermore, the following page says: Aggregates (structures and arrays) and unions assume the alignment of their most strictly aligned component. That seems inconsistent with the behavior of the following program: #include <stdio.h> int main(void) { printf("_Alignof(long long) = %d\n", (int)_Alignof(long long)); printf("_Alignof(struct {long long x;}) = %d\n", (int)_Alignof(struct {long long x;})); return 0; } whose output on my system, with gcc -std=c11 -pedantic c.c -o c && ./c is: _Alignof(long long) = 8 _Alignof(struct {long long x;}) = 4 My conclusion in bug 52023 was that _Alignof should differ from __alignof__ to meet the standard requirements (but really the standard didn't have such strange ABIs in mind at all). (In reply to comment #3) > N1370 (C11 draft) 6.5.3.4 paragraph 3 says: > > The _Alignof operator yields the alignment requirement of its > operand type. Does that imply that an i386 host should return 1 for most types, simply because it *can* allow unaligned accesses? On Wed, 8 Aug 2012, rth at gcc dot gnu.org wrote:
> > N1370 (C11 draft) 6.5.3.4 paragraph 3 says:
> >
> > The _Alignof operator yields the alignment requirement of its
> > operand type.
>
> Does that imply that an i386 host should return 1 for most types,
> simply because it *can* allow unaligned accesses?
Alignment requirements are defined in terms of "addresses at which objects
of that type may be allocated", not in terms of what might happen with a
pointer dereference.
|