1 /* $NetBSD: decl.c,v 1.50 2009/10/02 21:04:03 christos Exp $ */
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by Jochen Pohl for
20 * 4. The name of the author may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 #if HAVE_NBTOOL_CONFIG_H
36 #include "nbtool_config.h"
39 #include <sys/cdefs.h>
40 #if defined(__RCSID) && !defined(lint)
41 __RCSID("$NetBSD: decl.c,v 1.50 2009/10/02 21:04:03 christos Exp $");
44 #include <sys/param.h>
51 const char *unnamed
= "<unnamed>";
53 /* shared type structures for arithmtic types and void */
54 static type_t
*typetab
;
56 /* value of next enumerator during declaration of enum types */
60 * pointer to top element of a stack which contains informations local
61 * to nested declarations
65 static type_t
*tdeferr(type_t
*, tspec_t
);
66 static void settdsym(type_t
*, sym_t
*);
67 static tspec_t
mrgtspec(tspec_t
, tspec_t
);
68 static void align(int, int);
69 static sym_t
*newtag(sym_t
*, scl_t
, int, int);
70 static int eqargs(type_t
*, type_t
*, int *);
71 static int mnoarg(type_t
*, int *);
72 static int chkosdef(sym_t
*, sym_t
*);
73 static int chkptdecl(sym_t
*, sym_t
*);
74 static sym_t
*nsfunc(sym_t
*, sym_t
*);
75 static void osfunc(sym_t
*, sym_t
*);
76 static void ledecl(sym_t
*);
77 static int chkinit(sym_t
*);
78 static void chkausg(int, sym_t
*);
79 static void chkvusg(int, sym_t
*);
80 static void chklusg(sym_t
*);
81 static void chktusg(sym_t
*);
82 static void chkglvar(sym_t
*);
83 static void glchksz(sym_t
*);
86 * initializes all global vars used in declarations
93 /* declaration stack */
94 dcs
= xcalloc(1, sizeof (dinfo_t
));
96 dcs
->d_ldlsym
= &dcs
->d_dlsyms
;
98 /* type information and classification */
101 /* shared type structures */
102 typetab
= xcalloc(NTSPEC
, sizeof (type_t
));
103 for (i
= 0; i
< NTSPEC
; i
++)
104 typetab
[i
].t_tspec
= NOTSPEC
;
105 typetab
[BOOL
].t_tspec
= BOOL
;
106 typetab
[CHAR
].t_tspec
= CHAR
;
107 typetab
[SCHAR
].t_tspec
= SCHAR
;
108 typetab
[UCHAR
].t_tspec
= UCHAR
;
109 typetab
[SHORT
].t_tspec
= SHORT
;
110 typetab
[USHORT
].t_tspec
= USHORT
;
111 typetab
[INT
].t_tspec
= INT
;
112 typetab
[UINT
].t_tspec
= UINT
;
113 typetab
[LONG
].t_tspec
= LONG
;
114 typetab
[ULONG
].t_tspec
= ULONG
;
115 typetab
[QUAD
].t_tspec
= QUAD
;
116 typetab
[UQUAD
].t_tspec
= UQUAD
;
117 typetab
[FLOAT
].t_tspec
= FLOAT
;
118 typetab
[DOUBLE
].t_tspec
= DOUBLE
;
119 typetab
[LDOUBLE
].t_tspec
= LDOUBLE
;
120 typetab
[FCOMPLEX
].t_tspec
= FCOMPLEX
;
121 typetab
[DCOMPLEX
].t_tspec
= DCOMPLEX
;
122 typetab
[LCOMPLEX
].t_tspec
= LCOMPLEX
;
123 typetab
[COMPLEX
].t_tspec
= COMPLEX
;
124 typetab
[VOID
].t_tspec
= VOID
;
126 * Next two are not real types. They are only used by the parser
127 * to return keywords "signed" and "unsigned"
129 typetab
[SIGNED
].t_tspec
= SIGNED
;
130 typetab
[UNSIGN
].t_tspec
= UNSIGN
;
134 * Returns a shared type structure vor arithmetic types and void.
136 * It's important do duplicate this structure (using duptyp() or tdupdyp())
137 * if it is to be modified (adding qualifiers or anything else).
143 return (&typetab
[t
]);
147 duptyp(const type_t
*tp
)
151 ntp
= getblk(sizeof (type_t
));
152 STRUCT_ASSIGN(*ntp
, *tp
);
157 * Use tduptyp() instead of duptyp() inside expressions (if the
158 * allocated memory should be freed after the expr).
161 tduptyp(const type_t
*tp
)
165 ntp
= tgetblk(sizeof (type_t
));
166 STRUCT_ASSIGN(*ntp
, *tp
);
171 * Returns 1 if the argument is void or an incomplete array,
172 * struct, union or enum type.
179 if ((t
= tp
->t_tspec
) == VOID
) {
181 } else if (t
== ARRAY
) {
182 return (tp
->t_aincompl
);
183 } else if (t
== STRUCT
|| t
== UNION
) {
184 return (tp
->t_str
->sincompl
);
185 } else if (t
== ENUM
) {
186 return (tp
->t_enum
->eincompl
);
192 * Set the flag for (in)complete array, struct, union or enum
196 setcompl(type_t
*tp
, int ic
)
200 if ((t
= tp
->t_tspec
) == ARRAY
) {
202 } else if (t
== STRUCT
|| t
== UNION
) {
203 tp
->t_str
->sincompl
= ic
;
206 LERROR("setcompl()");
207 tp
->t_enum
->eincompl
= ic
;
212 * Remember the storage class of the current declaration in dcs->d_scl
213 * (the top element of the declaration stack) and detect multiple
223 warning(10, "inline");
227 if (dcs
->d_type
!= NULL
|| dcs
->d_atyp
!= NOTSPEC
||
228 dcs
->d_smod
!= NOTSPEC
|| dcs
->d_lmod
!= NOTSPEC
) {
229 /* storage class after type is obsolescent */
232 if (dcs
->d_scl
== NOSCL
) {
236 * multiple storage classes. An error will be reported in
244 * Remember the type, modifier or typedef name returned by the parser
245 * in *dcs (top element of decl stack). This information is used in
246 * deftyp() to build the type used for all declarators in this
249 * Is tp->t_typedef 1, the type comes from a previously defined typename.
250 * Otherwise it comes from a type specifier (int, long, ...) or a
251 * struct/union/enum tag.
259 printf("addtype %s\n", tyname(buf
, sizeof(buf
), tp
));
262 if (dcs
->d_type
!= NULL
|| dcs
->d_atyp
!= NOTSPEC
||
263 dcs
->d_lmod
!= NOTSPEC
|| dcs
->d_smod
!= NOTSPEC
) {
265 * something like "typedef int a; int a b;"
266 * This should not happen with current grammar.
276 if (t
== STRUCT
|| t
== UNION
|| t
== ENUM
) {
278 * something like "int struct a ..."
279 * struct/union/enum with anything else is not allowed
281 if (dcs
->d_type
!= NULL
|| dcs
->d_atyp
!= NOTSPEC
||
282 dcs
->d_lmod
!= NOTSPEC
|| dcs
->d_smod
!= NOTSPEC
) {
284 * remember that an error must be reported in
288 dcs
->d_atyp
= dcs
->d_lmod
= dcs
->d_smod
= NOTSPEC
;
294 if (dcs
->d_type
!= NULL
&& !dcs
->d_type
->t_typedef
) {
296 * something like "struct a int"
297 * struct/union/enum with anything else is not allowed
304 if (dcs
->d_cmod
== FLOAT
)
306 else if (dcs
->d_cmod
== DOUBLE
) {
309 error(308, basictyname(dcs
->d_cmod
));
310 dcs
->d_cmod
= NOTSPEC
;
313 if (t
== LONG
&& dcs
->d_lmod
== LONG
) {
314 /* "long long" or "long ... long" */
316 dcs
->d_lmod
= NOTSPEC
;
318 /* %s C does not support 'long long' */
319 (void)c99ism(265, tflag
? "traditional" : "c89");
322 if (dcs
->d_type
!= NULL
&& dcs
->d_type
->t_typedef
) {
323 /* something like "typedef int a; a long ..." */
324 dcs
->d_type
= tdeferr(dcs
->d_type
, t
);
328 /* now it can be only a combination of arithmetic types and void */
329 if (t
== SIGNED
|| t
== UNSIGN
) {
330 /* remember specifiers "signed" & "unsigned" in dcs->d_smod */
331 if (dcs
->d_smod
!= NOTSPEC
)
333 * more than one "signed" and/or "unsigned"; print
334 * an error in deftyp()
338 } else if (t
== SHORT
|| t
== LONG
|| t
== QUAD
) {
340 * remember specifiers "short", "long" and "long long" in
343 if (dcs
->d_lmod
!= NOTSPEC
)
344 /* more than one, print error in deftyp() */
347 } else if (t
== FLOAT
|| t
== DOUBLE
) {
348 if (dcs
->d_lmod
== NOTSPEC
|| dcs
->d_lmod
== LONG
) {
349 if (dcs
->d_cmod
!= NOTSPEC
350 || (t
== FLOAT
&& dcs
->d_lmod
== LONG
))
354 if (dcs
->d_atyp
!= NOTSPEC
)
360 * remember specifiers "void", "char", "int",
361 * or "_Complex" int dcs->d_atyp
363 if (dcs
->d_atyp
!= NOTSPEC
)
364 /* more than one, print error in deftyp() */
371 * called if a list of declaration specifiers contains a typedef name
372 * and other specifiers (except struct, union, enum, typedef name)
375 tdeferr(type_t
*td
, tspec_t t
)
384 if (t2
== CHAR
|| t2
== SHORT
|| t2
== INT
|| t2
== LONG
||
387 /* modifying typedef with ... */
388 warning(5, ttab
[t
].tt_name
);
389 td
= duptyp(gettyp(mrgtspec(t2
, t
)));
395 if (t2
== INT
|| t2
== UINT
) {
396 /* modifying typedef with ... */
398 td
= duptyp(gettyp(t2
== INT
? SHORT
: USHORT
));
404 if (t2
== INT
|| t2
== UINT
|| t2
== LONG
|| t2
== ULONG
||
405 t2
== FLOAT
|| t2
== DOUBLE
|| t2
== DCOMPLEX
) {
406 /* modifying typedef with ... */
410 } else if (t2
== UINT
) {
412 } else if (t2
== LONG
) {
414 } else if (t2
== ULONG
) {
416 } else if (t2
== FLOAT
) {
418 } else if (t2
== DOUBLE
) {
419 td
= gettyp(LDOUBLE
);
420 } else if (t2
== DCOMPLEX
) {
421 td
= gettyp(LCOMPLEX
);
428 /* LINTED (enumeration values not handled in switch) */
456 case NTSPEC
: /* this value unused */
460 /* Anything other is not accepted. */
467 * Remember the symbol of a typedef name (2nd arg) in a struct, union
468 * or enum tag if the typedef name is the first defined for this tag.
470 * If the tag is unnamed, the typdef name is used for identification
471 * of this tag in lint2. Although its possible that more than one typedef
472 * name is defined for one tag, the first name defined should be unique
473 * if the tag is unnamed.
476 settdsym(type_t
*tp
, sym_t
*sym
)
480 if ((t
= tp
->t_tspec
) == STRUCT
|| t
== UNION
) {
481 if (tp
->t_str
->stdef
== NULL
)
482 tp
->t_str
->stdef
= sym
;
483 } else if (t
== ENUM
) {
484 if (tp
->t_enum
->etdef
== NULL
)
485 tp
->t_enum
->etdef
= sym
;
490 setpackedsize(type_t
*tp
)
496 switch (tp
->t_tspec
) {
501 for (mem
= sp
->memb
; mem
!= NULL
; mem
= mem
->s_nxt
) {
502 if (mem
->s_type
->t_isfield
) {
503 size_t len
= mem
->s_type
->t_flen
;
504 while (mem
&& mem
->s_type
->t_isfield
) {
505 len
+= mem
->s_type
->t_flen
;
508 len
= ((len
+ INT_SIZE
- 1) /
509 INT_SIZE
) * INT_SIZE
;
514 size_t x
= (size_t)tsize(mem
->s_type
);
515 if (tp
->t_tspec
== STRUCT
)
517 else if (x
> sp
->size
)
522 warning(326, "packed", tyname(buf
, sizeof(buf
), tp
));
530 if (dcs
->d_type
== NULL
)
533 setpackedsize(dcs
->d_type
);
537 * Remember a qualifier which is part of the declaration specifiers
538 * (and not the declarator) in the top element of the declaration stack.
539 * Also detect multiple qualifiers of the same kind.
541 * The remembered qualifier is used by deftyp() to construct the type
542 * for all declarators.
551 warning(10, "const");
557 if (dcs
->d_volatile
) {
559 warning(10, "volatile");
566 * Go to the next declaration level (structs, nested structs, blocks,
567 * argument declaration lists ...)
574 /* put a new element on the declaration stack */
575 di
= xcalloc(1, sizeof (dinfo_t
));
579 di
->d_ldlsym
= &di
->d_dlsyms
;
581 (void)printf("pushdecl(%p %d)\n", dcs
, (int)sc
);
586 * Go back to previous declaration level
594 (void)printf("popdecl(%p %d)\n", dcs
, (int)dcs
->d_ctx
);
596 if (dcs
->d_nxt
== NULL
)
602 /* there is nothing after external declarations */
609 * Symbols declared in (nested) structs or enums are
610 * part of the next level (they are removed from the
611 * symbol table if the symbols of the outher level are
614 if ((*dcs
->d_ldlsym
= di
->d_dlsyms
) != NULL
)
615 dcs
->d_ldlsym
= di
->d_ldlsym
;
619 * All symbols in dcs->d_dlsyms are introduced in old style
620 * argument declarations (it's not clean, but possible).
621 * They are appended to the list of symbols declared in
622 * an old style argument identifier list or a new style
623 * parameter type list.
625 if (di
->d_dlsyms
!= NULL
) {
626 *di
->d_ldlsym
= dcs
->d_fpsyms
;
627 dcs
->d_fpsyms
= di
->d_dlsyms
;
633 * Append all symbols declared in the abstract declaration
634 * to the list of symbols declared in the surounding decl.
636 * XXX I'm not sure whether they should be removed from the
637 * symbol table now or later.
639 if ((*dcs
->d_ldlsym
= di
->d_dlsyms
) != NULL
)
640 dcs
->d_ldlsym
= di
->d_ldlsym
;
643 /* check usage of local vars */
647 /* usage of arguments will be checked by funcend() */
648 rmsyms(di
->d_dlsyms
);
657 * Set flag d_asm in all declaration stack elements up to the
660 * This is used to mark compound statements which have, possibly in
661 * nested compound statements, asm statements. For these compound
662 * statements no warnings about unused or unitialized variables are
665 * There is no need to clear d_asm in dinfo structs with context AUTO,
666 * because these structs are freed at the end of the compound statement.
667 * But it must be cleard in the outermost dinfo struct, which has
668 * context EXTERN. This could be done in clrtyp() and would work for
669 * C, but not for C++ (due to mixed statements and declarations). Thus
670 * we clear it in glclup(), which is used to do some cleanup after
671 * global declarations/definitions.
678 for (di
= dcs
; di
!= NULL
; di
= di
->d_nxt
)
683 * Clean all elements of the top element of declaration stack which
684 * will be used by the next declaration
690 dcs
->d_atyp
= dcs
->d_cmod
= dcs
->d_smod
= dcs
->d_lmod
= NOTSPEC
;
693 dcs
->d_const
= dcs
->d_volatile
= 0;
695 dcs
->d_mscl
= dcs
->d_terr
= 0;
701 * Create a type structure from the informations gathered in
702 * the declaration stack.
703 * Complain about storage classes which are not possible in current
713 t
= dcs
->d_atyp
; /* BOOL, CHAR, INT, COMPLEX, VOID */
714 s
= dcs
->d_smod
; /* SIGNED, UNSIGNED */
715 l
= dcs
->d_lmod
; /* SHORT, LONG, QUAD */
716 c
= dcs
->d_cmod
; /* FLOAT, DOUBLE */
720 if (t
== NOTSPEC
&& s
== NOTSPEC
&& l
== NOTSPEC
&& c
== NOTSPEC
&&
723 if (t
== NOTSPEC
&& s
== NOTSPEC
&& (l
== NOTSPEC
|| l
== LONG
) &&
727 if (tp
!= NULL
&& (t
!= NOTSPEC
|| s
!= NOTSPEC
|| l
!= NOTSPEC
)) {
728 /* should never happen */
754 /* use 'double' instead of ... */
763 /* 'long double' is illegal in ... */
772 /* 'long double' is illegal in ... */
783 if (t
!= INT
&& t
!= CHAR
&& (s
!= NOTSPEC
|| l
!= NOTSPEC
)) {
789 dcs
->d_type
= gettyp(mrgtspec(t
, s
));
793 /* only one storage class allowed */
797 /* illegal type combination */
801 if (dcs
->d_ctx
== EXTERN
) {
802 if (scl
== REG
|| scl
== AUTO
) {
803 /* illegal storage class */
807 } else if (dcs
->d_ctx
== ARG
|| dcs
->d_ctx
== PARG
) {
808 if (scl
!= NOSCL
&& scl
!= REG
) {
809 /* only "register" valid ... */
817 if (dcs
->d_const
&& dcs
->d_type
->t_const
) {
818 if (!dcs
->d_type
->t_typedef
)
820 /* typedef already qualified with "%s" */
821 warning(68, "const");
823 if (dcs
->d_volatile
&& dcs
->d_type
->t_volatile
) {
824 if (!dcs
->d_type
->t_typedef
)
826 /* typedef already qualified with "%s" */
827 warning(68, "volatile");
830 if (dcs
->d_const
|| dcs
->d_volatile
) {
831 dcs
->d_type
= duptyp(dcs
->d_type
);
832 dcs
->d_type
->t_const
|= dcs
->d_const
;
833 dcs
->d_type
->t_volatile
|= dcs
->d_volatile
;
838 * Merge type specifiers (char, ..., long long, signed, unsigned).
841 mrgtspec(tspec_t t
, tspec_t s
)
844 if (s
== SIGNED
|| s
== UNSIGN
) {
846 t
= s
== SIGNED
? SCHAR
: UCHAR
;
847 } else if (t
== SHORT
) {
848 t
= s
== SIGNED
? SHORT
: USHORT
;
849 } else if (t
== INT
) {
850 t
= s
== SIGNED
? INT
: UINT
;
851 } else if (t
== LONG
) {
852 t
= s
== SIGNED
? LONG
: ULONG
;
853 } else if (t
== QUAD
) {
854 t
= s
== SIGNED
? QUAD
: UQUAD
;
862 * Return the length of a type in bit.
864 * Printing a message if the outhermost dimension of an array is 0 must
865 * be done by the caller. All other problems are reported by length()
866 * if name is not NULL.
869 length(type_t
*tp
, const char *name
)
874 while (tp
&& tp
->t_tspec
== ARRAY
) {
881 switch (tp
->t_tspec
) {
883 /* compiler takes size of function */
888 if (incompl(tp
) && name
!= NULL
) {
889 /* incomplete structure or union %s: %s */
890 error(31, tp
->t_str
->stag
->s_name
, name
);
892 elsz
= tp
->t_str
->size
;
895 if (incompl(tp
) && name
!= NULL
) {
896 /* incomplete enum type: %s */
901 elsz
= size(tp
->t_tspec
);
906 return (elem
* elsz
);
910 * Get the alignment of the given Type in bits.
918 while (tp
&& tp
->t_tspec
== ARRAY
)
924 if ((t
= tp
->t_tspec
) == STRUCT
|| t
== UNION
) {
925 a
= tp
->t_str
->align
;
926 } else if (t
== FUNC
) {
927 /* compiler takes alignment of function */
929 a
= ALIGN(1) * CHAR_BIT
;
931 if ((a
= size(t
)) == 0) {
933 } else if (a
> ALIGN(1) * CHAR_BIT
) {
934 a
= ALIGN(1) * CHAR_BIT
;
937 if (a
< CHAR_BIT
|| a
> ALIGN(1) * CHAR_BIT
)
938 LERROR("getbound()");
943 * Concatenate two lists of symbols by s_nxt. Used by declarations of
944 * struct/union/enum elements and parameters.
947 lnklst(sym_t
*l1
, sym_t
*l2
)
951 if ((l
= l1
) == NULL
)
953 while (l1
->s_nxt
!= NULL
)
960 * Check if the type of the given symbol is valid and print an error
961 * message if it is not.
964 * - arrays of incomlete types or functions
965 * - functions returning arrays or functions
966 * - void types other than type of function or pointer
976 while ((tp
= *tpp
) != NULL
) {
979 * If this is the type of an old style function definition,
980 * a better warning is printed in funcdef().
982 if (t
== FUNC
&& !tp
->t_proto
&&
983 !(to
== NOTSPEC
&& sym
->s_osdef
)) {
985 /* function declaration is not a prototype */
989 if (t
== FUNC
|| t
== ARRAY
) {
990 /* function returns illegal type */
993 *tpp
= incref(*tpp
, PTR
);
995 *tpp
= incref((*tpp
)->t_subt
, PTR
);
998 } else if (tp
->t_const
|| tp
->t_volatile
) {
999 if (sflag
) { /* XXX oder better !tflag ? */
1000 /* function cannot return const... */
1004 } if (to
== ARRAY
) {
1006 /* array of function is illegal */
1010 } else if (t
== ARRAY
&& tp
->t_dim
== 0) {
1011 /* null dimension */
1014 } else if (t
== VOID
) {
1015 /* illegal use of void */
1018 #if 0 /* errors are produced by length() */
1019 } else if (incompl(tp
)) {
1020 /* array of incomplete type */
1028 } else if (to
== NOTSPEC
&& t
== VOID
) {
1029 if (dcs
->d_ctx
== PARG
) {
1030 if (sym
->s_scl
!= ABSTRACT
) {
1031 if (sym
->s_name
== unnamed
)
1033 /* void param cannot have name: %s */
1034 error(61, sym
->s_name
);
1037 } else if (dcs
->d_ctx
== ABSTRACT
) {
1039 } else if (sym
->s_scl
!= TYPEDEF
) {
1040 /* void type for %s */
1041 error(19, sym
->s_name
);
1045 if (t
== VOID
&& to
!= PTR
) {
1046 if (tp
->t_const
|| tp
->t_volatile
) {
1047 /* inappropriate qualifiers with "void" */
1049 tp
->t_const
= tp
->t_volatile
= 0;
1058 * Process the declarator of a struct/union element.
1061 decl1str(sym_t
*dsym
)
1066 int o
= 0; /* Appease gcc */
1069 if ((sc
= dsym
->s_scl
) != MOS
&& sc
!= MOU
)
1070 LERROR("decl1str()");
1072 if (dcs
->d_rdcsym
!= NULL
) {
1073 if ((sc
= dcs
->d_rdcsym
->s_scl
) != MOS
&& sc
!= MOU
)
1074 /* should be ensured by storesym() */
1075 LERROR("decl1str()");
1076 if (dsym
->s_styp
== dcs
->d_rdcsym
->s_styp
) {
1077 /* duplicate member name: %s */
1078 error(33, dsym
->s_name
);
1079 rmsym(dcs
->d_rdcsym
);
1085 t
= (tp
= dsym
->s_type
)->t_tspec
;
1087 if (dsym
->s_field
) {
1091 * only unsigned und signed int are protable bit-field types
1092 *(at least in ANSI C, in traditional C only unsigned int)
1094 if (t
== CHAR
|| t
== UCHAR
|| t
== SCHAR
||
1095 t
== SHORT
|| t
== USHORT
|| t
== ENUM
) {
1096 if (bitfieldtype_ok
== 0) {
1100 * bit-field type '%s' invalid in
1104 tyname(buf
, sizeof(buf
), tp
));
1106 /* nonportable bit-field type */
1110 } else if (t
== INT
&& dcs
->d_smod
== NOTSPEC
) {
1111 if (pflag
&& bitfieldtype_ok
== 0) {
1112 /* nonportable bit-field type */
1115 } else if (t
!= INT
&& t
!= UINT
) {
1117 * Non-integer types are always illegal for
1118 * bitfields, regardless of BITFIELDTYPE.
1119 * Integer types not dealt with above are
1120 * okay only if BITFIELDTYPE is in effect.
1122 if (bitfieldtype_ok
== 0 || isityp(t
) == 0) {
1123 /* illegal bit-field type */
1126 dsym
->s_type
= tp
= duptyp(gettyp(t
= INT
));
1127 if ((tp
->t_flen
= sz
) > size(t
))
1128 tp
->t_flen
= size(t
);
1131 if ((len
= tp
->t_flen
) < 0 || len
> (ssize_t
)size(t
)) {
1132 /* illegal bit-field size */
1134 tp
->t_flen
= size(t
);
1135 } else if (len
== 0 && dsym
->s_name
!= unnamed
) {
1136 /* zero size bit-field */
1138 tp
->t_flen
= size(t
);
1140 if (dsym
->s_scl
== MOU
) {
1141 /* illegal use of bit-field */
1143 dsym
->s_type
->t_isfield
= 0;
1146 } else if (t
== FUNC
) {
1147 /* function illegal in structure or union */
1149 dsym
->s_type
= tp
= incref(tp
, t
= PTR
);
1153 * bit-fields of length 0 are not warned about because length()
1154 * does not return the length of the bit-field but the length
1155 * of the type the bit-field is packed in (its ok)
1157 if ((sz
= length(dsym
->s_type
, dsym
->s_name
)) == 0) {
1158 if (t
== ARRAY
&& dsym
->s_type
->t_dim
== 0) {
1159 /* illegal zero sized structure member: %s */
1160 c99ism(39, dsym
->s_name
);
1164 if (dcs
->d_ctx
== MOU
) {
1168 if (dsym
->s_field
) {
1169 align(getbound(tp
), tp
->t_flen
);
1170 dsym
->s_value
.v_quad
= (dcs
->d_offset
/ size(t
)) * size(t
);
1171 tp
->t_foffs
= dcs
->d_offset
- (int)dsym
->s_value
.v_quad
;
1172 dcs
->d_offset
+= tp
->t_flen
;
1174 align(getbound(tp
), 0);
1175 dsym
->s_value
.v_quad
= dcs
->d_offset
;
1176 dcs
->d_offset
+= sz
;
1178 if (dcs
->d_ctx
== MOU
) {
1179 if (o
> dcs
->d_offset
)
1186 * Clear the BITFIELDTYPE indicator after processing each
1187 * structure element.
1189 bitfieldtype_ok
= 0;
1195 * Aligns next structure element as required.
1197 * al contains the required alignment, len the length of a bit-field.
1200 align(int al
, int len
)
1205 * The alignment of the current element becomes the alignment of
1206 * the struct/union if it is larger than the current alignment
1207 * of the struct/union.
1209 if (al
> dcs
->d_stralign
)
1210 dcs
->d_stralign
= al
;
1212 no
= (dcs
->d_offset
+ (al
- 1)) & ~(al
- 1);
1213 if (len
== 0 || dcs
->d_offset
+ len
> no
)
1218 * Remember the width of the field in its type structure.
1221 bitfield(sym_t
*dsym
, int len
)
1225 dsym
= getblk(sizeof (sym_t
));
1226 dsym
->s_name
= unnamed
;
1227 dsym
->s_kind
= FMOS
;
1229 dsym
->s_type
= gettyp(UINT
);
1230 dsym
->s_blklev
= -1;
1232 dsym
->s_type
= duptyp(dsym
->s_type
);
1233 dsym
->s_type
->t_isfield
= 1;
1234 dsym
->s_type
->t_flen
= len
;
1240 * Collect informations about a sequence of asterisks and qualifiers
1241 * in a list of type pqinf_t.
1242 * Qualifiers refer always to the left asterisk. The rightmost asterisk
1243 * will be at the top of the list.
1246 mergepq(pqinf_t
*p1
, pqinf_t
*p2
)
1250 if (p2
->p_pcnt
!= 0) {
1251 /* left '*' at the end of the list */
1252 for (p
= p2
; p
->p_nxt
!= NULL
; p
= p
->p_nxt
)
1260 warning(10, "const");
1264 if (p2
->p_volatile
) {
1265 if (p1
->p_volatile
) {
1267 warning(10, "volatile");
1277 * Followint 3 functions extend the type of a declarator with
1278 * pointer, function and array types.
1280 * The current type is the Type built by deftyp() (dcs->d_type) and
1281 * pointer, function and array types already added for this
1282 * declarator. The new type extension is inserted between both.
1285 addptr(sym_t
*decl
, pqinf_t
*pi
)
1290 tpp
= &decl
->s_type
;
1291 while (*tpp
&& *tpp
!= dcs
->d_type
)
1292 tpp
= &(*tpp
)->t_subt
;
1296 while (pi
!= NULL
) {
1297 *tpp
= tp
= getblk(sizeof (type_t
));
1299 tp
->t_const
= pi
->p_const
;
1300 tp
->t_volatile
= pi
->p_volatile
;
1301 *(tpp
= &tp
->t_subt
) = dcs
->d_type
;
1310 * If a dimension was specified, dim is 1, otherwise 0
1311 * n is the specified dimension
1314 addarray(sym_t
*decl
, int dim
, int n
)
1318 tpp
= &decl
->s_type
;
1319 while (*tpp
&& *tpp
!= dcs
->d_type
)
1320 tpp
= &(*tpp
)->t_subt
;
1324 *tpp
= tp
= getblk(sizeof (type_t
));
1325 tp
->t_tspec
= ARRAY
;
1326 tp
->t_subt
= dcs
->d_type
;
1330 /* negative array dimension */
1333 } else if (n
== 0 && dim
) {
1334 /* zero array dimension */
1336 } else if (n
== 0 && !dim
) {
1337 /* is incomplete type */
1345 addfunc(sym_t
*decl
, sym_t
*args
)
1351 /* function prototypes are illegal in traditional C */
1353 args
= nsfunc(decl
, args
);
1359 * The symbols are removed from the symbol table by popdecl() after
1360 * addfunc(). To be able to restore them if this is a function
1361 * definition, a pointer to the list of all symbols is stored in
1362 * dcs->d_nxt->d_fpsyms. Also a list of the arguments (concatenated
1363 * by s_nxt) is stored in dcs->d_nxt->d_fargs.
1364 * (dcs->d_nxt must be used because *dcs is the declaration stack
1365 * element created for the list of params and is removed after
1368 if (dcs
->d_nxt
->d_ctx
== EXTERN
&&
1369 decl
->s_type
== dcs
->d_nxt
->d_type
) {
1370 dcs
->d_nxt
->d_fpsyms
= dcs
->d_dlsyms
;
1371 dcs
->d_nxt
->d_fargs
= args
;
1374 tpp
= &decl
->s_type
;
1375 while (*tpp
&& *tpp
!= dcs
->d_nxt
->d_type
)
1376 tpp
= &(*tpp
)->t_subt
;
1380 *tpp
= tp
= getblk(sizeof (type_t
));
1382 tp
->t_subt
= dcs
->d_nxt
->d_type
;
1383 if ((tp
->t_proto
= dcs
->d_proto
) != 0)
1385 tp
->t_vararg
= dcs
->d_vararg
;
1391 * Called for new style function declarations.
1395 nsfunc(sym_t
*decl
, sym_t
*args
)
1402 * Declarations of structs/unions/enums in param lists are legal,
1405 for (sym
= dcs
->d_dlsyms
; sym
!= NULL
; sym
= sym
->s_dlnxt
) {
1407 if (sc
== STRTAG
|| sc
== UNIONTAG
|| sc
== ENUMTAG
) {
1408 /* dubious tag declaration: %s %s */
1409 warning(85, scltoa(sc
), sym
->s_name
);
1414 for (arg
= args
; arg
!= NULL
; arg
= arg
->s_nxt
) {
1415 if (arg
->s_type
->t_tspec
== VOID
) {
1416 if (n
> 1 || arg
->s_nxt
!= NULL
) {
1417 /* "void" must be sole parameter */
1419 arg
->s_type
= gettyp(INT
);
1425 /* return NULL if first param is VOID */
1426 return (args
!= NULL
&& args
->s_type
->t_tspec
!= VOID
? args
: NULL
);
1430 * Called for old style function declarations.
1433 osfunc(sym_t
*decl
, sym_t
*args
)
1437 * Remember list of params only if this is really seams to be
1438 * a function definition.
1440 if (dcs
->d_nxt
->d_ctx
== EXTERN
&&
1441 decl
->s_type
== dcs
->d_nxt
->d_type
) {
1443 * We assume that this becomes a function definition. If
1444 * we are wrong, its corrected in chkfdef().
1448 decl
->s_args
= args
;
1452 /* function prototype parameters must have types */
1458 * Lists of Identifiers in functions declarations are allowed only if
1459 * its also a function definition. If this is not the case, print a
1463 chkfdef(sym_t
*sym
, int msg
)
1468 /* incomplete or misplaced function definition */
1477 * Process the name in a declarator.
1478 * If the symbol does already exists, a new one is created.
1479 * The symbol becomes one of the storage classes EXTERN, STATIC, AUTO or
1481 * s_def and s_reg are valid after dname().
1488 if (sym
->s_scl
== NOSCL
) {
1489 dcs
->d_rdcsym
= NULL
;
1490 } else if (sym
->s_defarg
) {
1492 dcs
->d_rdcsym
= NULL
;
1494 dcs
->d_rdcsym
= sym
;
1495 sym
= pushdown(sym
);
1498 switch (dcs
->d_ctx
) {
1502 sym
->s_styp
= dcs
->d_tagtyp
->t_str
;
1504 sym
->s_value
.v_tspec
= INT
;
1509 * static and external symbols without "extern" are
1510 * considered to be tentative defined, external
1511 * symbols with "extern" are declared, and typedef names
1512 * are defined. Tentative defined and declared symbols
1513 * may become defined if an initializer is present or
1514 * this is a function definition.
1516 if ((sc
= dcs
->d_scl
) == NOSCL
) {
1519 } else if (sc
== STATIC
) {
1521 } else if (sc
== TYPEDEF
) {
1523 } else if (sc
== EXTERN
) {
1533 if ((sc
= dcs
->d_scl
) == NOSCL
) {
1535 } else if (sc
== REG
) {
1544 if ((sc
= dcs
->d_scl
) == NOSCL
) {
1546 * XXX somewhat ugly because we dont know whether
1547 * this is AUTO or EXTERN (functions). If we are
1548 * wrong it must be corrected in decl1loc(), where
1549 * we have the necessary type information.
1553 } else if (sc
== AUTO
|| sc
== STATIC
|| sc
== TYPEDEF
) {
1555 } else if (sc
== REG
) {
1559 } else if (sc
== EXTERN
) {
1570 sym
->s_type
= dcs
->d_type
;
1572 dcs
->d_fpsyms
= NULL
;
1578 * Process a name in the list of formal params in an old style function
1585 if (sym
->s_scl
!= NOSCL
) {
1586 if (blklev
== sym
->s_blklev
) {
1587 /* redeclaration of formal parameter %s */
1588 error(21, sym
->s_name
);
1592 sym
= pushdown(sym
);
1594 sym
->s_type
= gettyp(INT
);
1597 sym
->s_defarg
= sym
->s_arg
= 1;
1602 * Create the type of a tag.
1604 * tag points to the symbol table entry of the tag
1605 * kind is the kind of the tag (STRUCT/UNION/ENUM)
1606 * decl is 1 if the type of the tag will be completed in this declaration
1607 * (the following token is T_LBRACE)
1608 * semi is 1 if the following token is T_SEMI
1611 mktag(sym_t
*tag
, tspec_t kind
, int decl
, int semi
)
1616 if (kind
== STRUCT
) {
1618 } else if (kind
== UNION
) {
1620 } else if (kind
== ENUM
) {
1627 if (tag
->s_scl
!= NOSCL
) {
1628 tag
= newtag(tag
, scl
, decl
, semi
);
1630 /* a new tag, no empty declaration */
1631 dcs
->d_nxt
->d_nedecl
= 1;
1632 if (scl
== ENUMTAG
&& !decl
) {
1633 if (!tflag
&& (sflag
|| pflag
))
1634 /* forward reference to enum type */
1638 if (tag
->s_scl
== NOSCL
) {
1640 tag
->s_type
= tp
= getblk(sizeof (type_t
));
1641 tp
->t_ispacked
= dcs
->d_ispacked
;
1646 tag
= getblk(sizeof (sym_t
));
1647 tag
->s_name
= unnamed
;
1648 UNIQUE_CURR_POS(tag
->s_dpos
);
1652 tag
->s_type
= tp
= getblk(sizeof (type_t
));
1653 tp
->t_ispacked
= dcs
->d_ispacked
;
1654 dcs
->d_nxt
->d_nedecl
= 1;
1657 if (tp
->t_tspec
== NOTSPEC
) {
1660 tp
->t_str
= getblk(sizeof (str_t
));
1661 tp
->t_str
->align
= CHAR_BIT
;
1662 tp
->t_str
->stag
= tag
;
1665 tp
->t_enum
= getblk(sizeof (enum_t
));
1666 tp
->t_enum
->etag
= tag
;
1668 /* ist unvollstaendiger Typ */
1675 * Checks all possible cases of tag redeclarations.
1676 * decl is 1 if T_LBRACE follows
1677 * semi is 1 if T_SEMI follows
1680 newtag(sym_t
*tag
, scl_t scl
, int decl
, int semi
)
1683 if (tag
->s_blklev
< blklev
) {
1688 /* decl. introduces new type ... */
1689 warning(44, scltoa(scl
), tag
->s_name
);
1690 tag
= pushdown(tag
);
1691 } else if (tag
->s_scl
!= scl
) {
1692 /* base type is really "%s %s" */
1693 warning(45, scltoa(tag
->s_scl
), tag
->s_name
);
1695 dcs
->d_nxt
->d_nedecl
= 1;
1697 /* "struct a { ... } " */
1699 /* redefinition hides earlier one: %s */
1700 warning(43, tag
->s_name
);
1701 tag
= pushdown(tag
);
1702 dcs
->d_nxt
->d_nedecl
= 1;
1703 } else if (tag
->s_scl
!= scl
) {
1704 /* base type is really "%s %s" */
1705 warning(45, scltoa(tag
->s_scl
), tag
->s_name
);
1706 /* declaration introduces new type in ANSI C: %s %s */
1708 warning(44, scltoa(scl
), tag
->s_name
);
1709 tag
= pushdown(tag
);
1710 dcs
->d_nxt
->d_nedecl
= 1;
1713 if (tag
->s_scl
!= scl
) {
1714 /* (%s) tag redeclared */
1715 error(46, scltoa(tag
->s_scl
));
1717 tag
= pushdown(tag
);
1718 dcs
->d_nxt
->d_nedecl
= 1;
1719 } else if (decl
&& !incompl(tag
->s_type
)) {
1720 /* (%s) tag redeclared */
1721 error(46, scltoa(tag
->s_scl
));
1723 tag
= pushdown(tag
);
1724 dcs
->d_nxt
->d_nedecl
= 1;
1725 } else if (semi
|| decl
) {
1726 dcs
->d_nxt
->d_nedecl
= 1;
1738 case EXTERN
: s
= "extern"; break;
1739 case STATIC
: s
= "static"; break;
1740 case AUTO
: s
= "auto"; break;
1741 case REG
: s
= "register"; break;
1742 case TYPEDEF
: s
= "typedef"; break;
1743 case STRTAG
: s
= "struct"; break;
1744 case UNIONTAG
: s
= "union"; break;
1745 case ENUMTAG
: s
= "enum"; break;
1746 default: LERROR("tagttoa()");
1752 * tp points to the type of the, tag, fmem to the list of members/enums.
1755 compltag(type_t
*tp
, sym_t
*fmem
)
1762 /* from now a complete type */
1765 if ((t
= tp
->t_tspec
) != ENUM
) {
1766 align(dcs
->d_stralign
, 0);
1768 sp
->align
= dcs
->d_stralign
;
1773 sp
->size
= dcs
->d_offset
;
1774 if (sp
->size
== 0) {
1776 (void)c99ism(47, ttab
[t
].tt_name
);
1779 for (mem
= fmem
; mem
!= NULL
; mem
= mem
->s_nxt
) {
1780 if (mem
->s_name
!= unnamed
)
1784 /* %s has no named members */
1786 t
== STRUCT
? "structure" : "union");
1790 tp
->t_enum
->elem
= fmem
;
1796 * Processes the name of an enumerator in en enum declaration.
1798 * sym points to the enumerator
1799 * val is the value of the enumerator
1800 * impl is 1 if the value of the enumerator was not explicit specified.
1803 ename(sym_t
*sym
, int val
, int impl
)
1807 if (sym
->s_blklev
== blklev
) {
1808 /* no hflag, because this is illegal!!! */
1810 /* enumeration constant hides parameter: %s */
1811 warning(57, sym
->s_name
);
1813 /* redeclaration of %s */
1814 error(27, sym
->s_name
);
1816 * inside blocks it should not too complicated
1817 * to find the position of the previous
1825 /* redefinition hides earlier one: %s */
1826 warning(43, sym
->s_name
);
1828 sym
= pushdown(sym
);
1830 sym
->s_scl
= ENUMCON
;
1831 sym
->s_type
= dcs
->d_tagtyp
;
1832 sym
->s_value
.v_tspec
= INT
;
1833 sym
->s_value
.v_quad
= val
;
1834 if (impl
&& val
- 1 == INT_MAX
) {
1835 /* overflow in enumeration values: %s */
1836 warning(48, sym
->s_name
);
1843 * Process a single external declarator.
1846 decl1ext(sym_t
*dsym
, int initflg
)
1848 int dowarn
, rval
, redec
;
1855 if (initflg
&& !(initerr
= chkinit(dsym
)))
1859 * Declarations of functions are marked as "tentative" in dname().
1860 * This is wrong because there are no tentative function
1863 if (dsym
->s_type
->t_tspec
== FUNC
&& dsym
->s_def
== TDEF
)
1866 if (dcs
->d_inline
) {
1867 if (dsym
->s_type
->t_tspec
== FUNC
) {
1870 /* variable declared inline: %s */
1871 warning(268, dsym
->s_name
);
1875 /* Write the declaration into the output file */
1876 if (plibflg
&& llibflg
&&
1877 dsym
->s_type
->t_tspec
== FUNC
&& dsym
->s_type
->t_proto
) {
1879 * With both LINTLIBRARY and PROTOLIB the prototyp is
1880 * written as a function definition to the output file.
1882 rval
= dsym
->s_type
->t_subt
->t_tspec
!= VOID
;
1883 outfdef(dsym
, &dsym
->s_dpos
, rval
, 0, NULL
);
1885 outsym(dsym
, dsym
->s_scl
, dsym
->s_def
);
1888 if ((rdsym
= dcs
->d_rdcsym
) != NULL
) {
1891 * If the old symbol stems from a old style function definition
1892 * we have remembered the params in rdsmy->s_args and compare
1893 * them with the params of the prototype.
1895 if (rdsym
->s_osdef
&& dsym
->s_type
->t_proto
) {
1896 redec
= chkosdef(rdsym
, dsym
);
1901 if (!redec
&& !isredec(dsym
, (dowarn
= 0, &dowarn
))) {
1904 /* redeclaration of %s */
1905 (*(sflag
? error
: warning
))(27, dsym
->s_name
);
1906 prevdecl(-1, rdsym
);
1910 * Overtake the rememberd params if the new symbol
1911 * is not a prototype.
1913 if (rdsym
->s_osdef
&& !dsym
->s_type
->t_proto
) {
1914 dsym
->s_osdef
= rdsym
->s_osdef
;
1915 dsym
->s_args
= rdsym
->s_args
;
1916 STRUCT_ASSIGN(dsym
->s_dpos
, rdsym
->s_dpos
);
1920 * Remember the position of the declaration if the
1921 * old symbol was a prototype and the new is not.
1922 * Also remember the position if the old symbol
1923 * was defined and the new is not.
1925 if (rdsym
->s_type
->t_proto
&& !dsym
->s_type
->t_proto
) {
1926 STRUCT_ASSIGN(dsym
->s_dpos
, rdsym
->s_dpos
);
1927 } else if (rdsym
->s_def
== DEF
&& dsym
->s_def
!= DEF
) {
1928 STRUCT_ASSIGN(dsym
->s_dpos
, rdsym
->s_dpos
);
1932 * Copy informations about usage of the name into
1935 cpuinfo(dsym
, rdsym
);
1937 /* Once a name is defined, it remains defined. */
1938 if (rdsym
->s_def
== DEF
)
1941 /* once a function is inline, it remains inline */
1942 if (rdsym
->s_inline
)
1945 compltyp(dsym
, rdsym
);
1952 if (dsym
->s_scl
== TYPEDEF
) {
1953 dsym
->s_type
= duptyp(dsym
->s_type
);
1954 dsym
->s_type
->t_typedef
= 1;
1955 settdsym(dsym
->s_type
, dsym
);
1961 * Copies informations about usage into a new symbol table entry of
1965 cpuinfo(sym_t
*sym
, sym_t
*rdsym
)
1968 sym
->s_spos
= rdsym
->s_spos
;
1969 sym
->s_upos
= rdsym
->s_upos
;
1970 sym
->s_set
= rdsym
->s_set
;
1971 sym
->s_used
= rdsym
->s_used
;
1975 * Prints an error and returns 1 if a symbol is redeclared/redefined.
1976 * Otherwise returns 0 and, in some cases of minor problems, prints
1980 isredec(sym_t
*dsym
, int *dowarn
)
1984 if ((rsym
= dcs
->d_rdcsym
)->s_scl
== ENUMCON
) {
1985 /* redeclaration of %s */
1986 error(27, dsym
->s_name
);
1990 if (rsym
->s_scl
== TYPEDEF
) {
1991 /* typedef redeclared: %s */
1992 error(89, dsym
->s_name
);
1996 if (dsym
->s_scl
== TYPEDEF
) {
1997 /* redeclaration of %s */
1998 error(27, dsym
->s_name
);
2002 if (rsym
->s_def
== DEF
&& dsym
->s_def
== DEF
) {
2003 /* redefinition of %s */
2004 error(28, dsym
->s_name
);
2008 if (!eqtype(rsym
->s_type
, dsym
->s_type
, 0, 0, dowarn
)) {
2009 /* redeclaration of %s */
2010 error(27, dsym
->s_name
);
2014 if (rsym
->s_scl
== EXTERN
&& dsym
->s_scl
== EXTERN
)
2016 if (rsym
->s_scl
== STATIC
&& dsym
->s_scl
== STATIC
)
2018 if (rsym
->s_scl
== STATIC
&& dsym
->s_def
== DECL
)
2020 if (rsym
->s_scl
== EXTERN
&& rsym
->s_def
== DEF
) {
2022 * All cases except "int a = 1; static int a;" are catched
2023 * above with or without a warning
2025 /* redeclaration of %s */
2026 error(27, dsym
->s_name
);
2030 if (rsym
->s_scl
== EXTERN
) {
2031 /* previously declared extern, becomes static: %s */
2032 warning(29, dsym
->s_name
);
2038 * "static a; int a;", "static a; int a = 1;", "static a = 1; int a;"
2040 /* redeclaration of %s; ANSI C requires "static" */
2042 warning(30, dsym
->s_name
);
2045 dsym
->s_scl
= STATIC
;
2050 chkqual(type_t
*tp1
, type_t
*tp2
, int ignqual
)
2052 if (tp1
->t_const
!= tp2
->t_const
&& !ignqual
&& !tflag
)
2055 if (tp1
->t_volatile
!= tp2
->t_volatile
&& !ignqual
&& !tflag
)
2062 eqptrtype(type_t
*tp1
, type_t
*tp2
, int ignqual
)
2064 if (tp1
->t_tspec
!= VOID
&& tp2
->t_tspec
!= VOID
)
2067 if (!chkqual(tp1
, tp2
, ignqual
))
2075 * Checks if two types are compatible. Returns 0 if not, otherwise 1.
2077 * ignqual ignore qualifiers of type; used for function params
2078 * promot promote left type; used for comparison of params of
2079 * old style function definitions with params of prototypes.
2080 * *dowarn set to 1 if an old style function declaration is not
2081 * compatible with a prototype
2084 eqtype(type_t
*tp1
, type_t
*tp2
, int ignqual
, int promot
, int *dowarn
)
2088 while (tp1
!= NULL
&& tp2
!= NULL
) {
2094 } else if (t
== CHAR
|| t
== SCHAR
) {
2096 } else if (t
== UCHAR
) {
2097 t
= tflag
? UINT
: INT
;
2098 } else if (t
== SHORT
) {
2100 } else if (t
== USHORT
) {
2102 t
= INT_MAX
< USHRT_MAX
|| tflag
? UINT
: INT
;
2106 if (t
!= tp2
->t_tspec
)
2109 if (!chkqual(tp1
, tp2
, ignqual
))
2112 if (t
== STRUCT
|| t
== UNION
)
2113 return (tp1
->t_str
== tp2
->t_str
);
2115 if (t
== ARRAY
&& tp1
->t_dim
!= tp2
->t_dim
) {
2116 if (tp1
->t_dim
!= 0 && tp2
->t_dim
!= 0)
2120 /* dont check prototypes for traditional */
2121 if (t
== FUNC
&& !tflag
) {
2122 if (tp1
->t_proto
&& tp2
->t_proto
) {
2123 if (!eqargs(tp1
, tp2
, dowarn
))
2125 } else if (tp1
->t_proto
) {
2126 if (!mnoarg(tp1
, dowarn
))
2128 } else if (tp2
->t_proto
) {
2129 if (!mnoarg(tp2
, dowarn
))
2136 ignqual
= promot
= 0;
2140 return (tp1
== tp2
);
2144 * Compares the parameter types of two prototypes.
2147 eqargs(type_t
*tp1
, type_t
*tp2
, int *dowarn
)
2151 if (tp1
->t_vararg
!= tp2
->t_vararg
)
2157 while (a1
!= NULL
&& a2
!= NULL
) {
2159 if (eqtype(a1
->s_type
, a2
->s_type
, 1, 0, dowarn
) == 0)
2171 * mnoarg() (matches functions with no argument type information)
2172 * returns 1 if all parameters of a prototype are compatible with
2173 * and old style function declaration.
2174 * This is the case if following conditions are met:
2175 * 1. the prototype must have a fixed number of parameters
2176 * 2. no parameter is of type float
2177 * 3. no parameter is converted to another type if integer promotion
2181 mnoarg(type_t
*tp
, int *dowarn
)
2190 for (arg
= tp
->t_args
; arg
!= NULL
; arg
= arg
->s_nxt
) {
2191 if ((t
= arg
->s_type
->t_tspec
) == FLOAT
||
2192 t
== CHAR
|| t
== SCHAR
|| t
== UCHAR
||
2193 t
== SHORT
|| t
== USHORT
) {
2202 * Compares a prototype declaration with the remembered arguments of
2203 * a previous old style function definition.
2206 chkosdef(sym_t
*rdsym
, sym_t
*dsym
)
2208 sym_t
*args
, *pargs
, *arg
, *parg
;
2212 args
= rdsym
->s_args
;
2213 pargs
= dsym
->s_type
->t_args
;
2218 for (arg
= args
; arg
!= NULL
; arg
= arg
->s_nxt
)
2220 for (parg
= pargs
; parg
!= NULL
; parg
= parg
->s_nxt
)
2222 if (narg
!= nparg
) {
2223 /* prototype does not match old-style definition */
2235 * If it does not match due to promotion and sflag is
2236 * not set we print only a warning.
2238 if (!eqtype(arg
->s_type
, parg
->s_type
, 1, 1, &dowarn
) || dowarn
) {
2239 /* prototype does not match old-style def., arg #%d */
2250 /* old style definition */
2251 prevdecl(300, rdsym
);
2257 * Complets a type by copying the dimension and prototype information
2258 * from a second compatible type.
2260 * Following lines are legal:
2261 * "typedef a[]; a b; a b[10]; a c; a c[20];"
2262 * "typedef ft(); ft f; f(int); ft g; g(long);"
2263 * This means that, if a type is completed, the type structure must
2267 compltyp(sym_t
*dsym
, sym_t
*ssym
)
2269 type_t
**dstp
, *src
;
2272 dstp
= &dsym
->s_type
;
2275 while ((dst
= *dstp
) != NULL
) {
2276 if (src
== NULL
|| dst
->t_tspec
!= src
->t_tspec
)
2277 LERROR("compltyp()");
2278 if (dst
->t_tspec
== ARRAY
) {
2279 if (dst
->t_dim
== 0 && src
->t_dim
!= 0) {
2280 *dstp
= dst
= duptyp(dst
);
2281 dst
->t_dim
= src
->t_dim
;
2282 /* now a complete Typ */
2285 } else if (dst
->t_tspec
== FUNC
) {
2286 if (!dst
->t_proto
&& src
->t_proto
) {
2287 *dstp
= dst
= duptyp(dst
);
2289 dst
->t_args
= src
->t_args
;
2292 dstp
= &dst
->t_subt
;
2298 * Completes the declaration of a single argument.
2301 decl1arg(sym_t
*sym
, int initflg
)
2309 if (dcs
->d_rdcsym
!= NULL
&& dcs
->d_rdcsym
->s_blklev
== blklev
) {
2310 /* redeclaration of formal parameter %s */
2311 error(237, sym
->s_name
);
2312 rmsym(dcs
->d_rdcsym
);
2317 /* declared argument %s is missing */
2318 error(53, sym
->s_name
);
2323 /* cannot initialize parameter: %s */
2324 error(52, sym
->s_name
);
2328 if ((t
= sym
->s_type
->t_tspec
) == ARRAY
) {
2329 sym
->s_type
= incref(sym
->s_type
->t_subt
, PTR
);
2330 } else if (t
== FUNC
) {
2332 /* a function is declared as an argument: %s */
2333 warning(50, sym
->s_name
);
2334 sym
->s_type
= incref(sym
->s_type
, PTR
);
2335 } else if (t
== FLOAT
) {
2337 sym
->s_type
= gettyp(DOUBLE
);
2341 /* argument declared inline: %s */
2342 warning(269, sym
->s_name
);
2345 * Arguments must have complete types. lengths() prints the needed
2346 * error messages (null dimension is impossible because arrays are
2347 * converted to pointers).
2349 if (sym
->s_type
->t_tspec
!= VOID
)
2350 (void)length(sym
->s_type
, sym
->s_name
);
2358 * Does some checks for lint directives which apply to functions.
2359 * Processes arguments in old style function definitions which default
2361 * Checks compatiblility of old style function definition with previous
2367 sym_t
*args
, *arg
, *pargs
, *parg
;
2368 int narg
, nparg
, n
, msg
;
2371 args
= funcsym
->s_args
;
2372 pargs
= funcsym
->s_type
->t_args
;
2374 /* check for illegal combinations of lint directives */
2375 if (prflstrg
!= -1 && scflstrg
!= -1) {
2376 /* can't be used together: ** PRINTFLIKE ** ** SCANFLIKE ** */
2378 prflstrg
= scflstrg
= -1;
2380 if (nvararg
!= -1 && (prflstrg
!= -1 || scflstrg
!= -1)) {
2381 /* dubious use of ** VARARGS ** with ** %s ** */
2382 warning(288, prflstrg
!= -1 ? "PRINTFLIKE" : "SCANFLIKE");
2387 * check if the argument of a lint directive is compatible with the
2388 * number of arguments.
2391 for (arg
= dcs
->d_fargs
; arg
!= NULL
; arg
= arg
->s_nxt
)
2393 if (nargusg
> narg
) {
2394 /* argument number mismatch with directive: ** %s ** */
2395 warning(283, "ARGSUSED");
2398 if (nvararg
> narg
) {
2399 /* argument number mismatch with directive: ** %s ** */
2400 warning(283, "VARARGS");
2403 if (prflstrg
> narg
) {
2404 /* argument number mismatch with directive: ** %s ** */
2405 warning(283, "PRINTFLIKE");
2407 } else if (prflstrg
== 0) {
2410 if (scflstrg
> narg
) {
2411 /* argument number mismatch with directive: ** %s ** */
2412 warning(283, "SCANFLIKE");
2414 } else if (scflstrg
== 0) {
2417 if (prflstrg
!= -1 || scflstrg
!= -1) {
2418 narg
= prflstrg
!= -1 ? prflstrg
: scflstrg
;
2420 for (n
= 1; n
< narg
; n
++)
2422 if (arg
->s_type
->t_tspec
!= PTR
||
2423 ((t
= arg
->s_type
->t_subt
->t_tspec
) != CHAR
&&
2424 t
!= UCHAR
&& t
!= SCHAR
)) {
2425 /* arg. %d must be 'char *' for PRINTFLIKE/SCANFLIKE */
2427 prflstrg
= scflstrg
= -1;
2432 * print a warning for each argument off an old style function
2433 * definition which defaults to int
2435 for (arg
= args
; arg
!= NULL
; arg
= arg
->s_nxt
) {
2436 if (arg
->s_defarg
) {
2437 /* argument type defaults to int: %s */
2438 warning(32, arg
->s_name
);
2445 * If this is an old style function definition and a prototyp
2446 * exists, compare the types of arguments.
2448 if (funcsym
->s_osdef
&& funcsym
->s_type
->t_proto
) {
2450 * If the number of arguments does not macht, we need not
2455 for (parg
= pargs
; parg
!= NULL
; parg
= parg
->s_nxt
)
2457 for (arg
= args
; arg
!= NULL
; arg
= arg
->s_nxt
)
2459 if (narg
!= nparg
) {
2460 /* parameter mismatch: %d declared, %d defined */
2461 error(51, nparg
, narg
);
2467 msg
|= chkptdecl(arg
, parg
);
2473 /* prototype declaration */
2474 prevdecl(285, dcs
->d_rdcsym
);
2476 /* from now the prototype is valid */
2477 funcsym
->s_osdef
= 0;
2478 funcsym
->s_args
= NULL
;
2485 * Checks compatibility of an old style function definition with a previous
2486 * prototype declaration.
2487 * Returns 1 if the position of the previous declaration should be reported.
2490 chkptdecl(sym_t
*arg
, sym_t
*parg
)
2501 if (!eqtype(tp
, ptp
, 1, 1, &dowarn
)) {
2502 if (eqtype(tp
, ptp
, 1, 0, &dowarn
)) {
2503 /* type does not match prototype: %s */
2504 msg
= gnuism(58, arg
->s_name
);
2506 /* type does not match prototype: %s */
2507 error(58, arg
->s_name
);
2510 } else if (dowarn
) {
2511 /* type does not match prototype: %s */
2512 (*(sflag
? error
: warning
))(58, arg
->s_name
);
2520 * Completes a single local declaration/definition.
2523 decl1loc(sym_t
*dsym
, int initflg
)
2526 /* Correct a mistake done in dname(). */
2527 if (dsym
->s_type
->t_tspec
== FUNC
) {
2529 if (dcs
->d_scl
== NOSCL
)
2530 dsym
->s_scl
= EXTERN
;
2533 if (dsym
->s_type
->t_tspec
== FUNC
) {
2534 if (dsym
->s_scl
== STATIC
) {
2535 /* dubious static function at block level: %s */
2536 warning(93, dsym
->s_name
);
2537 dsym
->s_scl
= EXTERN
;
2538 } else if (dsym
->s_scl
!= EXTERN
&& dsym
->s_scl
!= TYPEDEF
) {
2539 /* function has illegal storage class: %s */
2540 error(94, dsym
->s_name
);
2541 dsym
->s_scl
= EXTERN
;
2546 * functions may be declared inline at local scope, although
2547 * this has no effect for a later definition of the same
2549 * XXX it should have an effect if tflag is set. this would
2550 * also be the way gcc behaves.
2552 if (dcs
->d_inline
) {
2553 if (dsym
->s_type
->t_tspec
== FUNC
) {
2556 /* variable declared inline: %s */
2557 warning(268, dsym
->s_name
);
2565 if (dcs
->d_rdcsym
!= NULL
&& dsym
->s_scl
== EXTERN
)
2568 if (dsym
->s_scl
== EXTERN
) {
2570 * XXX wenn die statische Variable auf Ebene 0 erst
2571 * spaeter definiert wird, haben wir die Brille auf.
2573 if (dsym
->s_xsym
== NULL
) {
2574 outsym(dsym
, EXTERN
, dsym
->s_def
);
2576 outsym(dsym
, dsym
->s_xsym
->s_scl
, dsym
->s_def
);
2580 if (dcs
->d_rdcsym
!= NULL
) {
2582 if (dcs
->d_rdcsym
->s_blklev
== 0) {
2584 switch (dsym
->s_scl
) {
2586 /* automatic hides external declaration: %s */
2588 warning(86, dsym
->s_name
);
2591 /* static hides external declaration: %s */
2593 warning(87, dsym
->s_name
);
2596 /* typedef hides external declaration: %s */
2598 warning(88, dsym
->s_name
);
2602 * Warnings and errors are printed in ledecl()
2606 LERROR("decl1loc()");
2609 } else if (dcs
->d_rdcsym
->s_blklev
== blklev
) {
2611 /* no hflag, because its illegal! */
2612 if (dcs
->d_rdcsym
->s_arg
) {
2614 * if !tflag, a "redeclaration of %s" error
2619 /* decl. hides parameter: %s */
2620 warning(91, dsym
->s_name
);
2621 rmsym(dcs
->d_rdcsym
);
2625 } else if (dcs
->d_rdcsym
->s_blklev
< blklev
) {
2628 /* declaration hides earlier one: %s */
2629 warning(95, dsym
->s_name
);
2633 if (dcs
->d_rdcsym
->s_blklev
== blklev
) {
2635 /* redeclaration of %s */
2636 error(27, dsym
->s_name
);
2637 rmsym(dcs
->d_rdcsym
);
2643 if (initflg
&& !(initerr
= chkinit(dsym
))) {
2648 if (dsym
->s_scl
== TYPEDEF
) {
2649 dsym
->s_type
= duptyp(dsym
->s_type
);
2650 dsym
->s_type
->t_typedef
= 1;
2651 settdsym(dsym
->s_type
, dsym
);
2655 * Before we can check the size we must wait for a initialisation
2661 * Processes (re)declarations of external Symbols inside blocks.
2669 /* look for a symbol with the same name */
2670 esym
= dcs
->d_rdcsym
;
2671 while (esym
!= NULL
&& esym
->s_blklev
!= 0) {
2672 while ((esym
= esym
->s_link
) != NULL
) {
2673 if (esym
->s_kind
!= FVFT
)
2675 if (strcmp(dsym
->s_name
, esym
->s_name
) == 0)
2681 if (esym
->s_scl
!= EXTERN
&& esym
->s_scl
!= STATIC
) {
2682 /* gcc accepts this without a warning, pcc prints an error. */
2683 /* redeclaration of %s */
2684 warning(27, dsym
->s_name
);
2690 eqt
= eqtype(esym
->s_type
, dsym
->s_type
, 0, 0, &dowarn
);
2692 if (!eqt
|| dowarn
) {
2693 if (esym
->s_scl
== EXTERN
) {
2694 /* inconsistent redeclaration of extern: %s */
2695 warning(90, dsym
->s_name
);
2698 /* inconsistent redeclaration of static: %s */
2699 warning(92, dsym
->s_name
);
2706 * Remember the external symbol so we can update usage
2707 * information at the end of the block.
2709 dsym
->s_xsym
= esym
;
2714 * Print an error or a warning if the symbol cant be initialized due
2715 * to type/storage class. Returnvalue is 1 if an error has been
2725 if (sym
->s_type
->t_tspec
== FUNC
) {
2726 /* cannot initialize function: %s */
2727 error(24, sym
->s_name
);
2729 } else if (sym
->s_scl
== TYPEDEF
) {
2730 /* cannot initialize typedef: %s */
2731 error(25, sym
->s_name
);
2733 } else if (sym
->s_scl
== EXTERN
&& sym
->s_def
== DECL
) {
2734 /* cannot initialize "extern" declaration: %s */
2735 if (dcs
->d_ctx
== EXTERN
) {
2736 warning(26, sym
->s_name
);
2738 error(26, sym
->s_name
);
2747 * Create a symbole for an abstract declaration.
2754 if (dcs
->d_ctx
!= ABSTRACT
&& dcs
->d_ctx
!= PARG
)
2757 sym
= getblk(sizeof (sym_t
));
2759 sym
->s_name
= unnamed
;
2761 sym
->s_scl
= ABSTRACT
;
2764 if (dcs
->d_ctx
== PARG
)
2767 sym
->s_type
= dcs
->d_type
;
2768 dcs
->d_rdcsym
= NULL
;
2775 * Removes anything which has nothing to do on global level.
2781 while (dcs
->d_nxt
!= NULL
)
2789 * remove all informations about pending lint directives without
2796 * Process an abstract type declaration
2799 decl1abs(sym_t
*sym
)
2808 * Checks size after declarations of variables and their initialisation.
2815 * check size only for symbols which are defined and no function and
2818 if (dsym
->s_def
!= DEF
)
2820 if (dsym
->s_scl
== TYPEDEF
)
2822 if (dsym
->s_type
->t_tspec
== FUNC
)
2825 if (length(dsym
->s_type
, dsym
->s_name
) == 0 &&
2826 dsym
->s_type
->t_tspec
== ARRAY
&& dsym
->s_type
->t_dim
== 0) {
2827 /* empty array declaration: %s */
2829 warning(190, dsym
->s_name
);
2831 error(190, dsym
->s_name
);
2837 * Mark an object as set if it is not already
2845 UNIQUE_CURR_POS(sym
->s_spos
);
2850 * Mark an object as used if it is not already
2853 setuflg(sym_t
*sym
, int fcall
, int szof
)
2858 UNIQUE_CURR_POS(sym
->s_upos
);
2861 * for function calls another record is written
2863 * XXX Should symbols used in sizeof() treated as used or not?
2864 * Probably not, because there is no sense to declare an
2865 * external variable only to get their size.
2867 if (!fcall
&& !szof
&& sym
->s_kind
== FVFT
&& sym
->s_scl
== EXTERN
)
2872 * Prints warnings for a list of variables and labels (concatenated
2873 * with s_dlnxt) if these are not used or only set.
2876 chkusage(dinfo_t
*di
)
2881 /* for this warnings LINTED has no effect */
2886 printf("%s, %d: >temp nowarn = 0\n", curr_pos
.p_file
, curr_pos
.p_line
);
2888 for (sym
= di
->d_dlsyms
; sym
!= NULL
; sym
= sym
->s_dlnxt
)
2889 chkusg1(di
->d_asm
, sym
);
2892 printf("%s, %d: <temp nowarn = %d\n", curr_pos
.p_file
, curr_pos
.p_line
,
2898 * Prints a warning for a single variable or label if it is not used or
2902 chkusg1(int novar
, sym_t
*sym
)
2906 if (sym
->s_blklev
== -1)
2909 STRUCT_ASSIGN(cpos
, curr_pos
);
2911 if (sym
->s_kind
== FVFT
) {
2913 chkausg(novar
, sym
);
2915 chkvusg(novar
, sym
);
2917 } else if (sym
->s_kind
== FLAB
) {
2919 } else if (sym
->s_kind
== FTAG
) {
2923 STRUCT_ASSIGN(curr_pos
, cpos
);
2927 chkausg(int novar
, sym_t
*arg
)
2931 LERROR("chkausg()");
2936 if (!arg
->s_used
&& vflag
) {
2937 STRUCT_ASSIGN(curr_pos
, arg
->s_dpos
);
2938 /* argument %s unused in function %s */
2939 warning(231, arg
->s_name
, funcsym
->s_name
);
2944 chkvusg(int novar
, sym_t
*sym
)
2949 if (blklev
== 0 || sym
->s_blklev
== 0)
2950 LERROR("chkvusg()");
2952 /* errors in expressions easily cause lots of these warnings */
2957 * XXX Only variables are checkd, although types should
2958 * probably also be checked
2960 if ((sc
= sym
->s_scl
) != EXTERN
&& sc
!= STATIC
&&
2961 sc
!= AUTO
&& sc
!= REG
) {
2969 if (!sym
->s_used
&& !sym
->s_set
) {
2970 STRUCT_ASSIGN(curr_pos
, sym
->s_dpos
);
2971 /* %s unused in function %s */
2972 warning(192, sym
->s_name
, funcsym
->s_name
);
2975 if (sym
->s_set
&& !sym
->s_used
) {
2976 STRUCT_ASSIGN(curr_pos
, sym
->s_spos
);
2977 /* %s set but not used in function %s */
2978 warning(191, sym
->s_name
, funcsym
->s_name
);
2979 } else if (!sym
->s_used
) {
2980 STRUCT_ASSIGN(curr_pos
, sym
->s_dpos
);
2981 /* %s unused in function %s */
2982 warning(192, sym
->s_name
, funcsym
->s_name
);
2988 * information about usage is taken over into the symbol
2989 * tabel entry at level 0 if the symbol was locally declared
2990 * as an external symbol.
2992 * XXX This is wrong for symbols declared static at level 0
2993 * if the usage information stems from sizeof(). This is
2994 * because symbols at level 0 only used in sizeof() are
2995 * considered to not be used.
2997 if ((xsym
= sym
->s_xsym
) != NULL
) {
2998 if (sym
->s_used
&& !xsym
->s_used
) {
3000 STRUCT_ASSIGN(xsym
->s_upos
, sym
->s_upos
);
3002 if (sym
->s_set
&& !xsym
->s_set
) {
3004 STRUCT_ASSIGN(xsym
->s_spos
, sym
->s_spos
);
3014 if (blklev
!= 1 || lab
->s_blklev
!= 1)
3015 LERROR("chklusg()");
3017 if (lab
->s_set
&& !lab
->s_used
) {
3018 STRUCT_ASSIGN(curr_pos
, lab
->s_spos
);
3019 /* label %s unused in function %s */
3020 warning(192, lab
->s_name
, funcsym
->s_name
);
3021 } else if (!lab
->s_set
) {
3022 STRUCT_ASSIGN(curr_pos
, lab
->s_upos
);
3023 /* undefined label %s */
3024 warning(23, lab
->s_name
);
3032 if (!incompl(sym
->s_type
))
3035 /* complain alwasy about incomplet tags declared inside blocks */
3036 if (!zflag
|| dcs
->d_ctx
!= EXTERN
)
3039 STRUCT_ASSIGN(curr_pos
, sym
->s_dpos
);
3040 switch (sym
->s_type
->t_tspec
) {
3042 /* struct %s never defined */
3043 warning(233, sym
->s_name
);
3046 /* union %s never defined */
3047 warning(234, sym
->s_name
);
3050 /* enum %s never defined */
3051 warning(235, sym
->s_name
);
3054 LERROR("chktusg()");
3059 * Called after the entire translation unit has been parsed.
3060 * Changes tentative definitions in definitions.
3061 * Performs some tests on global Symbols. Detected Problems are:
3062 * - defined variables of incomplete type
3063 * - constant variables which are not initialized
3064 * - static symbols which are never used
3072 if (blklev
!= 0 || dcs
->d_nxt
!= NULL
)
3075 STRUCT_ASSIGN(cpos
, curr_pos
);
3077 for (sym
= dcs
->d_dlsyms
; sym
!= NULL
; sym
= sym
->s_dlnxt
) {
3078 if (sym
->s_blklev
== -1)
3080 if (sym
->s_kind
== FVFT
) {
3082 } else if (sym
->s_kind
== FTAG
) {
3085 if (sym
->s_kind
!= FMOS
)
3086 LERROR("chkglsyms()");
3090 STRUCT_ASSIGN(curr_pos
, cpos
);
3094 chkglvar(sym_t
*sym
)
3097 if (sym
->s_scl
== TYPEDEF
|| sym
->s_scl
== ENUMCON
)
3100 if (sym
->s_scl
!= EXTERN
&& sym
->s_scl
!= STATIC
)
3101 LERROR("chkglvar()");
3105 if (sym
->s_scl
== STATIC
) {
3106 if (sym
->s_type
->t_tspec
== FUNC
) {
3107 if (sym
->s_used
&& sym
->s_def
!= DEF
) {
3108 STRUCT_ASSIGN(curr_pos
, sym
->s_upos
);
3109 /* static func. called but not def.. */
3110 error(225, sym
->s_name
);
3114 STRUCT_ASSIGN(curr_pos
, sym
->s_dpos
);
3115 if (sym
->s_type
->t_tspec
== FUNC
) {
3116 if (sym
->s_def
== DEF
) {
3118 /* static function %s unused */
3119 warning(236, sym
->s_name
);
3121 /* static function %s decl. but ... */
3122 warning(290, sym
->s_name
);
3124 } else if (!sym
->s_set
) {
3125 /* static variable %s unused */
3126 warning(226, sym
->s_name
);
3128 /* static variable %s set but not used */
3129 warning(307, sym
->s_name
);
3132 if (!tflag
&& sym
->s_def
== TDEF
&& sym
->s_type
->t_const
) {
3133 STRUCT_ASSIGN(curr_pos
, sym
->s_dpos
);
3134 /* const object %s should have initializer */
3135 warning(227, sym
->s_name
);
3144 if (sym
->s_def
== TDEF
) {
3145 if (sym
->s_type
->t_tspec
== FUNC
)
3147 * this can happen if an syntax error occurred
3148 * after a function declaration
3151 STRUCT_ASSIGN(curr_pos
, sym
->s_dpos
);
3152 if (length(sym
->s_type
, sym
->s_name
) == 0 &&
3153 sym
->s_type
->t_tspec
== ARRAY
&& sym
->s_type
->t_dim
== 0) {
3154 /* empty array declaration: %s */
3155 if (tflag
|| (sym
->s_scl
== EXTERN
&& !sflag
)) {
3156 warning(190, sym
->s_name
);
3158 error(190, sym
->s_name
);
3165 * Prints information about location of previous definition/declaration.
3168 prevdecl(int msg
, sym_t
*psym
)
3175 STRUCT_ASSIGN(cpos
, curr_pos
);
3176 STRUCT_ASSIGN(curr_pos
, psym
->s_dpos
);
3178 message(msg
, psym
->s_name
);
3179 } else if (psym
->s_def
== DEF
|| psym
->s_def
== TDEF
) {
3180 /* previous definition of %s */
3181 message(261, psym
->s_name
);
3183 /* previous declaration of %s */
3184 message(260, psym
->s_name
);
3186 STRUCT_ASSIGN(curr_pos
, cpos
);