Tue Oct 13 20:25:21 2015 UTC ()
handle anonymous struct/union members.


(christos)
diff -r1.72 -r1.73 src/usr.bin/xlint/lint1/cgram.y
diff -r1.59 -r1.60 src/usr.bin/xlint/lint1/decl.c

cvs diff -r1.72 -r1.73 src/usr.bin/xlint/lint1/cgram.y (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/cgram.y 2015/10/13 16:09:33 1.72
+++ src/usr.bin/xlint/lint1/cgram.y 2015/10/13 20:25:21 1.73
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1%{ 1%{
2/* $NetBSD: cgram.y,v 1.72 2015/10/13 16:09:33 christos Exp $ */ 2/* $NetBSD: cgram.y,v 1.73 2015/10/13 20:25:21 christos Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
6 * Copyright (c) 1994, 1995 Jochen Pohl 6 * Copyright (c) 1994, 1995 Jochen Pohl
7 * All Rights Reserved. 7 * All Rights Reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37#if defined(__RCSID) && !defined(lint) 37#if defined(__RCSID) && !defined(lint)
38__RCSID("$NetBSD: cgram.y,v 1.72 2015/10/13 16:09:33 christos Exp $"); 38__RCSID("$NetBSD: cgram.y,v 1.73 2015/10/13 20:25:21 christos Exp $");
39#endif 39#endif
40 40
41#include <stdlib.h> 41#include <stdlib.h>
42#include <string.h> 42#include <string.h>
43#include <limits.h> 43#include <limits.h>
44 44
45#include "lint1.h" 45#include "lint1.h"
46 46
47extern char *yytext; 47extern char *yytext;
48/* 48/*
49 * Contains the level of current declaration. 0 is extern. 49 * Contains the level of current declaration. 0 is extern.
50 * Used for symbol table entries. 50 * Used for symbol table entries.
51 */ 51 */
@@ -95,26 +95,34 @@ static inline void RESTORE(const char *f @@ -95,26 +95,34 @@ static inline void RESTORE(const char *f
95 if (olwarn != LWARN_BAD) { 95 if (olwarn != LWARN_BAD) {
96 lwarn = olwarn; 96 lwarn = olwarn;
97 printf("%s, %d: restore flags %s %zu = %d\n", curr_pos.p_file, 97 printf("%s, %d: restore flags %s %zu = %d\n", curr_pos.p_file,
98 curr_pos.p_line, file, line, lwarn); 98 curr_pos.p_line, file, line, lwarn);
99 olwarn = LWARN_BAD; 99 olwarn = LWARN_BAD;
100 } else 100 } else
101 CLRWFLGS(file, line); 101 CLRWFLGS(file, line);
102} 102}
103#else 103#else
104#define CLRWFLGS(f, l) clrwflgs(), olwarn = LWARN_BAD 104#define CLRWFLGS(f, l) clrwflgs(), olwarn = LWARN_BAD
105#define SAVE(f, l) olwarn = lwarn 105#define SAVE(f, l) olwarn = lwarn
106#define RESTORE(f, l) (void)(olwarn == LWARN_BAD ? (clrwflgs(), 0) : (lwarn = olwarn)) 106#define RESTORE(f, l) (void)(olwarn == LWARN_BAD ? (clrwflgs(), 0) : (lwarn = olwarn))
107#endif 107#endif
 108
 109/* unbind the anonymous struct members from the struct */
 110static void
 111anonymize(sym_t *s)
 112{
 113 for ( ; s; s = s->s_nxt)
 114 s->s_styp = NULL;
 115}
108%} 116%}
109 117
110%expect 80 118%expect 80
111 119
112%union { 120%union {
113 int y_int; 121 int y_int;
114 val_t *y_val; 122 val_t *y_val;
115 sbuf_t *y_sb; 123 sbuf_t *y_sb;
116 sym_t *y_sym; 124 sym_t *y_sym;
117 op_t y_op; 125 op_t y_op;
118 scl_t y_scl; 126 scl_t y_scl;
119 tspec_t y_tspec; 127 tspec_t y_tspec;
120 tqual_t y_tqual; 128 tqual_t y_tqual;
@@ -688,34 +696,42 @@ member_declaration: @@ -688,34 +696,42 @@ member_declaration:
688 /* too late, i know, but getsym() compensates it */ 696 /* too late, i know, but getsym() compensates it */
689 symtyp = FMOS; 697 symtyp = FMOS;
690 } notype_member_decls { 698 } notype_member_decls {
691 symtyp = FVFT; 699 symtyp = FVFT;
692 $$ = $4; 700 $$ = $4;
693 } 701 }
694 | noclass_declspecs deftyp { 702 | noclass_declspecs deftyp {
695 symtyp = FMOS; 703 symtyp = FMOS;
696 } type_member_decls { 704 } type_member_decls {
697 symtyp = FVFT; 705 symtyp = FVFT;
698 $$ = $4; 706 $$ = $4;
699 } 707 }
700 | noclass_declmods deftyp { 708 | noclass_declmods deftyp {
 709 symtyp = FMOS;
701 /* struct or union member must be named */ 710 /* struct or union member must be named */
702 warning(49); 711 if (!Sflag)
703 $$ = NULL; 712 warning(49);
 713 /* add all the members of the anonymous struct/union */
 714 $$ = dcs->d_type->t_str->memb;
 715 anonymize($$);
704 } 716 }
705 | noclass_declspecs deftyp { 717 | noclass_declspecs deftyp {
 718 symtyp = FMOS;
706 /* struct or union member must be named */ 719 /* struct or union member must be named */
707 warning(49); 720 if (!Sflag)
708 $$ = NULL; 721 warning(49);
 722 $$ = dcs->d_type->t_str->memb;
 723 /* add all the members of the anonymous struct/union */
 724 anonymize($$);
709 } 725 }
710 | error { 726 | error {
711 symtyp = FVFT; 727 symtyp = FVFT;
712 $$ = NULL; 728 $$ = NULL;
713 } 729 }
714 ; 730 ;
715 731
716noclass_declspecs: 732noclass_declspecs:
717 clrtyp_typespec { 733 clrtyp_typespec {
718 addtype($1); 734 addtype($1);
719 } 735 }
720 | type_attribute noclass_declspecs 736 | type_attribute noclass_declspecs
721 | noclass_declmods typespec { 737 | noclass_declmods typespec {

cvs diff -r1.59 -r1.60 src/usr.bin/xlint/lint1/decl.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/decl.c 2014/04/18 00:20:37 1.59
+++ src/usr.bin/xlint/lint1/decl.c 2015/10/13 20:25:21 1.60
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: decl.c,v 1.59 2014/04/18 00:20:37 christos Exp $ */ 1/* $NetBSD: decl.c,v 1.60 2015/10/13 20:25:21 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl 5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#if HAVE_NBTOOL_CONFIG_H 35#if HAVE_NBTOOL_CONFIG_H
36#include "nbtool_config.h" 36#include "nbtool_config.h"
37#endif 37#endif
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40#if defined(__RCSID) && !defined(lint) 40#if defined(__RCSID) && !defined(lint)
41__RCSID("$NetBSD: decl.c,v 1.59 2014/04/18 00:20:37 christos Exp $"); 41__RCSID("$NetBSD: decl.c,v 1.60 2015/10/13 20:25:21 christos Exp $");
42#endif 42#endif
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <limits.h> 45#include <limits.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <string.h> 47#include <string.h>
48 48
49#include "lint1.h" 49#include "lint1.h"
50 50
51const char *unnamed = "<unnamed>"; 51const char *unnamed = "<unnamed>";
52 52
53/* shared type structures for arithmtic types and void */ 53/* shared type structures for arithmtic types and void */
54static type_t *typetab; 54static type_t *typetab;
@@ -1768,26 +1768,29 @@ compltag(type_t *tp, sym_t *fmem) @@ -1768,26 +1768,29 @@ compltag(type_t *tp, sym_t *fmem)
1768 sp = tp->t_str; 1768 sp = tp->t_str;
1769 sp->align = dcs->d_stralign; 1769 sp->align = dcs->d_stralign;
1770 sp->memb = fmem; 1770 sp->memb = fmem;
1771 if (tp->t_ispacked) 1771 if (tp->t_ispacked)
1772 setpackedsize(tp); 1772 setpackedsize(tp);
1773 else 1773 else
1774 sp->size = dcs->d_offset; 1774 sp->size = dcs->d_offset;
1775 if (sp->size == 0) { 1775 if (sp->size == 0) {
1776 /* zero sized %s */ 1776 /* zero sized %s */
1777 (void)c99ism(47, ttab[t].tt_name); 1777 (void)c99ism(47, ttab[t].tt_name);
1778 } else { 1778 } else {
1779 n = 0; 1779 n = 0;
1780 for (mem = fmem; mem != NULL; mem = mem->s_nxt) { 1780 for (mem = fmem; mem != NULL; mem = mem->s_nxt) {
 1781 /* bind anonymous members to the structure */
 1782 if (mem->s_styp == NULL)
 1783 mem->s_styp = sp;
1781 if (mem->s_name != unnamed) 1784 if (mem->s_name != unnamed)
1782 n++; 1785 n++;
1783 } 1786 }
1784 if (n == 0) { 1787 if (n == 0) {
1785 /* %s has no named members */ 1788 /* %s has no named members */
1786 warning(65, 1789 warning(65,
1787 t == STRUCT ? "structure" : "union"); 1790 t == STRUCT ? "structure" : "union");
1788 } 1791 }
1789 } 1792 }
1790 } else { 1793 } else {
1791 tp->t_enum->elem = fmem; 1794 tp->t_enum->elem = fmem;
1792 } 1795 }
1793 return (tp); 1796 return (tp);