Commit 8cd7aac2 authored by Robert Hencke's avatar Robert Hencke Committed by Russ Cox

godefs: do not assume forward type references are enums

Fixes #1466.

R=mikioh.mikioh, rsc
CC=golang-dev
https://golang.org/cl/4564043
parent c5030e5f
...@@ -75,6 +75,7 @@ extern Const *con; ...@@ -75,6 +75,7 @@ extern Const *con;
extern int ncon; extern int ncon;
extern Type **typ; extern Type **typ;
extern int ntyp; extern int ntyp;
extern int kindsize[];
// Language output // Language output
typedef struct Lang Lang; typedef struct Lang Lang;
......
...@@ -181,7 +181,7 @@ main(int argc, char **argv) ...@@ -181,7 +181,7 @@ main(int argc, char **argv)
char **av, *q, *r, *tofree, *name; char **av, *q, *r, *tofree, *name;
char nambuf[100]; char nambuf[100];
Biobuf *bin, *bout; Biobuf *bin, *bout;
Type *t; Type *t, *tt;
Field *f; Field *f;
int orig_output_fd; int orig_output_fd;
...@@ -373,8 +373,16 @@ Continue: ...@@ -373,8 +373,16 @@ Continue:
prefix = prefixlen(t); prefix = prefixlen(t);
for(j=0; j<t->nf; j++) { for(j=0; j<t->nf; j++) {
f = &t->f[j]; f = &t->f[j];
if(f->type->kind == 0) if(f->type->kind == 0 && f->size <= 64 && (f->size&(f->size-1)) == 0) {
continue; // unknown type but <= 64 bits and bit size is a power of two.
// could be enum - make Uint64 and then let it reduce
tt = emalloc(sizeof *tt);
*tt = *f->type;
f->type = tt;
tt->kind = Uint64;
while(tt->kind > Uint8 && kindsize[tt->kind] > f->size)
tt->kind -= 2;
}
// padding // padding
if(t->kind == Struct || lang == &go) { if(t->kind == Struct || lang == &go) {
if(f->offset%8 != 0 || f->size%8 != 0) { if(f->offset%8 != 0 || f->size%8 != 0) {
......
...@@ -149,7 +149,7 @@ Intrange intranges[] = { ...@@ -149,7 +149,7 @@ Intrange intranges[] = {
16, 0, Void, 16, 0, Void,
}; };
static int kindsize[] = { int kindsize[] = {
0, 0,
0, 0,
8, 8,
...@@ -381,14 +381,6 @@ parsedef(char **pp, char *name) ...@@ -381,14 +381,6 @@ parsedef(char **pp, char *name)
while(f->type->kind == Typedef) while(f->type->kind == Typedef)
f->type = f->type->type; f->type = f->type->type;
if(f->type->kind == 0 && f->size <= 64 && (f->size&(f->size-1)) == 0) {
// unknown type but <= 64 bits and bit size is a power of two.
// could be enum - make Uint64 and then let it reduce
tt = emalloc(sizeof *tt);
*tt = *f->type;
f->type = tt;
tt->kind = Uint64;
}
// rewrite // rewrite
// uint32 x : 8; // uint32 x : 8;
......
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
// MACHINE GENERATED - DO NOT EDIT. // MACHINE GENERATED - DO NOT EDIT.
// Manual corrections: TODO: need to fix godefs (issue 1466)
// change Msghdr field to Iov *Iovec (was uint32/64)
// change BpfProgram field to Insns *BpfInsn (was uint32/64)
package syscall package syscall
// Constants // Constants
......
...@@ -2,10 +2,6 @@ ...@@ -2,10 +2,6 @@
// MACHINE GENERATED - DO NOT EDIT. // MACHINE GENERATED - DO NOT EDIT.
// Manual corrections: TODO: need to fix godefs (issue 1466)
// change Msghdr field to Iov *Iovec (was uint32/64)
// change BpfProgram field to Insns *BpfInsn (was uint32/64)
package syscall package syscall
// Constants // Constants
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment