Subject: Re: gcc4 lossage on mips kernels with semi-packed struct
To: None <tech-toolchain@netbsd.org>
From: Simon Burge <simonb@wasabisystems.com>
List: tech-toolchain
Date: 05/17/2006 11:36:54
I've made a simple test case:

    struct in_addr {
	unsigned int s_addr;
    } __attribute__((__packed__));

    struct bootpcontext {
	char expected_dhcpmsgtype, dhcp_ok;
	struct in_addr serverip;
    };

    void
    bootpcheck(int *p, struct bootpcontext *bpc)
    {
	memcpy(&bpc->serverip.s_addr, p, sizeof(bpc->serverip.s_addr));
    }

This generates:

        lw      $2,0($4)
        j       $31
        sw      $2,2($5)

Before we submit a bug report to gcc, do any language lawyers have any
comments on what this is doing?  The description of -Wpacked from "info
gcc" says that we can expect serverip.s_addr in struct bootpcontext to
be unaligned, so it would seem that the memcpy optimisation is wrong in
forgetting about the packed attribute.

Simon.
--
Simon Burge                                   <simonb@wasabisystems.com>
NetBSD Development, Support and Service:   http://www.wasabisystems.com/