This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/26565] New: Unaligned accesses with __attribute__(packed) and memcpy
- From: "falk at debian dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 5 Mar 2006 08:26:35 -0000
- Subject: [Bug middle-end/26565] New: Unaligned accesses with __attribute__(packed) and memcpy
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
gcc version 4.2.0 20060304 (experimental)
falk@juist:/tmp% cat test.c
void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n);
struct timeval {
long tv_sec;
};
struct outdata {
char seq;
struct timeval tv __attribute__((packed));
};
void send_probe(struct outdata *outdata, struct timeval *tp) {
memcpy(&outdata->tv, tp, sizeof outdata->tv);
}
falk@juist:/tmp% gcc-3.4 -c -O3 test.c && objdump -dr test.o
0000000000000000 <send_probe>:
0: 00 00 51 a6 ldq a2,0(a1)
4: 08 00 10 2d ldq_u t7,8(a0)
8: 01 00 70 20 lda t2,1(a0)
c: 01 00 f0 2c ldq_u t6,1(a0)
10: e5 0e 43 4a insqh a2,t2,t4
14: 64 07 43 4a insql a2,t2,t3
18: 46 0e 03 49 mskqh t7,t2,t5
1c: 40 06 e3 48 mskql t6,t2,v0
20: 01 04 c5 44 or t5,t4,t0
24: 08 00 30 3c stq_u t0,8(a0)
28: 02 04 04 44 or v0,t3,t1
2c: 01 00 50 3c stq_u t1,1(a0)
30: 01 80 fa 6b ret
falk@juist:/tmp% gcc -c -O3 test.c && objdump -dr test.o
0000000000000000 <send_probe>:
0: 00 00 31 a4 ldq t0,0(a1)
4: 01 00 30 b4 stq t0,1(a0)
8: 01 80 fa 6b ret
So 3.4 accounts for an unaligned access, but mainline doesn't.
This has been broken since 4.0. Just reading outdata->tv.tv_sec works fine.
--
Summary: Unaligned accesses with __attribute__(packed) and memcpy
Product: gcc
Version: 4.2.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: middle-end
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: falk at debian dot org
GCC build triplet: alphaev68-linux-gnu
GCC host triplet: alphaev68-linux-gnu
GCC target triplet: alphaev68-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26565