diff options
| author | Ian Lance Taylor <iant@golang.org> | 2009-02-10 11:46:26 -0800 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2009-02-10 11:46:26 -0800 |
| commit | e114da7db7c1cb0a09c2193f99ee627084f06a95 (patch) | |
| tree | d67091af3bcae0f07a74be6a8a45f697a6b12742 /src/cmd/gc/dcl.c | |
| parent | 6246d58105c44f9ed4f5a0ae7230b8a96f55cc99 (diff) | |
| download | golang-e114da7db7c1cb0a09c2193f99ee627084f06a95.tar.gz | |
Implement unsafe.Alignof.
R=ken
DELTA=20 (19 added, 0 deleted, 1 changed)
OCL=24719
CL=24771
Diffstat (limited to 'src/cmd/gc/dcl.c')
| -rw-r--r-- | src/cmd/gc/dcl.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/cmd/gc/dcl.c b/src/cmd/gc/dcl.c index d5d3a9bf4..35d1a8e62 100644 --- a/src/cmd/gc/dcl.c +++ b/src/cmd/gc/dcl.c @@ -1495,6 +1495,7 @@ unsafenmagic(Node *l, Node *r) { Node *n; Sym *s; + Type *t; long v; Val val; @@ -1519,7 +1520,23 @@ unsafenmagic(Node *l, Node *r) if(r->op != ODOT && r->op != ODOTPTR) goto no; walktype(r, Erv); - v = n->xoffset; + v = r->xoffset; + goto yes; + } + if(strcmp(s->name, "Alignof") == 0) { + walktype(r, Erv); + if (r->type == T) + goto no; + // make struct { byte; T; } + t = typ(TSTRUCT); + t->type = typ(TFIELD); + t->type->type = types[TUINT8]; + t->type->down = typ(TFIELD); + t->type->down->type = r->type; + // compute struct widths + dowidth(t); + // the offset of T is its required alignment + v = t->type->down->width; goto yes; } |
