* [9fans] c compiler size bug fix
@ 2009-09-15 22:14 erik quanstrom
0 siblings, 0 replies; only message in thread
From: erik quanstrom @ 2009-09-15 22:14 UTC (permalink / raw)
To: 9fans
unfortunately i let this one fester until it cost
us some time. this problem has cropped up
again http://9fans.net/archive/2009/07/305
(it appears that my worry about expandable arrays
was unfounded.)
the problem is that the size of an undefined
struct as the last element of a struct is not
counted because it is not known at the time.
rather than diagnosing an incomplete reference,
the program compiles and prints an unespected
size, "sizeof A = 4 4". i don't believe it should
compile at all.
the fix is simply this:
/n/dump/2009/0915/sys/src/cmd/cc/dcl.c:541,547 - dcl.c:541,547
l->offset = o;
} else {
if(l->width <= 0)
- if(l->down != T)
+ if(l->down != T || l->width < 0)
if(l->sym)
diag(Z, "incomplete structure element: %s",
l->sym->name);
thanks to bwc for identifying the problem (again).
patch submitted: /n/sources/patch/incmpltdiag
- erik
---
#include <u.h>
#include <libc.h>
typedef struct A A;
typedef struct B B;
struct A {
int a;
B;
};
struct B {
uchar buf[512];
};
void
main(void)
{
A a;
B b;
print("sizeof A = %d %d\n", sizeof(A), sizeof a);
print("sizeof B = %d %d\n", sizeof(B), sizeof b);
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-09-15 22:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-15 22:14 [9fans] c compiler size bug fix erik quanstrom
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).