it appears that ?c do not properly do structure
assignment if the structure is packed.
i've included a patch just for 8c and a sample
program that generates two "packed assignment"
warnings with the modified compiler.
feedback appreciated unless it's "don't do that."
if this looks entirely reasonable, i'll submit a patch
for all the compilers.
- erik
---
; diffy -c /sys/src/cmd/8c/cgen.c
/n/dump/2010/0914/sys/src/cmd/8c/cgen.c:1824,1829 -
/sys/src/cmd/8c/cgen.c:1824,1836
gins(ACLD, Z, Z);
gins(AREP, Z, Z);
gins(AMOVSL, Z, Z);
+ if(x = w & SZ_LONG-1){
+ warn(n, "packed assignment");
+ gins(AMOVL, nodconst(x), &nod3);
+ // gins(ACLD, Z, Z);
+ gins(AREP, Z, Z);
+ gins(AMOVSB, Z, Z);
+ }
if(c & 4) {
gins(APOPL, Z, &nod3);
reg[D_CX]--;
---
#include <u.h>
#include <libc.h>
#pragma pack on
typedef struct S S;
struct S
{
uchar a;
ushort b;
uint c;
};
#pragma pack off
S
func(void)
{
S s;
s.a = 1;
s.b = 2;
s.c = 3;
return s;
}
void
main(void)
{
S s, t;
memset(&s, 0xff, sizeof s);
print("sizeof s = %d\n", sizeof s);
s = func();
memset(&t, 0xff, sizeof t);
t = s;
print("a=%d b=%d c=%d\n", t.a, t.b, t.c);
exits(nil);
}