Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 recognize struct __packed x { }; in addi...



details:   https://anonhg.NetBSD.org/src/rev/f371d7ebe933
branches:  trunk
changeset: 747807:f371d7ebe933
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Oct 02 19:01:13 2009 +0000

description:
recognize struct __packed x { }; in addition to struct x { } __packed;

diffstat:

 usr.bin/xlint/lint1/cgram.y |   7 ++++---
 usr.bin/xlint/lint1/decl.c  |  30 ++++++++++++++++++------------
 usr.bin/xlint/lint1/lint1.h |   3 ++-
 usr.bin/xlint/lint1/tree.c  |   6 +++---
 4 files changed, 27 insertions(+), 19 deletions(-)

diffs (158 lines):

diff -r aac86dc4127a -r f371d7ebe933 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Fri Oct 02 18:52:13 2009 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Fri Oct 02 19:01:13 2009 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.45 2009/10/02 15:03:45 christos Exp $ */
+/* $NetBSD: cgram.y,v 1.46 2009/10/02 19:01:13 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.45 2009/10/02 15:03:45 christos Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.46 2009/10/02 19:01:13 christos Exp $");
 #endif
 
 #include <stdlib.h>
@@ -591,7 +591,8 @@
        ;
 
 struct:
-         T_SOU {
+         struct type_attribute
+       | T_SOU {
                symtyp = FTAG;
                pushdecl($1 == STRUCT ? MOS : MOU);
                dcs->d_offset = 0;
diff -r aac86dc4127a -r f371d7ebe933 usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Fri Oct 02 18:52:13 2009 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Fri Oct 02 19:01:13 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.47 2009/10/02 15:03:45 christos Exp $ */
+/* $NetBSD: decl.c,v 1.48 2009/10/02 19:01:13 christos Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.47 2009/10/02 15:03:45 christos Exp $");
+__RCSID("$NetBSD: decl.c,v 1.48 2009/10/02 19:01:13 christos Exp $");
 #endif
 
 #include <sys/param.h>
@@ -484,19 +484,13 @@
        }
 }
 
-void
-addpacked(void)
+static void
+setpackedsize(type_t *tp)
 {
        str_t *sp;
        sym_t *mem;
-       type_t *tp = dcs->d_type;
        char buf[256];
 
-       if (tp == NULL)
-               LERROR("no type attr");
-
-       tp->t_ispacked = 1;
-
        switch (tp->t_tspec) {
        case STRUCT:
                sp = tp->t_str;
@@ -519,6 +513,15 @@
        }
 }
 
+void
+addpacked(void)
+{
+       if (dcs->d_type == NULL) {
+               dcs->d_ispacked = 1;
+       } else
+               setpackedsize(dcs->d_type);
+}
+
 /*
  * Remember a qualifier which is part of the declaration specifiers
  * (and not the declarator) in the top element of the declaration stack.
@@ -1624,6 +1627,7 @@
                if (tag->s_scl == NOSCL) {
                        tag->s_scl = scl;
                        tag->s_type = tp = getblk(sizeof (type_t));
+                       tp->t_ispacked = dcs->d_ispacked;
                } else {
                        tp = tag->s_type;
                }
@@ -1733,7 +1737,6 @@
 }
 
 /*
- * Completes the type of a tag in a struct/union/enum declaration.
  * tp points to the type of the, tag, fmem to the list of members/enums.
  */
 type_t *
@@ -1751,8 +1754,11 @@
                align(dcs->d_stralign, 0);
                sp = tp->t_str;
                sp->align = dcs->d_stralign;
-               sp->size = dcs->d_offset;
                sp->memb = fmem;
+               if (tp->t_ispacked)
+                       setpackedsize(tp);
+               else
+                       sp->size = dcs->d_offset;
                if (sp->size == 0) {
                        /* zero sized %s */
                        (void)c99ism(47, ttab[t].tt_name);
diff -r aac86dc4127a -r f371d7ebe933 usr.bin/xlint/lint1/lint1.h
--- a/usr.bin/xlint/lint1/lint1.h       Fri Oct 02 18:52:13 2009 +0000
+++ b/usr.bin/xlint/lint1/lint1.h       Fri Oct 02 19:01:13 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.23 2009/10/02 15:03:45 christos Exp $ */
+/* $NetBSD: lint1.h,v 1.24 2009/10/02 19:01:14 christos Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -329,6 +329,7 @@
        u_int   d_proto : 1;    /* current funct. decl. is prototype */
        u_int   d_notyp : 1;    /* set if no type specifier was present */
        u_int   d_asm : 1;      /* set if d_ctx == AUTO and asm() present */
+       u_int   d_ispacked : 1; /* packed */
        type_t  *d_tagtyp;      /* tag during member declaration */
        sym_t   *d_fargs;       /* list of arguments during function def. */
        pos_t   d_fdpos;        /* position of function definition */
diff -r aac86dc4127a -r f371d7ebe933 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Fri Oct 02 18:52:13 2009 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Fri Oct 02 19:01:13 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.59 2009/05/02 16:10:49 christos Exp $       */
+/*     $NetBSD: tree.c,v 1.60 2009/10/02 19:01:14 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.59 2009/05/02 16:10:49 christos Exp $");
+__RCSID("$NetBSD: tree.c,v 1.60 2009/10/02 19:01:14 christos Exp $");
 #endif
 
 #include <stdlib.h>
@@ -3093,7 +3093,7 @@
 #else
        st = UINT;
 #endif
-
+printf("size %p = %ld\n", tp, (int64_t)(elem * elsz / CHAR_BIT));
        return (getinode(st, (int64_t)(elem * elsz / CHAR_BIT)));
 }
 



Home | Main Index | Thread Index | Old Index