Module Name:    src
Committed By:   christos
Date:           Fri Oct  2 19:01:14 UTC 2009

Modified Files:
        src/usr.bin/xlint/lint1: cgram.y decl.c lint1.h tree.c

Log Message:
recognize struct __packed x { }; in addition to struct x { } __packed;


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/xlint/lint1/decl.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/xlint/lint1/lint1.h
cvs rdiff -u -r1.59 -r1.60 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.45 src/usr.bin/xlint/lint1/cgram.y:1.46
--- src/usr.bin/xlint/lint1/cgram.y:1.45	Fri Oct  2 11:03:45 2009
+++ src/usr.bin/xlint/lint1/cgram.y	Fri Oct  2 15:01:13 2009
@@ -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;

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.47 src/usr.bin/xlint/lint1/decl.c:1.48
--- src/usr.bin/xlint/lint1/decl.c:1.47	Fri Oct  2 11:03:45 2009
+++ src/usr.bin/xlint/lint1/decl.c	Fri Oct  2 15:01:13 2009
@@ -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);

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.23 src/usr.bin/xlint/lint1/lint1.h:1.24
--- src/usr.bin/xlint/lint1/lint1.h:1.23	Fri Oct  2 11:03:45 2009
+++ src/usr.bin/xlint/lint1/lint1.h	Fri Oct  2 15:01:14 2009
@@ -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 */

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.59 src/usr.bin/xlint/lint1/tree.c:1.60
--- src/usr.bin/xlint/lint1/tree.c:1.59	Sat May  2 12:10:49 2009
+++ src/usr.bin/xlint/lint1/tree.c	Fri Oct  2 15:01:14 2009
@@ -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)));
 }
 

Reply via email to