summaryrefslogtreecommitdiff
path: root/src/cmd/gc/dcl.c
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2009-02-10 11:46:26 -0800
committerIan Lance Taylor <iant@golang.org>2009-02-10 11:46:26 -0800
commite114da7db7c1cb0a09c2193f99ee627084f06a95 (patch)
treed67091af3bcae0f07a74be6a8a45f697a6b12742 /src/cmd/gc/dcl.c
parent6246d58105c44f9ed4f5a0ae7230b8a96f55cc99 (diff)
downloadgolang-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.c19
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;
}