* [Bug c/18287] Unaligned access to fields inside packed records
2004-11-03 17:51 [Bug c/18287] New: Unaligned access to fields inside packed records ebotcazou at gcc dot gnu dot org
@ 2004-11-03 17:53 ` ebotcazou at gcc dot gnu dot org
2004-11-03 18:02 ` pinskia at gcc dot gnu dot org
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2004-11-03 17:53 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ebotcazou at gcc dot gnu dot org 2004-11-03 17:53 -------
Created an attachment (id=7467)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7467&action=view)
Testcase.
To be compiled with -O0.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/18287] Unaligned access to fields inside packed records
2004-11-03 17:51 [Bug c/18287] New: Unaligned access to fields inside packed records ebotcazou at gcc dot gnu dot org
2004-11-03 17:53 ` [Bug c/18287] " ebotcazou at gcc dot gnu dot org
@ 2004-11-03 18:02 ` pinskia at gcc dot gnu dot org
2004-11-03 18:03 ` pinskia at gcc dot gnu dot org
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-03 18:02 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-11-03 18:02 -------
Are you sure that 4.0.0 does not work, as it no longer does the transformation for &(a->b) into a +
offsetof(a,b).
>From the last tree dump for 4.0.0:
;; Function Assign_Hour_Of (Assign_Hour_Of)
Assign_Hour_Of (t)
{
<bb 0>:
t->Hour = 44;
return;
}
;; Function Clobber_Hour_Of (Clobber_Hour_Of)
Clobber_Hour_Of (dt)
{
struct Time_T * D.1128;
<bb 0>:
D.1128 = &dt->Time;
Assign_Hour_Of (D.1128);
return;
}
;; Function main (main)
main ()
{
struct Date_And_Time_T dt;
int D.1135;
<bb 0>:
dt.Time.Hour = 22;
Clobber_Hour_Of (&dt);
D.1135 = 0;
return D.1135;
}
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/18287] Unaligned access to fields inside packed records
2004-11-03 17:51 [Bug c/18287] New: Unaligned access to fields inside packed records ebotcazou at gcc dot gnu dot org
2004-11-03 17:53 ` [Bug c/18287] " ebotcazou at gcc dot gnu dot org
2004-11-03 18:02 ` pinskia at gcc dot gnu dot org
@ 2004-11-03 18:03 ` pinskia at gcc dot gnu dot org
2004-11-03 18:17 ` ebotcazou at gcc dot gnu dot org
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-03 18:03 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-11-03 18:03 -------
t->Hour = 44; /* unaligned word access */
is unaligned word access if t is not word aligned in the first place, correct which is where the problem
comes in right?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/18287] Unaligned access to fields inside packed records
2004-11-03 17:51 [Bug c/18287] New: Unaligned access to fields inside packed records ebotcazou at gcc dot gnu dot org
` (2 preceding siblings ...)
2004-11-03 18:03 ` pinskia at gcc dot gnu dot org
@ 2004-11-03 18:17 ` ebotcazou at gcc dot gnu dot org
2004-11-03 19:57 ` pinskia at gcc dot gnu dot org
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2004-11-03 18:17 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ebotcazou at gcc dot gnu dot org 2004-11-03 18:17 -------
> t->Hour = 44; /* unaligned word access */
> is unaligned word access if t is not word aligned in the first place, correct
> which is where the problem comes in right?
I confirm that the bus error (not bug error!) happens with 4.0.0 20041103. But,
you're right, probably another problem there.
The compiler should not pass the adress of &dt->Time to Assign_Hour_Of if it
can't prove that the field is at least as aligned as its type.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/18287] Unaligned access to fields inside packed records
2004-11-03 17:51 [Bug c/18287] New: Unaligned access to fields inside packed records ebotcazou at gcc dot gnu dot org
` (3 preceding siblings ...)
2004-11-03 18:17 ` ebotcazou at gcc dot gnu dot org
@ 2004-11-03 19:57 ` pinskia at gcc dot gnu dot org
2004-11-04 16:54 ` wintermute101 at wp dot pl
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-03 19:57 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-11-03 19:57 -------
There is another example of this in PR 17949 where the tree-optimizations cause something werid to
happen only because the middle-end does not know that they are unaligned loads.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/18287] Unaligned access to fields inside packed records
2004-11-03 17:51 [Bug c/18287] New: Unaligned access to fields inside packed records ebotcazou at gcc dot gnu dot org
` (4 preceding siblings ...)
2004-11-03 19:57 ` pinskia at gcc dot gnu dot org
@ 2004-11-04 16:54 ` wintermute101 at wp dot pl
2005-01-02 10:57 ` ebotcazou at gcc dot gnu dot org
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: wintermute101 at wp dot pl @ 2004-11-04 16:54 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From wintermute101 at wp dot pl 2004-11-04 16:54 -------
I write here cause it's simmilar situation as reported here but I have no data
about other gcc versions than 3.3.2.
I have following:
/////////////////
define _aligned(n) __attribute__((aligned(n), packed))
struct CzazPort {
unsigned short number;
unsigned long speed;
unsigned long protocol;
unsigned long mode;
unsigned short timeout;
unsigned short loglevel;
unsigned short timerid;
} _aligned(2);
struct CzazPort tmp;
sscanf( data, "%lu", &tmp.speed );
/////////////////////
data="9600"
before sscanf (content of tmp)
00:01:00:00:96:00:52:54:55:00:38:4e:31:00:03:e8:00:04:2b:67
after sscanf
00:00:25:80:96:00:52:54:55:00:38:4e:31:00:03:e8:00:04:2b:67
9600 in hex -> 0x2580
it was compiled for MOXA UC7420
the same program compiled for i686 works fine
this MOXA has XScale Intel prcessor working in big-endian. I guess this is the
problem (big-endian).
sscanf is just example from source. The same occurs when I relpace sscanf with
(*(&tmp.speed)) = 9600;
but
tmp.speed=9600;
works fine.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/18287] Unaligned access to fields inside packed records
2004-11-03 17:51 [Bug c/18287] New: Unaligned access to fields inside packed records ebotcazou at gcc dot gnu dot org
` (5 preceding siblings ...)
2004-11-04 16:54 ` wintermute101 at wp dot pl
@ 2005-01-02 10:57 ` ebotcazou at gcc dot gnu dot org
2005-01-02 11:03 ` ebotcazou at gcc dot gnu dot org
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2005-01-02 10:57 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ebotcazou at gcc dot gnu dot org 2005-01-02 10:57 -------
Reconfirmed with gcc version 4.0.0 20050101 (experimental) at -O0 on SPARC 32-bit.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed| |1
Last reconfirmed|0000-00-00 00:00:00 |2005-01-02 10:57:40
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/18287] Unaligned access to fields inside packed records
2004-11-03 17:51 [Bug c/18287] New: Unaligned access to fields inside packed records ebotcazou at gcc dot gnu dot org
` (6 preceding siblings ...)
2005-01-02 10:57 ` ebotcazou at gcc dot gnu dot org
@ 2005-01-02 11:03 ` ebotcazou at gcc dot gnu dot org
2005-01-02 11:12 ` ebotcazou at gcc dot gnu dot org
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2005-01-02 11:03 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ebotcazou at gcc dot gnu dot org 2005-01-02 11:03 -------
Clobber_Hour_Of:
save %sp, -112, %sp
st %i0, [%fp+68]
ld [%fp+68], %g1
add %g1, 5, %g1
mov %g1, %o0
call Assign_Hour_Of, 0
nop
is wrong: you can't merely add 5 to the address on STRICT_ALIGNMENT platforms.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/18287] Unaligned access to fields inside packed records
2004-11-03 17:51 [Bug c/18287] New: Unaligned access to fields inside packed records ebotcazou at gcc dot gnu dot org
` (7 preceding siblings ...)
2005-01-02 11:03 ` ebotcazou at gcc dot gnu dot org
@ 2005-01-02 11:12 ` ebotcazou at gcc dot gnu dot org
2005-01-02 16:45 ` giovannibajo at libero dot it
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2005-01-02 11:12 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ebotcazou at gcc dot gnu dot org 2005-01-02 11:11 -------
.t03.generic is already wrong:
Clobber_Hour_Of (dt)
{
struct Time_T * D.1122;
D.1122 = &dt->Time;
Assign_Hour_Of (D.1122);
}
struct Time_T is 32-bit aligned so D.1122 must be a multiple of 4; as such, it
cannot be assigned &dt->Time which is not a multiple of 4. A properly aligned
temporary should be created instead and its address assigned to D.1122.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/18287] Unaligned access to fields inside packed records
2004-11-03 17:51 [Bug c/18287] New: Unaligned access to fields inside packed records ebotcazou at gcc dot gnu dot org
` (8 preceding siblings ...)
2005-01-02 11:12 ` ebotcazou at gcc dot gnu dot org
@ 2005-01-02 16:45 ` giovannibajo at libero dot it
2005-01-02 17:20 ` ebotcazou at gcc dot gnu dot org
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: giovannibajo at libero dot it @ 2005-01-02 16:45 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From giovannibajo at libero dot it 2005-01-02 16:45 -------
Are we really forced to support ADDR_EXPR on unaligned fields? How would you
fix it with a temporary? Are you going to generate a FINALLY_EXPR to copy the
contents of the temporary back into the original field?
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/18287] Unaligned access to fields inside packed records
2004-11-03 17:51 [Bug c/18287] New: Unaligned access to fields inside packed records ebotcazou at gcc dot gnu dot org
` (9 preceding siblings ...)
2005-01-02 16:45 ` giovannibajo at libero dot it
@ 2005-01-02 17:20 ` ebotcazou at gcc dot gnu dot org
2005-01-03 23:16 ` rth at gcc dot gnu dot org
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2005-01-02 17:20 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ebotcazou at gcc dot gnu dot org 2005-01-02 17:20 -------
> Are we really forced to support ADDR_EXPR on unaligned fields? How would you
> fix it with a temporary? Are you going to generate a FINALLY_EXPR to copy the
> contents of the temporary back into the original field?
Yes and yes. The Ada compiler has been doing this for ages.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/18287] Unaligned access to fields inside packed records
2004-11-03 17:51 [Bug c/18287] New: Unaligned access to fields inside packed records ebotcazou at gcc dot gnu dot org
` (10 preceding siblings ...)
2005-01-02 17:20 ` ebotcazou at gcc dot gnu dot org
@ 2005-01-03 23:16 ` rth at gcc dot gnu dot org
2005-01-04 5:17 ` ebotcazou at gcc dot gnu dot org
2005-01-04 9:14 ` rth at gcc dot gnu dot org
13 siblings, 0 replies; 15+ messages in thread
From: rth at gcc dot gnu dot org @ 2005-01-03 23:16 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From rth at gcc dot gnu dot org 2005-01-03 23:16 -------
The Ada compiler may do it, but the C compiler does not. This test case,
written in C, is invalid.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/18287] Unaligned access to fields inside packed records
2004-11-03 17:51 [Bug c/18287] New: Unaligned access to fields inside packed records ebotcazou at gcc dot gnu dot org
` (11 preceding siblings ...)
2005-01-03 23:16 ` rth at gcc dot gnu dot org
@ 2005-01-04 5:17 ` ebotcazou at gcc dot gnu dot org
2005-01-04 9:14 ` rth at gcc dot gnu dot org
13 siblings, 0 replies; 15+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2005-01-04 5:17 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ebotcazou at gcc dot gnu dot org 2005-01-04 05:17 -------
> The Ada compiler may do it, but the C compiler does not. This test case,
> written in C, is invalid.
Could you tell on what grounds? AFAICS all fields are still addressable.
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |rth at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug c/18287] Unaligned access to fields inside packed records
2004-11-03 17:51 [Bug c/18287] New: Unaligned access to fields inside packed records ebotcazou at gcc dot gnu dot org
` (12 preceding siblings ...)
2005-01-04 5:17 ` ebotcazou at gcc dot gnu dot org
@ 2005-01-04 9:14 ` rth at gcc dot gnu dot org
13 siblings, 0 replies; 15+ messages in thread
From: rth at gcc dot gnu dot org @ 2005-01-04 9:14 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From rth at gcc dot gnu dot org 2005-01-04 09:14 -------
Subject: Re: Unaligned access to fields inside packed records
> Could you tell on what grounds? AFAICS all fields are still addressable.
Not really, they aren't. I've argued in the past that we should either
make them non-addressable, or (more usefully) implement pointers to
unaligned data. But having done neither, the result of the addressof
operator is undefined.
r~
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
^ permalink raw reply [flat|nested] 15+ messages in thread