summaryrefslogtreecommitdiff
path: root/src/cmd/gc/unsafe.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/gc/unsafe.c')
-rw-r--r--src/cmd/gc/unsafe.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/cmd/gc/unsafe.c b/src/cmd/gc/unsafe.c
index d304077c8..95200ad41 100644
--- a/src/cmd/gc/unsafe.c
+++ b/src/cmd/gc/unsafe.c
@@ -2,12 +2,15 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+#include <u.h>
+#include <libc.h>
#include "go.h"
/*
* look for
* unsafe.Sizeof
* unsafe.Offsetof
+ * unsafe.Alignof
* rewrite with a constant
*/
Node*
@@ -20,7 +23,7 @@ unsafenmagic(Node *nn)
Val val;
Node *fn;
NodeList *args;
-
+
fn = nn->left;
args = nn->list;
@@ -78,10 +81,10 @@ no:
return N;
bad:
- yyerror("invalid expression %#N", nn);
+ yyerror("invalid expression %N", nn);
v = 0;
goto ret;
-
+
yes:
if(args->next != nil)
yyerror("extra arguments for %S", s);
@@ -91,7 +94,23 @@ ret:
val.u.xval = mal(sizeof(*n->val.u.xval));
mpmovecfix(val.u.xval, v);
n = nod(OLITERAL, N, N);
+ n->orig = nn;
n->val = val;
n->type = types[TUINTPTR];
+ nn->type = types[TUINTPTR];
return n;
}
+
+int
+isunsafebuiltin(Node *n)
+{
+ if(n == N || n->op != ONAME || n->sym == S || n->sym->pkg != unsafepkg)
+ return 0;
+ if(strcmp(n->sym->name, "Sizeof") == 0)
+ return 1;
+ if(strcmp(n->sym->name, "Offsetof") == 0)
+ return 1;
+ if(strcmp(n->sym->name, "Alignof") == 0)
+ return 1;
+ return 0;
+}