This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/16038] New: Bug in handling packed structures on MIPS


Consider this test case:

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]);
}

Compiling this with the 3.3 branch targeted for mips-elf, with -O, produces code
which includes these lines:

	sll	$2,$16,2
	addu	$3,$2,$17
	ulw	$2,1($3)
	#nop
	beq	$2,$0,$L4
	lw	$4,1($3)
	jal	bar

This is wrong.  The lw is an unaligned access, and must actually be ulw.

This is fixed in 3.4.0.  The patch can be found here:

http://gcc.gnu.org/ml/gcc-patches/2003-04/msg00299.html

If there is going to be a 3.3.5 release, I propose that this patch be brought
onto the 3.3 branch.

This testcase arises in the NetBSD sources.

-- 
           Summary: Bug in handling packed structures on MIPS
           Product: gcc
           Version: 3.3.4
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ian at wasabisystems dot com
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: mips-elf


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16038


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]