This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[3.3 PATCH RFA]: Patch for packed structures on 3.3 branch (PR middle-end/16038)
- From: Ian Lance Taylor <ian at wasabisystems dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Date: 17 Jun 2004 16:04:52 -0400
- Subject: [3.3 PATCH RFA]: Patch for packed structures on 3.3 branch (PR middle-end/16038)
This test case fails for the mips-elf target on 3.3 with -O:
struct in_addr {
unsigned int s_addr;
} __attribute__((__packed__));
struct MemberInfo_t {
char membername[1];
struct in_addr ipaddrs[3];
};
extern void bar (struct in_addr);
void foo(struct MemberInfo_t *p)
{
unsigned int i;
for (i = 0; i < 3; i++)
if (p->ipaddrs[i].s_addr != 0)
bar(p->ipaddrs[i]);
}
It generates an illegal unaligned access. See PR middle-end/16038 for
the details.
The code works in 3.4. This patch fixes the problem in 3.3.
OK for the 3.3 branch for inclusion in 3.3.5?
Ian
2004-06-17 Ian Lance Taylor <ian@wasabisystems.com>
PR middle-end/16038
Backport from mainline:
Fri Apr 4 17:43:52 2003 Olivier Hainque <hainque@act-europe.fr>
* emit-rtl.c (get_mem_attrs): Adjust alignment tests determining
use of default attributes to agree MEM_ALIGN macro.
Index: emit-rtl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/emit-rtl.c,v
retrieving revision 1.303.2.4
diff -p -u -r1.303.2.4 emit-rtl.c
--- emit-rtl.c 10 Dec 2003 17:37:18 -0000 1.303.2.4
+++ emit-rtl.c 17 Jun 2004 20:04:22 -0000
@@ -297,13 +297,14 @@ get_mem_attrs (alias, expr, offset, size
mem_attrs attrs;
void **slot;
- /* If everything is the default, we can just return zero. */
+ /* If everything is the default, we can just return zero.
+ This must match what the corresponding MEM_* macros return when the
+ field is not present. */
if (alias == 0 && expr == 0 && offset == 0
&& (size == 0
|| (mode != BLKmode && GET_MODE_SIZE (mode) == INTVAL (size)))
- && (align == BITS_PER_UNIT
- || (STRICT_ALIGNMENT
- && mode != BLKmode && align == GET_MODE_ALIGNMENT (mode))))
+ && (STRICT_ALIGNMENT && mode != BLKmode
+ ? align == GET_MODE_ALIGNMENT (mode) : align == BITS_PER_UNIT))
return 0;
attrs.alias = alias;