1 /* $NetBSD: chk.c,v 1.2 1995/07/03 21:24:42 cgd Exp $ */
4 * Copyright (c) 1994, 1995 Jochen Pohl
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Jochen Pohl for
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * $NetBSD: chk.c,v 1.2 1995/07/03 21:24:42 cgd Exp $
34 * $DragonFly: src/usr.bin/xlint/lint2/chk.c,v 1.4 2003/11/03 19:31:34 eirikn Exp $
44 /* various type information */
48 static void chkund(hte_t *);
49 static void chkdnu(hte_t *);
50 static void chkdnud(hte_t *);
51 static void chkmd(hte_t *);
52 static void chkvtui(hte_t *, sym_t *, sym_t *);
53 static void chkvtdi(hte_t *, sym_t *, sym_t *);
54 static void chkfaui(hte_t *, sym_t *, sym_t *);
55 static void chkau __P((hte_t *, int, sym_t *, sym_t *, pos_t *,
56 fcall_t *, fcall_t *, type_t *, type_t *));
57 static void chkrvu(hte_t *, sym_t *);
58 static void chkadecl(hte_t *, sym_t *, sym_t *);
59 static void printflike __P((hte_t *,fcall_t *, int,
60 const char *, type_t **));
61 static void scanflike __P((hte_t *, fcall_t *, int,
62 const char *, type_t **));
63 static void badfmt(hte_t *, fcall_t *);
64 static void inconarg(hte_t *, fcall_t *, int);
65 static void tofewarg(hte_t *, fcall_t *);
66 static void tomanyarg(hte_t *, fcall_t *);
67 static int eqtype(type_t *, type_t *, int, int, int, int *);
68 static int eqargs(type_t *, type_t *, int *);
69 static int mnoarg(type_t *, int *);
82 0, 0, 0, 0, 0, "signed" } },
85 0, 0, 0, 0, 0, "unsigned" } },
86 { CHAR, { CHAR_BIT, CHAR_BIT,
88 1, 0, 0, 1, 1, "char" } },
89 { SCHAR, { CHAR_BIT, CHAR_BIT,
91 1, 0, 0, 1, 1, "signed char" } },
92 { UCHAR, { CHAR_BIT, CHAR_BIT,
94 1, 1, 0, 1, 1, "unsigned char" } },
95 { SHORT, { sizeof (short) * CHAR_BIT, 2 * CHAR_BIT,
97 1, 0, 0, 1, 1, "short" } },
98 { USHORT, { sizeof (u_short) * CHAR_BIT, 2 * CHAR_BIT,
100 1, 1, 0, 1, 1, "unsigned short" } },
101 { INT, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT,
103 1, 0, 0, 1, 1, "int" } },
104 { UINT, { sizeof (u_int) * CHAR_BIT, 3 * CHAR_BIT,
106 1, 1, 0, 1, 1, "unsigned int" } },
107 { LONG, { sizeof (long) * CHAR_BIT, 4 * CHAR_BIT,
109 1, 0, 0, 1, 1, "long" } },
110 { ULONG, { sizeof (u_long) * CHAR_BIT, 4 * CHAR_BIT,
112 1, 1, 0, 1, 1, "unsigned long" } },
113 { QUAD, { sizeof (quad_t) * CHAR_BIT, 8 * CHAR_BIT,
115 1, 0, 0, 1, 1, "long long" } },
116 { UQUAD, { sizeof (u_quad_t) * CHAR_BIT, 8 * CHAR_BIT,
118 1, 1, 0, 1, 1, "unsigned long long" } },
119 { FLOAT, { sizeof (float) * CHAR_BIT, 4 * CHAR_BIT,
121 0, 0, 1, 1, 1, "float" } },
122 { DOUBLE, { sizeof (double) * CHAR_BIT, 8 * CHAR_BIT,
124 0, 0, 1, 1, 1, "double" } },
125 { LDOUBLE, { sizeof (ldbl_t) * CHAR_BIT, 10 * CHAR_BIT,
127 0, 0, 1, 1, 1, "long double" } },
130 0, 0, 0, 0, 0, "void" } },
133 0, 0, 0, 0, 0, "struct" } },
136 0, 0, 0, 0, 0, "union" } },
137 { ENUM, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT,
139 1, 0, 0, 1, 1, "enum" } },
140 { PTR, { sizeof (void *) * CHAR_BIT, 4 * CHAR_BIT,
142 0, 1, 0, 0, 1, "pointer" } },
145 0, 0, 0, 0, 0, "array" } },
148 0, 0, 0, 0, 0, "function" } },
151 for (i = 0; i < sizeof (ittab) / sizeof (ittab[0]); i++)
152 STRUCT_ASSIGN(ttab[ittab[i].it_tspec], ittab[i].it_ttab);
154 for (i = 0; i < NTSPEC; i++)
155 ttab[i].tt_psz = ttab[i].tt_sz;
161 * If there is a symbol named "main", mark it as used.
168 if ((hte = hsearch("main", 0)) != NULL)
173 * Performs all tests for a single name
179 sym_t *sym, *def, *pdecl, *decl;
189 /* Get definition, prototype declaration and declaration */
190 def = pdecl = decl = NULL;
191 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
192 if (def == NULL && (sym->s_def == DEF || sym->s_def == TDEF))
194 if (pdecl == NULL && sym->s_def == DECL &&
195 TP(sym->s_type)->t_tspec == FUNC &&
196 TP(sym->s_type)->t_proto) {
199 if (decl == NULL && sym->s_def == DECL)
203 /* A prototype is better than an old style declaration. */
207 chkvtui(hte, def, decl);
209 chkvtdi(hte, def, decl);
211 chkfaui(hte, def, decl);
215 chkadecl(hte, def, decl);
219 * Print a warning if the name has been used, but not defined.
228 if (!hte->h_used || hte->h_def)
231 if ((fcall = hte->h_calls) != NULL) {
232 /* %s used( %s ), but not defined */
233 msg(0, hte->h_name, mkpos(&fcall->f_pos));
234 } else if ((usym = hte->h_usyms) != NULL) {
235 /* %s used( %s ), but not defined */
236 msg(0, hte->h_name, mkpos(&usym->u_pos));
241 * Print a warning if the name has been defined, but never used.
249 if (!hte->h_def || hte->h_used)
252 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
253 if (sym->s_def == DEF || sym->s_def == TDEF) {
254 /* %s defined( %s ), but never used */
255 msg(1, hte->h_name, mkpos(&sym->s_pos));
262 * Print a warning if the name has been declared, but is not used
271 if (hte->h_syms == NULL || hte->h_used || hte->h_def)
274 if ((sym = hte->h_syms) != NULL) {
275 if (sym->s_def != DECL)
276 errx(1, "internal error: chkdnud() 1");
277 /* %s declared( %s ), but never used or defined */
278 msg(2, hte->h_name, mkpos(&sym->s_pos));
283 * Print a warning if there is more then one definition for
297 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
299 * ANSI C allows tentative definitions of the same name in
300 * only one compilation unit.
302 if (sym->s_def != DEF && (!sflag || sym->s_def != TDEF))
308 pos1 = xstrdup(mkpos(&def1->s_pos));
309 /* %s multiply defined\t%s :: %s */
310 msg(3, hte->h_name, pos1, mkpos(&sym->s_pos));
316 * Print a warning if the return value assumed for a function call
317 * differs from the return value of the function definition or
318 * function declaration.
320 * If no definition/declaration can be found, the assumed return values
321 * are always int. So there is no need to compare with another function
322 * call as it's done for function arguments.
325 chkvtui(hte, def, decl)
332 /* LINTED (automatic hides external declaration: warn) */
336 if (hte->h_calls == NULL)
344 t1 = (tp1 = TP(def->s_type)->t_subt)->t_tspec;
345 for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
346 tp2 = TP(call->f_type)->t_subt;
347 eq = eqtype(tp1, tp2, 1, 0, 0, (warn = 0, &warn));
348 if (!call->f_rused) {
349 /* no return value used */
350 if ((t1 == STRUCT || t1 == UNION) && !eq) {
352 * If a function returns a struct or union it
353 * must be declared to return a struct or
354 * union, also if the return value is ignored.
355 * This is necessary because the caller must
356 * allocate stack space for the return value.
357 * If it does not, the return value would over-
359 * XXX Following massage may be confusing
360 * because it appears also if the return value
361 * was declared inconsistently. But this
362 * behaviour matches pcc based lint, so it is
365 pos1 = xstrdup(mkpos(&def->s_pos));
366 /* %s value must be decl. before use %s :: %s */
368 pos1, mkpos(&call->f_pos));
373 if (!eq || (sflag && warn)) {
374 pos1 = xstrdup(mkpos(&def->s_pos));
375 /* %s value used inconsistenty\t%s :: %s */
376 msg(4, hte->h_name, pos1, mkpos(&call->f_pos));
383 * Print a warning if a definition/declaration does not match another
384 * definition/declaration of the same name. For functions, only the
385 * types of return values are tested.
388 chkvtdi(hte, def, decl)
394 /* LINTED (automatic hides external declaration: warn) */
403 tp1 = TP(def->s_type);
404 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
407 tp2 = TP(sym->s_type);
409 if (tp1->t_tspec == FUNC && tp2->t_tspec == FUNC) {
410 eq = eqtype(tp1->t_subt, tp2->t_subt, 1, 0, 0, &warn);
412 eq = eqtype(tp1, tp2, 0, 0, 0, &warn);
414 if (!eq || (sflag && warn)) {
415 pos1 = xstrdup(mkpos(&def->s_pos));
416 /* %s value declared inconsistently\t%s :: %s */
417 msg(5, hte->h_name, pos1, mkpos(&sym->s_pos));
424 * Print a warning if a function is called with arguments which does
425 * not match the function definition, declaration or another call
426 * of the same function.
429 chkfaui(hte, def, decl)
433 type_t *tp1, *tp2, **ap1, **ap2;
435 fcall_t *calls, *call, *call1;
440 if ((calls = hte->h_calls) == NULL)
444 * If we find a function definition, we use this for comparision,
445 * otherwise the first prototype we can find. If there is no
446 * definition or prototype declaration, the first function call
452 if ((tp1 = TP(def->s_type))->t_tspec != FUNC)
455 } else if (decl != NULL && TP(decl->s_type)->t_proto) {
456 if ((tp1 = TP(decl->s_type))->t_tspec != FUNC)
458 pos1p = &decl->s_pos;
462 calls = calls->f_nxt;
463 if ((tp1 = TP(call1->f_type))->t_tspec != FUNC)
465 pos1p = &call1->f_pos;
469 for (call = calls; call != NULL; call = call->f_nxt) {
470 if ((tp2 = TP(call->f_type))->t_tspec != FUNC)
475 while (*ap1 != NULL && *ap2 != NULL) {
476 if (def != NULL && def->s_va && n >= def->s_nva)
479 chkau(hte, n, def, decl, pos1p, call1, call,
485 /* equal # of arguments */
486 } else if (def != NULL && def->s_va && n >= def->s_nva) {
488 * function definition with VARARGS; The # of
489 * arguments of the call must be at least as large
490 * as the parameter of VARARGS.
492 } else if (*ap2 != NULL && tp1->t_proto && tp1->t_vararg) {
494 * prototype with ... and function call with
495 * at least the same # of arguments as declared
499 pos1 = xstrdup(mkpos(pos1p));
500 /* %s: variable # of args\t%s :: %s */
501 msg(7, hte->h_name, pos1, mkpos(&call->f_pos));
506 /* perform SCANFLIKE/PRINTFLIKE tests */
507 if (def == NULL || (!def->s_prfl && !def->s_scfl))
509 as = def->s_prfl ? def->s_nprfl : def->s_nscfl;
510 for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) {
514 if (ai == NULL || !ai->a_fmt)
517 printflike(hte, call, n, ai->a_fstrg, ap2);
519 scanflike(hte, call, n, ai->a_fstrg, ap2);
525 * Check a single argument in a function call.
527 * hte a pointer to the hash table entry of the function
528 * n the number of the argument (1..)
529 * def the function definition or NULL
530 * decl prototype declaration, old style declaration or NULL
531 * pos1p position of definition, declaration of first call
532 * call1 first call, if both def and decl are old style def/decl
534 * arg1 currently checked argument of def/decl/call1
535 * arg2 currently checked argument of call
539 chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2)
544 fcall_t *call1, *call;
547 /* LINTED (automatic hides external declaration: warn) */
548 int promote, asgn, warn;
554 * If a function definition is available (def != NULL), we compair the
555 * function call (call) with the definition. Otherwise, if a function
556 * definition is available and it is not an old style definition
557 * (decl != NULL && TP(decl->s_type)->t_proto), we compair the call
558 * with this declaration. Otherwise we compair it with the first
559 * call we have found (call1).
562 /* arg1 must be promoted if it stems from an old style definition */
563 promote = def != NULL && def->s_osdef;
566 * If we compair with a definition or declaration, we must perform
567 * the same checks for qualifiers in indirected types as in
570 asgn = def != NULL || (decl != NULL && TP(decl->s_type)->t_proto);
573 if (eqtype(arg1, arg2, 1, promote, asgn, &warn) && (!sflag || !warn))
577 * Other lint implementations print warnings as soon as the type
578 * of an argument does not match exactly the expected type. The
579 * result are lots of warnings which are really not neccessary.
580 * We print a warning only if
581 * (0) at least one type is not an interger type and types differ
582 * (1) hflag is set and types differ
583 * (2) types differ, except in signedness
584 * If the argument is an integer constant whose msb is not set,
585 * signedness is ignored (e.g. 0 matches both signed and unsigned
586 * int). This is with and without hflag.
587 * If the argument is an integer constant with value 0 and the
588 * expected argument is of type pointer and the width of the
589 * interger constant is the same as the width of the pointer,
590 * no warning is printed.
594 if (isityp(t1) && isityp(t2) && !arg1->t_isenum && !arg2->t_isenum) {
597 * XXX Here is a problem: Althrough it is possible to
598 * pass an int where a char/short it expected, there
599 * may be loss in significant digits. We should first
600 * check for const arguments if they can be converted
601 * into the original parameter type.
605 } else if (t1 == CHAR || t1 == SCHAR) {
607 } else if (t1 == UCHAR) {
608 t1 = tflag ? UINT : INT;
609 } else if (t1 == SHORT) {
611 } else if (t1 == USHORT) {
613 t1 = INT_MAX < USHRT_MAX || tflag ? UINT : INT;
617 if (styp(t1) == styp(t2)) {
620 * types differ only in signedness; get information
625 * treat a definition like a call with variable
628 ai1 = call1 != NULL ? call1->f_args : NULL;
631 * if two calls are compared, ai1 is set to the
632 * information for the n-th argument, if this was
633 * a constant, otherwise to NULL
635 for ( ; ai1 != NULL; ai1 = ai1->a_nxt) {
640 * ai is set to the information of the n-th arg
641 * of the (second) call, if this was a constant,
644 for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) {
649 if (ai1 == NULL && ai == NULL) {
650 /* no constant at all */
653 } else if (ai1 == NULL || ai == NULL) {
657 if (ai->a_zero || ai->a_pcon)
658 /* same value in signed and unsigned */
660 /* value (not representation) differently */
663 * two constants, one signed, one unsigned;
664 * if the msb of one of the constants is set,
665 * the argument is used inconsistently.
667 if (!ai1->a_ncon && !ai->a_ncon)
672 } else if (t1 == PTR && isityp(t2) && psize(t1) == psize(t2)) {
673 for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) {
677 if (ai != NULL && ai->a_zero)
681 pos1 = xstrdup(mkpos(pos1p));
682 /* %s, arg %d used inconsistently\t%s :: %s */
683 msg(6, hte->h_name, n, pos1, mkpos(&call->f_pos));
688 * Compare the types in the NULL-terminated array ap with the format
692 printflike(hte, call, n, fmt, ap)
701 int fwidth, prec, left, sign, space, alt, zero;
711 tomanyarg(hte, call);
719 fwidth = prec = left = sign = space = alt = zero = 0;
728 } else if (fc == '+') {
732 } else if (fc == ' ') {
736 } else if (fc == '#') {
740 } else if (fc == '0') {
753 do { fc = *fp++; } while (isdigit(fc)) ;
754 } else if (fc == '*') {
757 if ((tp = *ap++) == NULL) {
762 if ((t1 = tp->t_tspec) != INT && (hflag || t1 != UINT))
763 inconarg(hte, call, n);
771 do { fc = *fp++; } while (isdigit(fc));
772 } else if (fc == '*') {
774 if ((tp = *ap++) == NULL) {
779 if (tp->t_tspec != INT)
780 inconarg(hte, call, n);
789 } else if (fc == 'l') {
791 } else if (fc == 'q') {
793 } else if (fc == 'L') {
800 if (sz != NOTSPEC || left || sign || space ||
801 alt || zero || prec || fwidth) {
813 if ((tp = *ap++) == NULL) {
818 if ((t1 = tp->t_tspec) == PTR)
819 t2 = tp->t_subt->t_tspec;
821 if (fc == 'd' || fc == 'i') {
822 if (alt || sz == LDOUBLE) {
828 if (t1 != LONG && (hflag || t1 != ULONG))
829 inconarg(hte, call, n);
830 } else if (sz == QUAD) {
831 if (t1 != QUAD && (hflag || t1 != UQUAD))
832 inconarg(hte, call, n);
835 * SHORT is always promoted to INT, USHORT
838 if (t1 != INT && (hflag || t1 != UINT))
839 inconarg(hte, call, n);
841 } else if (fc == 'o' || fc == 'u' || fc == 'x' || fc == 'X') {
842 if ((alt && fc == 'u') || sz == LDOUBLE)
846 if (t1 != ULONG && (hflag || t1 != LONG))
847 inconarg(hte, call, n);
848 } else if (sz == QUAD) {
849 if (t1 != UQUAD && (hflag || t1 != QUAD))
850 inconarg(hte, call, n);
851 } else if (sz == SHORT) {
852 /* USHORT was promoted to INT or UINT */
853 if (t1 != UINT && t1 != INT)
854 inconarg(hte, call, n);
856 if (t1 != UINT && (hflag || t1 != INT))
857 inconarg(hte, call, n);
859 } else if (fc == 'D' || fc == 'O' || fc == 'U') {
860 if ((alt && fc != 'O') || sz != NOTSPEC || !tflag)
868 } else if (fc == 'f' || fc == 'e' || fc == 'E' ||
869 fc == 'g' || fc == 'G') {
872 if (sz != DOUBLE && sz != LDOUBLE)
875 inconarg(hte, call, n);
876 } else if (fc == 'c') {
877 if (sz != NOTSPEC || alt || zero)
880 inconarg(hte, call, n);
881 } else if (fc == 's') {
882 if (sz != NOTSPEC || alt || zero)
885 (t2 != CHAR && t2 != UCHAR && t2 != SCHAR)) {
886 inconarg(hte, call, n);
888 } else if (fc == 'p') {
889 if (fwidth || prec || sz != NOTSPEC || alt || zero)
891 if (t1 != PTR || (hflag && t2 != VOID))
892 inconarg(hte, call, n);
893 } else if (fc == 'n') {
894 if (fwidth || prec || alt || zero || sz == LDOUBLE)
897 inconarg(hte, call, n);
898 } else if (sz == LONG) {
899 if (t2 != LONG && t2 != ULONG)
900 inconarg(hte, call, n);
901 } else if (sz == SHORT) {
902 if (t2 != SHORT && t2 != USHORT)
903 inconarg(hte, call, n);
905 if (t2 != INT && t2 != UINT)
906 inconarg(hte, call, n);
918 * Compare the types in the NULL-terminated array ap with the format
922 scanflike(hte, call, n, fmt, ap)
941 tomanyarg(hte, call);
960 do { fc = *fp++; } while (isdigit(fc));
965 } else if (fc == 'l') {
967 } else if (fc == 'q') {
969 } else if (fc == 'L') {
976 if (sz != NOTSPEC || noasgn || fwidth)
983 if ((tp = *ap++) == NULL) {
988 if ((t1 = tp->t_tspec) == PTR)
989 t2 = tp->t_subt->t_tspec;
992 if (fc == 'd' || fc == 'i' || fc == 'n') {
995 if (sz != SHORT && sz != LONG && sz != QUAD)
1000 inconarg(hte, call, n);
1001 } else if (t2 != styp(sz)) {
1002 inconarg(hte, call, n);
1003 } else if (hflag && t2 != sz) {
1004 inconarg(hte, call, n);
1005 } else if (tp->t_subt->t_const) {
1006 inconarg(hte, call, n);
1009 } else if (fc == 'o' || fc == 'u' || fc == 'x') {
1014 } else if (sz == LONG) {
1016 } else if (sz == QUAD) {
1022 } else if (fc == 'D') {
1023 if (sz != NOTSPEC || !tflag)
1027 } else if (fc == 'O') {
1028 if (sz != NOTSPEC || !tflag)
1032 } else if (fc == 'X') {
1034 * XXX valid in ANSI C, but in NetBSD's libc imple-
1035 * mented as "lx". Thats why it should be avoided.
1037 if (sz != NOTSPEC || !tflag)
1041 } else if (fc == 'E') {
1043 * XXX valid in ANSI C, but in NetBSD's libc imple-
1044 * mented as "lf". Thats why it should be avoided.
1046 if (sz != NOTSPEC || !tflag)
1050 } else if (fc == 'F') {
1051 /* XXX only for backward compatibility */
1052 if (sz != NOTSPEC || !tflag)
1056 } else if (fc == 'G') {
1058 * XXX valid in ANSI C, but in NetBSD's libc not
1061 if (sz != NOTSPEC && sz != LONG && sz != LDOUBLE)
1064 } else if (fc == 'e' || fc == 'f' || fc == 'g') {
1066 if (sz == NOTSPEC) {
1068 } else if (sz == LONG) {
1070 } else if (sz != LDOUBLE) {
1075 } else if (fc == 's' || fc == '[' || fc == 'c') {
1079 if ((fc = *fp++) == '-') {
1091 inconarg(hte, call, n);
1092 } else if (t2 != CHAR && t2 != UCHAR &&
1094 inconarg(hte, call, n);
1097 } else if (fc == 'p') {
1101 if (t1 != PTR || t2 != PTR) {
1102 inconarg(hte, call, n);
1103 } else if (tp->t_subt->t_subt->t_tspec!=VOID) {
1105 inconarg(hte, call, n);
1122 /* %s: malformed format string\t%s */
1123 msg(13, hte->h_name, mkpos(&call->f_pos));
1127 inconarg(hte, call, n)
1132 /* %s, arg %d inconsistent with format\t%s(%d) */
1133 msg(14, hte->h_name, n, mkpos(&call->f_pos));
1141 /* %s: too few args for format \t%s */
1142 msg(15, hte->h_name, mkpos(&call->f_pos));
1146 tomanyarg(hte, call)
1150 /* %s: too many args for format \t%s */
1151 msg(16, hte->h_name, mkpos(&call->f_pos));
1156 * Print warnings for return values which are used, but not returned,
1157 * or return values which are always or sometimes ignored.
1168 /* don't know wheter or not the functions returns a value */
1171 if (hte->h_calls == NULL)
1175 /* function has return value */
1177 for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
1178 used |= call->f_rused;
1179 ignored |= !call->f_rused && !call->f_rdisc;
1182 * XXX as soon as we are able to disable single warnings
1183 * the following dependencies from hflag should be removed.
1184 * but for now I do'nt want to be botherd by this warnings
1185 * which are almost always useless.
1187 if (!used && ignored) {
1189 /* %s returns value which is always ignored */
1190 msg(8, hte->h_name);
1191 } else if (used && ignored) {
1193 /* %s returns value which is sometimes ign. */
1194 msg(9, hte->h_name);
1197 /* function has no return value */
1198 for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
1200 /* %s value is used( %s ), but none ret. */
1201 msg(10, hte->h_name, mkpos(&call->f_pos));
1207 * Print warnings for inconsistent argument declarations.
1210 chkadecl(hte, def, decl)
1214 /* LINTED (automatic hides external declaration: warn) */
1215 int osdef, eq, warn, n;
1217 type_t **ap1, **ap2, *tp1, *tp2;
1223 osdef = def->s_osdef;
1225 } else if (decl != NULL && TP(decl->s_type)->t_proto) {
1230 if (TP(sym1->s_type)->t_tspec != FUNC)
1234 * XXX Prototypes should also be compared with old style function
1238 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
1239 if (sym == sym1 || !TP(sym->s_type)->t_proto)
1241 ap1 = TP(sym1->s_type)->t_args;
1242 ap2 = TP(sym->s_type)->t_args;
1244 while (*ap1 != NULL && *ap2 != NULL) {
1246 eq = eqtype(*ap1, *ap2, 1, osdef, 0, &warn);
1248 pos1 = xstrdup(mkpos(&sym1->s_pos));
1249 pos2 = mkpos(&sym->s_pos);
1250 /* %s, arg %d declared inconsistently ... */
1251 msg(11, hte->h_name, n + 1, pos1, pos2);
1259 tp1 = TP(sym1->s_type);
1260 tp2 = TP(sym->s_type);
1261 if (tp1->t_vararg == tp2->t_vararg)
1263 if (tp2->t_vararg &&
1264 sym1->s_va && sym1->s_nva == n && !sflag) {
1268 /* %s: variable # of args declared\t%s :: %s */
1269 pos1 = xstrdup(mkpos(&sym1->s_pos));
1270 msg(12, hte->h_name, pos1, mkpos(&sym->s_pos));
1277 * Check compatibility of two types. Returns 1 if types are compatible,
1280 * ignqual if set, ignore qualifiers of outhermost type; used for
1281 * function arguments
1282 * promote if set, promote left type before comparision; used for
1283 * comparisions of arguments with parameters of old style
1285 * asgn left indirected type must have at least the same qualifiers
1286 * like right indirected type (for assignments and function
1288 * *warn set to 1 if an old style declaration was compared with
1289 * an incompatible prototype declaration
1292 eqtype(tp1, tp2, ignqual, promot, asgn, warn)
1294 int ignqual, promot, asgn, *warn;
1302 while (tp1 != NULL && tp2 != NULL) {
1308 } else if (t == CHAR || t == SCHAR) {
1310 } else if (t == UCHAR) {
1311 t = tflag ? UINT : INT;
1312 } else if (t == SHORT) {
1314 } else if (t == USHORT) {
1316 t = INT_MAX < USHRT_MAX || tflag ? UINT : INT;
1320 if (asgn && to == PTR) {
1321 if (indir == 1 && (t == VOID || tp2->t_tspec == VOID))
1325 if (t != tp2->t_tspec) {
1327 * Give pointer to types which differ only in
1328 * signedness a chance if not sflag and not hflag.
1330 if (sflag || hflag || to != PTR)
1332 if (styp(t) != styp(tp2->t_tspec))
1336 if (tp1->t_isenum && tp2->t_isenum) {
1337 if (tp1->t_istag && tp2->t_istag) {
1338 return (tp1->t_tag == tp2->t_tag);
1339 } else if (tp1->t_istynam && tp2->t_istynam) {
1340 return (tp1->t_tynam == tp2->t_tynam);
1347 * XXX Handle combinations of enum and int if eflag is set.
1348 * But note: enum and 0 should be allowed.
1351 if (asgn && indir == 1) {
1352 if (!tp1->t_const && tp2->t_const)
1354 if (!tp1->t_volatile && tp2->t_volatile)
1356 } else if (!ignqual && !tflag) {
1357 if (tp1->t_const != tp2->t_const)
1359 if (tp1->t_const != tp2->t_const)
1363 if (t == STRUCT || t == UNION) {
1364 if (tp1->t_istag && tp2->t_istag) {
1365 return (tp1->t_tag == tp2->t_tag);
1366 } else if (tp1->t_istynam && tp2->t_istynam) {
1367 return (tp1->t_tynam == tp2->t_tynam);
1373 if (t == ARRAY && tp1->t_dim != tp2->t_dim) {
1374 if (tp1->t_dim != 0 && tp2->t_dim != 0)
1379 if (tp1->t_proto && tp2->t_proto) {
1380 if (!eqargs(tp1, tp2, warn))
1382 } else if (tp1->t_proto) {
1383 if (!mnoarg(tp1, warn))
1385 } else if (tp2->t_proto) {
1386 if (!mnoarg(tp2, warn))
1393 ignqual = promot = 0;
1399 return (tp1 == tp2);
1403 * Compares arguments of two prototypes
1406 eqargs(tp1, tp2, warn)
1412 if (tp1->t_vararg != tp2->t_vararg)
1418 while (*a1 != NULL && *a2 != NULL) {
1420 if (eqtype(*a1, *a2, 1, 0, 0, warn) == 0)
1428 return (*a1 == *a2);
1432 * mnoarg() (matches functions with no argument type information)
1433 * returns 1 if all parameters of a prototype are compatible with
1434 * and old style function declaration.
1435 * This is the case if following conditions are met:
1436 * 1. the prototype must have a fixed number of parameters
1437 * 2. no parameter is of type float
1438 * 3. no parameter is converted to another type if integer promotion
1449 if (tp->t_vararg && warn != NULL)
1451 for (arg = tp->t_args; *arg != NULL; arg++) {
1452 if ((t = (*arg)->t_tspec) == FLOAT)
1454 if (t == CHAR || t == SCHAR || t == UCHAR)
1456 if (t == SHORT || t == USHORT)