public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c/10360: __alignof__(double) answer 8
@ 2003-04-09 22:06 Frederic De Jaeger
0 siblings, 0 replies; 6+ messages in thread
From: Frederic De Jaeger @ 2003-04-09 22:06 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c/10360; it has been noted by GNATS.
From: Frederic De Jaeger <dejaeger@free.fr>
To: rth@gcc.gnu.org, discuss-gnustep@gnu.org, gcc-bugs@gcc.gnu.org,
gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, richard@brainstorm.co.uk,
thoran@free.fr, gcc-gnats@gcc.gnu.org
Cc:
Subject: Re: c/10360: __alignof__(double) answer 8
Date: 09 Apr 2003 23:59:58 +0200
rth> Synopsis: __alignof__(double) answer 8
rth> State-Changed-From-To: open->closed
rth> State-Changed-By: rth
rth> State-Changed-When: Wed Apr 9 17:29:53 2003
rth> State-Changed-Why:
rth> Not a bug. __alignof__ returns the *preferred* alignment.
rth> You're seeing other SVr4 ABI rules concerning structures.
Thus, why gcc does not align fields with respect to this *preferred*
alignment?
How can I compute the address of a field in a record?
I need to do this uniformly on all the types. That means I cannot use
the trick :
offset = (char *)&foo.bla - (char *)&foo.
or the "offsetof" macro.
because I don't know, statically, the type of the record from which I
need to compute offsets.
The type information comes from the @encode directive of
objective-C (ie: it's a characters string that describe a type).
Actually, we are using "objc_alignof_type" (from the objective-c API)
and we expect it to return the alignment used by the compiler (and not
the *preferred* alignment).
Thanks for your help,
Frederic De Jaeger
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: c/10360: __alignof__(double) answer 8
@ 2003-04-10 8:06 Richard Henderson
0 siblings, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2003-04-10 8:06 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c/10360; it has been noted by GNATS.
From: Richard Henderson <rth@redhat.com>
To: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Cc: gcc-gnats@gcc.gnu.org, thoran@free.fr, nobody@gcc.gnu.org,
gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org, discuss-gnustep@gnu.org,
rth@gcc.gnu.org, Frederic De Jaeger <dejaeger@free.fr>
Subject: Re: c/10360: __alignof__(double) answer 8
Date: Thu, 10 Apr 2003 01:00:00 -0700
On Thu, Apr 10, 2003 at 06:06:44AM +0100, Richard Frith-Macdonald wrote:
> It would be interesting to know in what sense the alignment is
> 'preferred'.
In that it takes one less cycle to load that way? In that that's
how data gets aligned which isn't constrained by the ABI?
> Shouldn't this either be fixed as Frederic suggests, or the documentation
> be changed so that instead of saying 'preferred' it says 'misleading and
> largely useless'
And indeed, that's what we ALREADY say, except you didn't read it.
To wit:
Some machines never actually require alignment; they allow
reference to any data type even at an odd addresses. For
these machines, __alignof__ reports the recommended alignment
of a type.
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: c/10360: __alignof__(double) answer 8
@ 2003-04-10 5:16 Richard Frith-Macdonald
0 siblings, 0 replies; 6+ messages in thread
From: Richard Frith-Macdonald @ 2003-04-10 5:16 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c/10360; it has been noted by GNATS.
From: Richard Frith-Macdonald <richard@brainstorm.co.uk>
To: Richard Henderson <rth@redhat.com>
Cc: gcc-gnats@gcc.gnu.org, thoran@free.fr, nobody@gcc.gnu.org,
gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org, discuss-gnustep@gnu.org,
rth@gcc.gnu.org, Frederic De Jaeger <dejaeger@free.fr>
Subject: Re: c/10360: __alignof__(double) answer 8
Date: Thu, 10 Apr 2003 06:06:44 +0100
On Wednesday, April 9, 2003, at 11:40 pm, Richard Henderson wrote:
> On Wed, Apr 09, 2003 at 11:59:58PM +0200, Frederic De Jaeger wrote:
>> Thus, why gcc does not align fields with respect to this *preferred*
>> alignment?
>
> Because the ABI says not to.
It would be interesting to know in what sense the alignment is
'preferred'.
Surely if the 'ABI says not to' then the alignment is not preferred?
>> ... and we expect it to return the alignment used by the compiler
>> (and not
>> the *preferred* alignment).
>
> A meaningless number. Because "the alignment used by the compiler"
> is going to depend on the context in which it is used.
I think that Frederic means the alignment the compiler uses to lay out
structures in memory.
It's hard to see how that can be context sensistive since the compiler
needs to know it to access the structure elements via a pointer, so
the code that stored the structure in memory and the code that
retrieves it through the pointer have to use the same alignments.
I imagine this is *by far* the most common context in which anyone
would want to know a type alignment (actually it's the only one I can
think of off hand).
So if __alignof__ is not returning the alignment of a type for structure
layout, how can it be returning the 'preferred' alignment. Shouldn't
this
either be fixed as Frederic suggests, or the documentation be changed
so that instead of saying 'preferred' it says 'misleading and largely
useless'
Sorry if this sounds overly aggressive, but I do think that compiler
extensions
should be useful and behave as expected, and this behavior seems to
mean that __alignof__ fails in this.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: c/10360: __alignof__(double) answer 8
@ 2003-04-09 22:46 Richard Henderson
0 siblings, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2003-04-09 22:46 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR c/10360; it has been noted by GNATS.
From: Richard Henderson <rth@redhat.com>
To: Frederic De Jaeger <dejaeger@free.fr>
Cc: rth@gcc.gnu.org, discuss-gnustep@gnu.org, gcc-bugs@gcc.gnu.org,
gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, richard@brainstorm.co.uk,
thoran@free.fr, gcc-gnats@gcc.gnu.org
Subject: Re: c/10360: __alignof__(double) answer 8
Date: Wed, 9 Apr 2003 15:40:39 -0700
On Wed, Apr 09, 2003 at 11:59:58PM +0200, Frederic De Jaeger wrote:
> Thus, why gcc does not align fields with respect to this *preferred*
> alignment?
Because the ABI says not to.
> How can I compute the address of a field in a record?
offsetof.
> I need to do this uniformly on all the types. That means I cannot use
> the trick :
> offset = (char *)&foo.bla - (char *)&foo.
> or the "offsetof" macro.
Tough luck then.
> ... and we expect it to return the alignment used by the compiler (and not
> the *preferred* alignment).
A meaningless number. Because "the alignment used by the compiler"
is going to depend on the context in which it is used.
r~
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: c/10360: __alignof__(double) answer 8
@ 2003-04-09 17:29 rth
0 siblings, 0 replies; 6+ messages in thread
From: rth @ 2003-04-09 17:29 UTC (permalink / raw)
To: discuss-gnustep, gcc-bugs, gcc-prs, nobody, richard, thoran
Synopsis: __alignof__(double) answer 8
State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Wed Apr 9 17:29:53 2003
State-Changed-Why:
Not a bug. __alignof__ returns the *preferred* alignment.
You're seeing other SVr4 ABI rules concerning structures.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=10360
^ permalink raw reply [flat|nested] 6+ messages in thread
* c/10360: __alignof__(double) answer 8
@ 2003-04-09 9:06 thoran
0 siblings, 0 replies; 6+ messages in thread
From: thoran @ 2003-04-09 9:06 UTC (permalink / raw)
To: gcc-gnats; +Cc: discuss-gnustep, Richard Frith-Macdonald
>Number: 10360
>Category: c
>Synopsis: __alignof__(double) answer 8
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Apr 09 09:06:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Frederic De Jaeger
>Release: gcc 3.2.3
>Organization:
>Environment:
Reading specs from /usr/lib/gcc-lib/i386-linux/3.2.3/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,proto,pascal,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-java-gc=boehm --enable-objc-gc i386-linux
Thread model: posix
gcc version 3.2.3 20030309 (Debian prerelease)
Linux thc 2.4.20-k7 #1 Tue Jan 14 00:29:06 EST 2003 i686 unknown unknown GNU/Linux
>Description:
__alignof__(double) answer 8. But actually, it is 4 (that's what gcc generates for record).
Apparently the problem happened in gcc 3.0
>How-To-Repeat:
#include <stdio.h>
struct bla
{
char c;
double v;
};
void main (void)
{
struct bla b;
printf("align double %d\neffective alignement %d\n", __alignof__(double),
((char *)(&b.v)) - ((char *)(&b.c)));
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2003-04-10 8:06 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-04-09 22:06 c/10360: __alignof__(double) answer 8 Frederic De Jaeger
-- strict thread matches above, loose matches on Subject: below --
2003-04-10 8:06 Richard Henderson
2003-04-10 5:16 Richard Frith-Macdonald
2003-04-09 22:46 Richard Henderson
2003-04-09 17:29 rth
2003-04-09 9:06 thoran
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).