* [Bug c/61447] _Alignof returns incorrect results for some types/archs
2014-06-08 14:30 [Bug c/61447] New: _Alignof returns incorrect results for some types/archs bugdal at aerifal dot cx
@ 2014-06-08 15:19 ` joseph at codesourcery dot com
2014-06-08 15:28 ` bugdal at aerifal dot cx
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: joseph at codesourcery dot com @ 2014-06-08 15:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61447
--- Comment #1 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
ISO C does not define _Alignof (object), only _Alignof (type).
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/61447] _Alignof returns incorrect results for some types/archs
2014-06-08 14:30 [Bug c/61447] New: _Alignof returns incorrect results for some types/archs bugdal at aerifal dot cx
2014-06-08 15:19 ` [Bug c/61447] " joseph at codesourcery dot com
@ 2014-06-08 15:28 ` bugdal at aerifal dot cx
2014-06-08 15:34 ` joseph at codesourcery dot com
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: bugdal at aerifal dot cx @ 2014-06-08 15:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61447
--- Comment #2 from Rich Felker <bugdal at aerifal dot cx> ---
Indeed, you seem to be correct in that claim. However it seems desirable that
if this usage is not supported, it should be treated as a constraint violation
rather than silently producing a wrong/meaningless result that appears "right"
in most cases. In any case, I still think it's a bug that the wrong value is
being produced for _Alignof(long long) except with -std=c11. Even if earlier
versions of the standard have nothing to say about what it should produce, the
principle of least surprise says that it should produce the same result as it
does under C11 since only C11 defines _Alignof.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/61447] _Alignof returns incorrect results for some types/archs
2014-06-08 14:30 [Bug c/61447] New: _Alignof returns incorrect results for some types/archs bugdal at aerifal dot cx
2014-06-08 15:19 ` [Bug c/61447] " joseph at codesourcery dot com
2014-06-08 15:28 ` bugdal at aerifal dot cx
@ 2014-06-08 15:34 ` joseph at codesourcery dot com
2014-06-08 15:47 ` bugdal at aerifal dot cx
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: joseph at codesourcery dot com @ 2014-06-08 15:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61447
--- Comment #3 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
What makes you think _Alignof depends on -std=c11 (other than for
-pedantic diagnostics)?
I don't see any point in requesting alignment of an object, as opposed to
a type, unless you want a result that can sometimes be bigger than what
you get from _Alignof applied to the type.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/61447] _Alignof returns incorrect results for some types/archs
2014-06-08 14:30 [Bug c/61447] New: _Alignof returns incorrect results for some types/archs bugdal at aerifal dot cx
` (2 preceding siblings ...)
2014-06-08 15:34 ` joseph at codesourcery dot com
@ 2014-06-08 15:47 ` bugdal at aerifal dot cx
2014-06-08 16:00 ` schwab@linux-m68k.org
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: bugdal at aerifal dot cx @ 2014-06-08 15:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61447
--- Comment #4 from Rich Felker <bugdal at aerifal dot cx> ---
Indeed, I can't reproduce that aspect of the problem now. My best guess is that
I accidentally used "gcc" rather than "gcc-4.9" for the test without -std=c11.
I'll post a follow-up comment if I do find such a problem again.
Back to the issue of _Alignof(object) however, I'm not so sure that your
interpretation of the standard is correct anymore. At the very least the
standard is ambiguous. 6.3.2.1 Lvalues, arrays, and function designators,
paragraph 2, reads:
"Except when it is the operand of the sizeof operator, the _Alignof operator,
the unary & operator, the ++ operator, the -- operator, or the left operand of
the . operator or an assignment operator, an lvalue that does not have array
type is converted to the value stored in the designated object (and is no
longer an lvalue); this is called lvalue conversion."
This text does not make sense if an expression cannot be the operand of
_Alignof. It's very possible that this is just residual cruft that should have
been removed, but it would be nice to get some clarification on whether, from
the committee's standpoint, the error is the presence of the above text or the
omission of text about how _Alignof handles an argument that's not a type.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/61447] _Alignof returns incorrect results for some types/archs
2014-06-08 14:30 [Bug c/61447] New: _Alignof returns incorrect results for some types/archs bugdal at aerifal dot cx
` (3 preceding siblings ...)
2014-06-08 15:47 ` bugdal at aerifal dot cx
@ 2014-06-08 16:00 ` schwab@linux-m68k.org
2014-06-09 6:27 ` mpolacek at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: schwab@linux-m68k.org @ 2014-06-08 16:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61447
--- Comment #5 from Andreas Schwab <schwab@linux-m68k.org> ---
The reference to _Alignof in 6.3.2.1 does not exist in the final version of the
standard, according to Larry Jones in comp.std.c (Message-Id:
<ucvm2a-hig.ln1@jones.homeip.net> or
<https://groups.google.com/d/topic/comp.std.c/v5hsWOu5vSw/discussion>).
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/61447] _Alignof returns incorrect results for some types/archs
2014-06-08 14:30 [Bug c/61447] New: _Alignof returns incorrect results for some types/archs bugdal at aerifal dot cx
` (4 preceding siblings ...)
2014-06-08 16:00 ` schwab@linux-m68k.org
@ 2014-06-09 6:27 ` mpolacek at gcc dot gnu.org
2014-06-09 15:14 ` joseph at codesourcery dot com
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-06-09 6:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61447
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |SUSPENDED
Last reconfirmed| |2014-06-09
CC| |mpolacek at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
There are more references to _Alignof in the draft that are not in the final
version. Anyway I think there isn't much to do for this PR right now, so
suspending for now until we have some conclusion about what should happen;
_Alignof (expr) is a GNU extension. The thing is that in case of EXPR, we
always call c_alignof_expr, but that can't be told that it should produce the
least alignment required for a type of EXPR. It wouldn't be hard to tweak it,
though.
Or should I close this one?
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/61447] _Alignof returns incorrect results for some types/archs
2014-06-08 14:30 [Bug c/61447] New: _Alignof returns incorrect results for some types/archs bugdal at aerifal dot cx
` (5 preceding siblings ...)
2014-06-09 6:27 ` mpolacek at gcc dot gnu.org
@ 2014-06-09 15:14 ` joseph at codesourcery dot com
2014-06-09 16:21 ` bugdal at aerifal dot cx
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: joseph at codesourcery dot com @ 2014-06-09 15:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61447
--- Comment #7 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
I think _Alignof (expr) should, for example, return the larger alignment
chosen with _Alignas in the case of a declaration using _Alignas, rather
than just being based on the type.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/61447] _Alignof returns incorrect results for some types/archs
2014-06-08 14:30 [Bug c/61447] New: _Alignof returns incorrect results for some types/archs bugdal at aerifal dot cx
` (6 preceding siblings ...)
2014-06-09 15:14 ` joseph at codesourcery dot com
@ 2014-06-09 16:21 ` bugdal at aerifal dot cx
2014-06-23 1:02 ` bugdal at aerifal dot cx
2014-06-23 5:37 ` mpolacek at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: bugdal at aerifal dot cx @ 2014-06-09 16:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61447
--- Comment #8 from Rich Felker <bugdal at aerifal dot cx> ---
There's already the GNU C __alignof__ which is free to do whatever GCC prefers,
so I fail to see the usefulness of making _Alignof do something nonstandard
(and IMO, utterly illogical) that might conflict with future standards. I would
prefer that __Alignof(expr) produce either an error, or
__Alignof(__typeof__(expr)).
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/61447] _Alignof returns incorrect results for some types/archs
2014-06-08 14:30 [Bug c/61447] New: _Alignof returns incorrect results for some types/archs bugdal at aerifal dot cx
` (7 preceding siblings ...)
2014-06-09 16:21 ` bugdal at aerifal dot cx
@ 2014-06-23 1:02 ` bugdal at aerifal dot cx
2014-06-23 5:37 ` mpolacek at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: bugdal at aerifal dot cx @ 2014-06-23 1:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61447
--- Comment #9 from Rich Felker <bugdal at aerifal dot cx> ---
As a related issue (let me know if I should open a new PR), the following code:
struct foo {
char c;
alignas(long long) long long ll;
};
is producing a wrong/nonsensical error with gcc 4.9:
error: '_Alignas' specifiers cannot reduce alignment of 'll'
Apparently (again) GCC wrongly internally thinks the alignment of long long is
8, rather than 4. With earlier gcc versions it simply gives the wrong alignment
(8 rather than 4).
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/61447] _Alignof returns incorrect results for some types/archs
2014-06-08 14:30 [Bug c/61447] New: _Alignof returns incorrect results for some types/archs bugdal at aerifal dot cx
` (8 preceding siblings ...)
2014-06-23 1:02 ` bugdal at aerifal dot cx
@ 2014-06-23 5:37 ` mpolacek at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-06-23 5:37 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61447
--- Comment #10 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Rich Felker from comment #9)
> As a related issue (let me know if I should open a new PR), the following
> code:
>
> struct foo {
> char c;
> alignas(long long) long long ll;
> };
>
> is producing a wrong/nonsensical error with gcc 4.9:
>
> error: '_Alignas' specifiers cannot reduce alignment of 'll'
>
> Apparently (again) GCC wrongly internally thinks the alignment of long long
> is 8, rather than 4. With earlier gcc versions it simply gives the wrong
> alignment (8 rather than 4).
This should be already fixed: PR61053 (earlier this month I backported the fix
even to 4.9).
^ permalink raw reply [flat|nested] 11+ messages in thread