Module Name:    src
Committed By:   christos
Date:           Tue Oct 13 20:25:21 UTC 2015

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

Log Message:
handle anonymous struct/union members.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/xlint/lint1/decl.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.72 src/usr.bin/xlint/lint1/cgram.y:1.73
--- src/usr.bin/xlint/lint1/cgram.y:1.72	Tue Oct 13 12:09:33 2015
+++ src/usr.bin/xlint/lint1/cgram.y	Tue Oct 13 16:25:21 2015
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.72 2015/10/13 16:09:33 christos Exp $ */
+/* $NetBSD: cgram.y,v 1.73 2015/10/13 20:25:21 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.72 2015/10/13 16:09:33 christos Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.73 2015/10/13 20:25:21 christos Exp $");
 #endif
 
 #include <stdlib.h>
@@ -105,6 +105,14 @@ static inline void RESTORE(const char *f
 #define SAVE(f, l)	olwarn = lwarn
 #define RESTORE(f, l) (void)(olwarn == LWARN_BAD ? (clrwflgs(), 0) : (lwarn = olwarn))
 #endif
+
+/* unbind the anonymous struct members from the struct */
+static void
+anonymize(sym_t *s)
+{
+	for ( ; s; s = s->s_nxt)
+		s->s_styp = NULL;
+}
 %}
 
 %expect 80
@@ -698,14 +706,22 @@ member_declaration:
 		$$ = $4;
 	  }
 	| noclass_declmods deftyp {
+		symtyp = FMOS;
 		/* struct or union member must be named */
-		warning(49);
-		$$ = NULL;
+		if (!Sflag)
+			warning(49);
+		/* add all the members of the anonymous struct/union */
+		$$ = dcs->d_type->t_str->memb;
+		anonymize($$);
 	  }
 	| noclass_declspecs deftyp {
+		symtyp = FMOS;
 		/* struct or union member must be named */
-		warning(49);
-		$$ = NULL;
+		if (!Sflag)
+			warning(49);
+		$$ = dcs->d_type->t_str->memb;
+		/* add all the members of the anonymous struct/union */
+		anonymize($$);
 	  }
 	| error {
 		symtyp = FVFT;

Index: src/usr.bin/xlint/lint1/decl.c
diff -u src/usr.bin/xlint/lint1/decl.c:1.59 src/usr.bin/xlint/lint1/decl.c:1.60
--- src/usr.bin/xlint/lint1/decl.c:1.59	Thu Apr 17 20:20:37 2014
+++ src/usr.bin/xlint/lint1/decl.c	Tue Oct 13 16:25:21 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.59 2014/04/18 00:20:37 christos Exp $ */
+/* $NetBSD: decl.c,v 1.60 2015/10/13 20:25:21 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.59 2014/04/18 00:20:37 christos Exp $");
+__RCSID("$NetBSD: decl.c,v 1.60 2015/10/13 20:25:21 christos Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1778,6 +1778,9 @@ compltag(type_t *tp, sym_t *fmem)
 		} else {
 			n = 0;
 			for (mem = fmem; mem != NULL; mem = mem->s_nxt) {
+				/* bind anonymous members to the structure */
+				if (mem->s_styp == NULL)
+					mem->s_styp = sp;
 				if (mem->s_name != unnamed)
 					n++;
 			}

Reply via email to