Module Name: src
Committed By: christos
Date: Mon Mar 6 21:01:39 UTC 2017
Modified Files:
src/usr.bin/xlint/lint1: cgram.y externs1.h scan.l tree.c
Log Message:
fix typeof, add __builtin_offsetof
To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/xlint/lint1/externs1.h
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/xlint/lint1/scan.l
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/xlint/lint1/tree.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.93 src/usr.bin/xlint/lint1/cgram.y:1.94
--- src/usr.bin/xlint/lint1/cgram.y:1.93 Mon Mar 6 06:58:31 2017
+++ src/usr.bin/xlint/lint1/cgram.y Mon Mar 6 16:01:39 2017
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.93 2017/03/06 11:58:31 christos Exp $ */
+/* $NetBSD: cgram.y,v 1.94 2017/03/06 21:01:39 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.93 2017/03/06 11:58:31 christos Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.94 2017/03/06 21:01:39 christos Exp $");
#endif
#include <stdlib.h>
@@ -140,6 +140,7 @@ anonymize(sym_t *s)
%token <y_op> T_UNOP
%token <y_op> T_INCDEC
%token T_SIZEOF
+%token T_BUILTIN_OFFSETOF
%token T_TYPEOF
%token T_EXTENSION
%token T_ALIGNOF
@@ -245,7 +246,7 @@ anonymize(sym_t *s)
%left T_SHFTOP
%left T_ADDOP
%left T_MULT T_DIVOP
-%right T_UNOP T_INCDEC T_SIZEOF T_ALIGNOF T_REAL T_IMAG
+%right T_UNOP T_INCDEC T_SIZEOF TBUILTIN_SIZEOF T_ALIGNOF T_REAL T_IMAG
%left T_LPARN T_LBRACK T_STROP
%token <y_sb> T_NAME
@@ -1362,10 +1363,7 @@ init_rbrace:
;
type_name:
- T_TYPEOF term {
- $$ = $2->tn_type;
- }
- | {
+ {
pushdecl(ABSTRACT);
} abstract_declaration {
popdecl();
@@ -1398,6 +1396,9 @@ abs_decl:
| pointer direct_abs_decl {
$$ = addptr($2, $1);
}
+ | T_TYPEOF term {
+ $$ = mktempsym($2->tn_type);
+ }
;
direct_abs_decl:
@@ -1905,6 +1906,11 @@ term:
| T_IMAG T_LPARN term T_RPARN {
$$ = build(IMAG, $3, NULL);
}
+ | T_BUILTIN_OFFSETOF T_LPARN type_name T_COMMA identifier T_RPARN
+ %prec T_BUILTIN_OFFSETOF {
+ symtyp = FMOS;
+ $$ = bldoffsetof($3, getsym($5));
+ }
| T_SIZEOF term %prec T_SIZEOF {
if (($$ = $2 == NULL ? NULL : bldszof($2->tn_type)) != NULL)
chkmisc($2, 0, 0, 0, 0, 0, 1);
Index: src/usr.bin/xlint/lint1/externs1.h
diff -u src/usr.bin/xlint/lint1/externs1.h:1.34 src/usr.bin/xlint/lint1/externs1.h:1.35
--- src/usr.bin/xlint/lint1/externs1.h:1.34 Tue Dec 27 16:52:35 2016
+++ src/usr.bin/xlint/lint1/externs1.h Mon Mar 6 16:01:39 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.34 2016/12/27 21:52:35 christos Exp $ */
+/* $NetBSD: externs1.h,v 1.35 2017/03/06 21:01:39 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -204,6 +204,7 @@ extern tnode_t *promote(op_t, int, tnode
extern tnode_t *convert(op_t, int, type_t *, tnode_t *);
extern void cvtcon(op_t, int, type_t *, val_t *, val_t *);
extern tnode_t *bldszof(type_t *);
+extern tnode_t *bldoffsetof(type_t *, sym_t *);
extern tnode_t *bldalof(type_t *);
extern tnode_t *cast(tnode_t *, type_t *);
extern tnode_t *funcarg(tnode_t *, tnode_t *);
Index: src/usr.bin/xlint/lint1/scan.l
diff -u src/usr.bin/xlint/lint1/scan.l:1.78 src/usr.bin/xlint/lint1/scan.l:1.79
--- src/usr.bin/xlint/lint1/scan.l:1.78 Sun Jan 15 16:10:24 2017
+++ src/usr.bin/xlint/lint1/scan.l Mon Mar 6 16:01:39 2017
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: scan.l,v 1.78 2017/01/15 21:10:24 christos Exp $ */
+/* $NetBSD: scan.l,v 1.79 2017/03/06 21:01:39 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: scan.l,v 1.78 2017/01/15 21:10:24 christos Exp $");
+__RCSID("$NetBSD: scan.l,v 1.79 2017/03/06 21:01:39 christos Exp $");
#endif
#include <stdlib.h>
@@ -218,6 +218,7 @@ static struct kwtab {
{ "bounded", T_AT_BOUNDED, 0, 0, 0, 0,0,1,1,5 },
{ "break", T_BREAK, 0, 0, 0, 0,0,0,0,1 },
{ "buffer", T_AT_BUFFER, 0, 0, 0, 0,0,1,1,5 },
+ { "builtin_offsetof", T_BUILTIN_OFFSETOF, 0, 0, 0, 0,0,1,0,2 },
{ "case", T_CASE, 0, 0, 0, 0,0,0,0,1 },
{ "char", T_TYPE, 0, CHAR, 0, 0,0,0,0,1 },
{ "cold", T_AT_COLD, 0, 0, 0, 0,0,1,1,5 },
Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.83 src/usr.bin/xlint/lint1/tree.c:1.84
--- src/usr.bin/xlint/lint1/tree.c:1.83 Fri Aug 19 06:19:45 2016
+++ src/usr.bin/xlint/lint1/tree.c Mon Mar 6 16:01:39 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.83 2016/08/19 10:19:45 christos Exp $ */
+/* $NetBSD: tree.c,v 1.84 2017/03/06 21:01:39 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.83 2016/08/19 10:19:45 christos Exp $");
+__RCSID("$NetBSD: tree.c,v 1.84 2017/03/06 21:01:39 christos Exp $");
#endif
#include <stdlib.h>
@@ -3012,6 +3012,26 @@ bldszof(type_t *tp)
return getinode(st, tsize(tp) / CHAR_BIT);
}
+/*
+ * Create a constant node for offsetof.
+ */
+tnode_t *
+bldoffsetof(type_t *tp, sym_t *sym)
+{
+ tspec_t st;
+#if SIZEOF_IS_ULONG
+ st = ULONG;
+#else
+ st = UINT;
+#endif
+ tspec_t t = tp->t_tspec;
+ if (t != STRUCT && t != UNION)
+ error(111, "offsetof");
+
+ // XXX: wrong size, no checking for sym fixme
+ return getinode(st, tsize(tp) / CHAR_BIT);
+}
+
int64_t
tsize(type_t *tp)
{