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.
35 static char rcsid[] = "$NetBSD: chk.c,v 1.2 1995/07/03 21:24:42 cgd Exp $";
45 /* various type information */
49 static void chkund __P((hte_t *));
50 static void chkdnu __P((hte_t *));
51 static void chkdnud __P((hte_t *));
52 static void chkmd __P((hte_t *));
53 static void chkvtui __P((hte_t *, sym_t *, sym_t *));
54 static void chkvtdi __P((hte_t *, sym_t *, sym_t *));
55 static void chkfaui __P((hte_t *, sym_t *, sym_t *));
56 static void chkau __P((hte_t *, int, sym_t *, sym_t *, pos_t *,
57 fcall_t *, fcall_t *, type_t *, type_t *));
58 static void chkrvu __P((hte_t *, sym_t *));
59 static void chkadecl __P((hte_t *, sym_t *, sym_t *));
60 static void printflike __P((hte_t *,fcall_t *, int,
61 const char *, type_t **));
62 static void scanflike __P((hte_t *, fcall_t *, int,
63 const char *, type_t **));
64 static void badfmt __P((hte_t *, fcall_t *));
65 static void inconarg __P((hte_t *, fcall_t *, int));
66 static void tofewarg __P((hte_t *, fcall_t *));
67 static void tomanyarg __P((hte_t *, fcall_t *));
68 static int eqtype __P((type_t *, type_t *, int, int, int, int *));
69 static int eqargs __P((type_t *, type_t *, int *));
70 static int mnoarg __P((type_t *, int *));
83 0, 0, 0, 0, 0, "signed" } },
86 0, 0, 0, 0, 0, "unsigned" } },
87 { CHAR, { CHAR_BIT, CHAR_BIT,
89 1, 0, 0, 1, 1, "char" } },
90 { SCHAR, { CHAR_BIT, CHAR_BIT,
92 1, 0, 0, 1, 1, "signed char" } },
93 { UCHAR, { CHAR_BIT, CHAR_BIT,
95 1, 1, 0, 1, 1, "unsigned char" } },
96 { SHORT, { sizeof (short) * CHAR_BIT, 2 * CHAR_BIT,
98 1, 0, 0, 1, 1, "short" } },
99 { USHORT, { sizeof (u_short) * CHAR_BIT, 2 * CHAR_BIT,
101 1, 1, 0, 1, 1, "unsigned short" } },
102 { INT, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT,
104 1, 0, 0, 1, 1, "int" } },
105 { UINT, { sizeof (u_int) * CHAR_BIT, 3 * CHAR_BIT,
107 1, 1, 0, 1, 1, "unsigned int" } },
108 { LONG, { sizeof (long) * CHAR_BIT, 4 * CHAR_BIT,
110 1, 0, 0, 1, 1, "long" } },
111 { ULONG, { sizeof (u_long) * CHAR_BIT, 4 * CHAR_BIT,
113 1, 1, 0, 1, 1, "unsigned long" } },
114 { QUAD, { sizeof (quad_t) * CHAR_BIT, 8 * CHAR_BIT,
116 1, 0, 0, 1, 1, "long long" } },
117 { UQUAD, { sizeof (u_quad_t) * CHAR_BIT, 8 * CHAR_BIT,
119 1, 1, 0, 1, 1, "unsigned long long" } },
120 { FLOAT, { sizeof (float) * CHAR_BIT, 4 * CHAR_BIT,
122 0, 0, 1, 1, 1, "float" } },
123 { DOUBLE, { sizeof (double) * CHAR_BIT, 8 * CHAR_BIT,
125 0, 0, 1, 1, 1, "double" } },
126 { LDOUBLE, { sizeof (ldbl_t) * CHAR_BIT, 10 * CHAR_BIT,
128 0, 0, 1, 1, 1, "long double" } },
131 0, 0, 0, 0, 0, "void" } },
134 0, 0, 0, 0, 0, "struct" } },
137 0, 0, 0, 0, 0, "union" } },
138 { ENUM, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT,
140 1, 0, 0, 1, 1, "enum" } },
141 { PTR, { sizeof (void *) * CHAR_BIT, 4 * CHAR_BIT,
143 0, 1, 0, 0, 1, "pointer" } },
146 0, 0, 0, 0, 0, "array" } },
149 0, 0, 0, 0, 0, "function" } },
152 for (i = 0; i < sizeof (ittab) / sizeof (ittab[0]); i++)
153 STRUCT_ASSIGN(ttab[ittab[i].it_tspec], ittab[i].it_ttab);
155 for (i = 0; i < NTSPEC; i++)
156 ttab[i].tt_psz = ttab[i].tt_sz;
162 * If there is a symbol named "main", mark it as used.
169 if ((hte = hsearch("main", 0)) != NULL)
174 * Performs all tests for a single name
180 sym_t *sym, *def, *pdecl, *decl;
190 /* Get definition, prototype declaration and declaration */
191 def = pdecl = decl = NULL;
192 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
193 if (def == NULL && (sym->s_def == DEF || sym->s_def == TDEF))
195 if (pdecl == NULL && sym->s_def == DECL &&
196 TP(sym->s_type)->t_tspec == FUNC &&
197 TP(sym->s_type)->t_proto) {
200 if (decl == NULL && sym->s_def == DECL)
204 /* A prototype is better than an old style declaration. */
208 chkvtui(hte, def, decl);
210 chkvtdi(hte, def, decl);
212 chkfaui(hte, def, decl);
216 chkadecl(hte, def, decl);
220 * Print a warning if the name has been used, but not defined.
229 if (!hte->h_used || hte->h_def)
232 if ((fcall = hte->h_calls) != NULL) {
233 /* %s used( %s ), but not defined */
234 msg(0, hte->h_name, mkpos(&fcall->f_pos));
235 } else if ((usym = hte->h_usyms) != NULL) {
236 /* %s used( %s ), but not defined */
237 msg(0, hte->h_name, mkpos(&usym->u_pos));
242 * Print a warning if the name has been defined, but never used.
250 if (!hte->h_def || hte->h_used)
253 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
254 if (sym->s_def == DEF || sym->s_def == TDEF) {
255 /* %s defined( %s ), but never used */
256 msg(1, hte->h_name, mkpos(&sym->s_pos));
263 * Print a warning if the name has been declared, but is not used
272 if (hte->h_syms == NULL || hte->h_used || hte->h_def)
275 if ((sym = hte->h_syms) != NULL) {
276 if (sym->s_def != DECL)
277 errx(1, "internal error: chkdnud() 1");
278 /* %s declared( %s ), but never used or defined */
279 msg(2, hte->h_name, mkpos(&sym->s_pos));
284 * Print a warning if there is more then one definition for
298 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
300 * ANSI C allows tentative definitions of the same name in
301 * only one compilation unit.
303 if (sym->s_def != DEF && (!sflag || sym->s_def != TDEF))
309 pos1 = xstrdup(mkpos(&def1->s_pos));
310 /* %s multiply defined\t%s :: %s */
311 msg(3, hte->h_name, pos1, mkpos(&sym->s_pos));
317 * Print a warning if the return value assumed for a function call
318 * differs from the return value of the function definition or
319 * function declaration.
321 * If no definition/declaration can be found, the assumed return values
322 * are always int. So there is no need to compare with another function
323 * call as it's done for function arguments.
326 chkvtui(hte, def, decl)
333 /* LINTED (automatic hides external declaration: warn) */
337 if (hte->h_calls == NULL)
345 t1 = (tp1 = TP(def->s_type)->t_subt)->t_tspec;
346 for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
347 tp2 = TP(call->f_type)->t_subt;
348 eq = eqtype(tp1, tp2, 1, 0, 0, (warn = 0, &warn));
349 if (!call->f_rused) {
350 /* no return value used */
351 if ((t1 == STRUCT || t1 == UNION) && !eq) {
353 * If a function returns a struct or union it
354 * must be declared to return a struct or
355 * union, also if the return value is ignored.
356 * This is necessary because the caller must
357 * allocate stack space for the return value.
358 * If it does not, the return value would over-
360 * XXX Following massage may be confusing
361 * because it appears also if the return value
362 * was declared inconsistently. But this
363 * behaviour matches pcc based lint, so it is
366 pos1 = xstrdup(mkpos(&def->s_pos));
367 /* %s value must be decl. before use %s :: %s */
369 pos1, mkpos(&call->f_pos));
374 if (!eq || (sflag && warn)) {
375 pos1 = xstrdup(mkpos(&def->s_pos));
376 /* %s value used inconsistenty\t%s :: %s */
377 msg(4, hte->h_name, pos1, mkpos(&call->f_pos));
384 * Print a warning if a definition/declaration does not match another
385 * definition/declaration of the same name. For functions, only the
386 * types of return values are tested.
389 chkvtdi(hte, def, decl)
395 /* LINTED (automatic hides external declaration: warn) */
404 tp1 = TP(def->s_type);
405 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
408 tp2 = TP(sym->s_type);
410 if (tp1->t_tspec == FUNC && tp2->t_tspec == FUNC) {
411 eq = eqtype(tp1->t_subt, tp2->t_subt, 1, 0, 0, &warn);
413 eq = eqtype(tp1, tp2, 0, 0, 0, &warn);
415 if (!eq || (sflag && warn)) {
416 pos1 = xstrdup(mkpos(&def->s_pos));
417 /* %s value declared inconsistently\t%s :: %s */
418 msg(5, hte->h_name, pos1, mkpos(&sym->s_pos));
425 * Print a warning if a function is called with arguments which does
426 * not match the function definition, declaration or another call
427 * of the same function.
430 chkfaui(hte, def, decl)
434 type_t *tp1, *tp2, **ap1, **ap2;
436 fcall_t *calls, *call, *call1;
441 if ((calls = hte->h_calls) == NULL)
445 * If we find a function definition, we use this for comparision,
446 * otherwise the first prototype we can find. If there is no
447 * definition or prototype declaration, the first function call
453 if ((tp1 = TP(def->s_type))->t_tspec != FUNC)
456 } else if (decl != NULL && TP(decl->s_type)->t_proto) {
457 if ((tp1 = TP(decl->s_type))->t_tspec != FUNC)
459 pos1p = &decl->s_pos;
463 calls = calls->f_nxt;
464 if ((tp1 = TP(call1->f_type))->t_tspec != FUNC)
466 pos1p = &call1->f_pos;
470 for (call = calls; call != NULL; call = call->f_nxt) {
471 if ((tp2 = TP(call->f_type))->t_tspec != FUNC)
476 while (*ap1 != NULL && *ap2 != NULL) {
477 if (def != NULL && def->s_va && n >= def->s_nva)
480 chkau(hte, n, def, decl, pos1p, call1, call,
486 /* equal # of arguments */
487 } else if (def != NULL && def->s_va && n >= def->s_nva) {
489 * function definition with VARARGS; The # of
490 * arguments of the call must be at least as large
491 * as the parameter of VARARGS.
493 } else if (*ap2 != NULL && tp1->t_proto && tp1->t_vararg) {
495 * prototype with ... and function call with
496 * at least the same # of arguments as declared
500 pos1 = xstrdup(mkpos(pos1p));
501 /* %s: variable # of args\t%s :: %s */
502 msg(7, hte->h_name, pos1, mkpos(&call->f_pos));
507 /* perform SCANFLIKE/PRINTFLIKE tests */
508 if (def == NULL || (!def->s_prfl && !def->s_scfl))
510 as = def->s_prfl ? def->s_nprfl : def->s_nscfl;
511 for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) {
515 if (ai == NULL || !ai->a_fmt)
518 printflike(hte, call, n, ai->a_fstrg, ap2);
520 scanflike(hte, call, n, ai->a_fstrg, ap2);
526 * Check a single argument in a function call.
528 * hte a pointer to the hash table entry of the function
529 * n the number of the argument (1..)
530 * def the function definition or NULL
531 * decl prototype declaration, old style declaration or NULL
532 * pos1p position of definition, declaration of first call
533 * call1 first call, if both def and decl are old style def/decl
535 * arg1 currently checked argument of def/decl/call1
536 * arg2 currently checked argument of call
540 chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2)
545 fcall_t *call1, *call;
548 /* LINTED (automatic hides external declaration: warn) */
549 int promote, asgn, warn;
555 * If a function definition is available (def != NULL), we compair the
556 * function call (call) with the definition. Otherwise, if a function
557 * definition is available and it is not an old style definition
558 * (decl != NULL && TP(decl->s_type)->t_proto), we compair the call
559 * with this declaration. Otherwise we compair it with the first
560 * call we have found (call1).
563 /* arg1 must be promoted if it stems from an old style definition */
564 promote = def != NULL && def->s_osdef;
567 * If we compair with a definition or declaration, we must perform
568 * the same checks for qualifiers in indirected types as in
571 asgn = def != NULL || (decl != NULL && TP(decl->s_type)->t_proto);
574 if (eqtype(arg1, arg2, 1, promote, asgn, &warn) && (!sflag || !warn))
578 * Other lint implementations print warnings as soon as the type
579 * of an argument does not match exactly the expected type. The
580 * result are lots of warnings which are really not neccessary.
581 * We print a warning only if
582 * (0) at least one type is not an interger type and types differ
583 * (1) hflag is set and types differ
584 * (2) types differ, except in signedness
585 * If the argument is an integer constant whose msb is not set,
586 * signedness is ignored (e.g. 0 matches both signed and unsigned
587 * int). This is with and without hflag.
588 * If the argument is an integer constant with value 0 and the
589 * expected argument is of type pointer and the width of the
590 * interger constant is the same as the width of the pointer,
591 * no warning is printed.
595 if (isityp(t1) && isityp(t2) && !arg1->t_isenum && !arg2->t_isenum) {
598 * XXX Here is a problem: Althrough it is possible to
599 * pass an int where a char/short it expected, there
600 * may be loss in significant digits. We should first
601 * check for const arguments if they can be converted
602 * into the original parameter type.
606 } else if (t1 == CHAR || t1 == SCHAR) {
608 } else if (t1 == UCHAR) {
609 t1 = tflag ? UINT : INT;
610 } else if (t1 == SHORT) {
612 } else if (t1 == USHORT) {
614 t1 = INT_MAX < USHRT_MAX || tflag ? UINT : INT;
618 if (styp(t1) == styp(t2)) {
621 * types differ only in signedness; get information
626 * treat a definition like a call with variable
629 ai1 = call1 != NULL ? call1->f_args : NULL;
632 * if two calls are compared, ai1 is set to the
633 * information for the n-th argument, if this was
634 * a constant, otherwise to NULL
636 for ( ; ai1 != NULL; ai1 = ai1->a_nxt) {
641 * ai is set to the information of the n-th arg
642 * of the (second) call, if this was a constant,
645 for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) {
650 if (ai1 == NULL && ai == NULL) {
651 /* no constant at all */
654 } else if (ai1 == NULL || ai == NULL) {
658 if (ai->a_zero || ai->a_pcon)
659 /* same value in signed and unsigned */
661 /* value (not representation) differently */
664 * two constants, one signed, one unsigned;
665 * if the msb of one of the constants is set,
666 * the argument is used inconsistently.
668 if (!ai1->a_ncon && !ai->a_ncon)
673 } else if (t1 == PTR && isityp(t2) && psize(t1) == psize(t2)) {
674 for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) {
678 if (ai != NULL && ai->a_zero)
682 pos1 = xstrdup(mkpos(pos1p));
683 /* %s, arg %d used inconsistently\t%s :: %s */
684 msg(6, hte->h_name, n, pos1, mkpos(&call->f_pos));
689 * Compare the types in the NULL-terminated array ap with the format
693 printflike(hte, call, n, fmt, ap)
702 int fwidth, prec, left, sign, space, alt, zero;
712 tomanyarg(hte, call);
720 fwidth = prec = left = sign = space = alt = zero = 0;
729 } else if (fc == '+') {
733 } else if (fc == ' ') {
737 } else if (fc == '#') {
741 } else if (fc == '0') {
754 do { fc = *fp++; } while (isdigit(fc)) ;
755 } else if (fc == '*') {
758 if ((tp = *ap++) == NULL) {
763 if ((t1 = tp->t_tspec) != INT && (hflag || t1 != UINT))
764 inconarg(hte, call, n);
772 do { fc = *fp++; } while (isdigit(fc));
773 } else if (fc == '*') {
775 if ((tp = *ap++) == NULL) {
780 if (tp->t_tspec != INT)
781 inconarg(hte, call, n);
790 } else if (fc == 'l') {
792 } else if (fc == 'q') {
794 } else if (fc == 'L') {
801 if (sz != NOTSPEC || left || sign || space ||
802 alt || zero || prec || fwidth) {
814 if ((tp = *ap++) == NULL) {
819 if ((t1 = tp->t_tspec) == PTR)
820 t2 = tp->t_subt->t_tspec;
822 if (fc == 'd' || fc == 'i') {
823 if (alt || sz == LDOUBLE) {
829 if (t1 != LONG && (hflag || t1 != ULONG))
830 inconarg(hte, call, n);
831 } else if (sz == QUAD) {
832 if (t1 != QUAD && (hflag || t1 != UQUAD))
833 inconarg(hte, call, n);
836 * SHORT is always promoted to INT, USHORT
839 if (t1 != INT && (hflag || t1 != UINT))
840 inconarg(hte, call, n);
842 } else if (fc == 'o' || fc == 'u' || fc == 'x' || fc == 'X') {
843 if ((alt && fc == 'u') || sz == LDOUBLE)
847 if (t1 != ULONG && (hflag || t1 != LONG))
848 inconarg(hte, call, n);
849 } else if (sz == QUAD) {
850 if (t1 != UQUAD && (hflag || t1 != QUAD))
851 inconarg(hte, call, n);
852 } else if (sz == SHORT) {
853 /* USHORT was promoted to INT or UINT */
854 if (t1 != UINT && t1 != INT)
855 inconarg(hte, call, n);
857 if (t1 != UINT && (hflag || t1 != INT))
858 inconarg(hte, call, n);
860 } else if (fc == 'D' || fc == 'O' || fc == 'U') {
861 if ((alt && fc != 'O') || sz != NOTSPEC || !tflag)
869 } else if (fc == 'f' || fc == 'e' || fc == 'E' ||
870 fc == 'g' || fc == 'G') {
873 if (sz != DOUBLE && sz != LDOUBLE)
876 inconarg(hte, call, n);
877 } else if (fc == 'c') {
878 if (sz != NOTSPEC || alt || zero)
881 inconarg(hte, call, n);
882 } else if (fc == 's') {
883 if (sz != NOTSPEC || alt || zero)
886 (t2 != CHAR && t2 != UCHAR && t2 != SCHAR)) {
887 inconarg(hte, call, n);
889 } else if (fc == 'p') {
890 if (fwidth || prec || sz != NOTSPEC || alt || zero)
892 if (t1 != PTR || (hflag && t2 != VOID))
893 inconarg(hte, call, n);
894 } else if (fc == 'n') {
895 if (fwidth || prec || alt || zero || sz == LDOUBLE)
898 inconarg(hte, call, n);
899 } else if (sz == LONG) {
900 if (t2 != LONG && t2 != ULONG)
901 inconarg(hte, call, n);
902 } else if (sz == SHORT) {
903 if (t2 != SHORT && t2 != USHORT)
904 inconarg(hte, call, n);
906 if (t2 != INT && t2 != UINT)
907 inconarg(hte, call, n);
919 * Compare the types in the NULL-terminated array ap with the format
923 scanflike(hte, call, n, fmt, ap)
942 tomanyarg(hte, call);
961 do { fc = *fp++; } while (isdigit(fc));
966 } else if (fc == 'l') {
968 } else if (fc == 'q') {
970 } else if (fc == 'L') {
977 if (sz != NOTSPEC || noasgn || fwidth)
984 if ((tp = *ap++) == NULL) {
989 if ((t1 = tp->t_tspec) == PTR)
990 t2 = tp->t_subt->t_tspec;
993 if (fc == 'd' || fc == 'i' || fc == 'n') {
996 if (sz != SHORT && sz != LONG && sz != QUAD)
1001 inconarg(hte, call, n);
1002 } else if (t2 != styp(sz)) {
1003 inconarg(hte, call, n);
1004 } else if (hflag && t2 != sz) {
1005 inconarg(hte, call, n);
1006 } else if (tp->t_subt->t_const) {
1007 inconarg(hte, call, n);
1010 } else if (fc == 'o' || fc == 'u' || fc == 'x') {
1015 } else if (sz == LONG) {
1017 } else if (sz == QUAD) {
1023 } else if (fc == 'D') {
1024 if (sz != NOTSPEC || !tflag)
1028 } else if (fc == 'O') {
1029 if (sz != NOTSPEC || !tflag)
1033 } else if (fc == 'X') {
1035 * XXX valid in ANSI C, but in NetBSD's libc imple-
1036 * mented as "lx". Thats why it should be avoided.
1038 if (sz != NOTSPEC || !tflag)
1042 } else if (fc == 'E') {
1044 * XXX valid in ANSI C, but in NetBSD's libc imple-
1045 * mented as "lf". Thats why it should be avoided.
1047 if (sz != NOTSPEC || !tflag)
1051 } else if (fc == 'F') {
1052 /* XXX only for backward compatibility */
1053 if (sz != NOTSPEC || !tflag)
1057 } else if (fc == 'G') {
1059 * XXX valid in ANSI C, but in NetBSD's libc not
1062 if (sz != NOTSPEC && sz != LONG && sz != LDOUBLE)
1065 } else if (fc == 'e' || fc == 'f' || fc == 'g') {
1067 if (sz == NOTSPEC) {
1069 } else if (sz == LONG) {
1071 } else if (sz != LDOUBLE) {
1076 } else if (fc == 's' || fc == '[' || fc == 'c') {
1080 if ((fc = *fp++) == '-') {
1092 inconarg(hte, call, n);
1093 } else if (t2 != CHAR && t2 != UCHAR &&
1095 inconarg(hte, call, n);
1098 } else if (fc == 'p') {
1102 if (t1 != PTR || t2 != PTR) {
1103 inconarg(hte, call, n);
1104 } else if (tp->t_subt->t_subt->t_tspec!=VOID) {
1106 inconarg(hte, call, n);
1123 /* %s: malformed format string\t%s */
1124 msg(13, hte->h_name, mkpos(&call->f_pos));
1128 inconarg(hte, call, n)
1133 /* %s, arg %d inconsistent with format\t%s(%d) */
1134 msg(14, hte->h_name, n, mkpos(&call->f_pos));
1142 /* %s: too few args for format \t%s */
1143 msg(15, hte->h_name, mkpos(&call->f_pos));
1147 tomanyarg(hte, call)
1151 /* %s: too many args for format \t%s */
1152 msg(16, hte->h_name, mkpos(&call->f_pos));
1157 * Print warnings for return values which are used, but not returned,
1158 * or return values which are always or sometimes ignored.
1169 /* don't know wheter or not the functions returns a value */
1172 if (hte->h_calls == NULL)
1176 /* function has return value */
1178 for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
1179 used |= call->f_rused;
1180 ignored |= !call->f_rused && !call->f_rdisc;
1183 * XXX as soon as we are able to disable single warnings
1184 * the following dependencies from hflag should be removed.
1185 * but for now I do'nt want to be botherd by this warnings
1186 * which are almost always useless.
1188 if (!used && ignored) {
1190 /* %s returns value which is always ignored */
1191 msg(8, hte->h_name);
1192 } else if (used && ignored) {
1194 /* %s returns value which is sometimes ign. */
1195 msg(9, hte->h_name);
1198 /* function has no return value */
1199 for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
1201 /* %s value is used( %s ), but none ret. */
1202 msg(10, hte->h_name, mkpos(&call->f_pos));
1208 * Print warnings for inconsistent argument declarations.
1211 chkadecl(hte, def, decl)
1215 /* LINTED (automatic hides external declaration: warn) */
1216 int osdef, eq, warn, n;
1218 type_t **ap1, **ap2, *tp1, *tp2;
1224 osdef = def->s_osdef;
1226 } else if (decl != NULL && TP(decl->s_type)->t_proto) {
1231 if (TP(sym1->s_type)->t_tspec != FUNC)
1235 * XXX Prototypes should also be compared with old style function
1239 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
1240 if (sym == sym1 || !TP(sym->s_type)->t_proto)
1242 ap1 = TP(sym1->s_type)->t_args;
1243 ap2 = TP(sym->s_type)->t_args;
1245 while (*ap1 != NULL && *ap2 != NULL) {
1247 eq = eqtype(*ap1, *ap2, 1, osdef, 0, &warn);
1249 pos1 = xstrdup(mkpos(&sym1->s_pos));
1250 pos2 = mkpos(&sym->s_pos);
1251 /* %s, arg %d declared inconsistently ... */
1252 msg(11, hte->h_name, n + 1, pos1, pos2);
1260 tp1 = TP(sym1->s_type);
1261 tp2 = TP(sym->s_type);
1262 if (tp1->t_vararg == tp2->t_vararg)
1264 if (tp2->t_vararg &&
1265 sym1->s_va && sym1->s_nva == n && !sflag) {
1269 /* %s: variable # of args declared\t%s :: %s */
1270 pos1 = xstrdup(mkpos(&sym1->s_pos));
1271 msg(12, hte->h_name, pos1, mkpos(&sym->s_pos));
1278 * Check compatibility of two types. Returns 1 if types are compatible,
1281 * ignqual if set, ignore qualifiers of outhermost type; used for
1282 * function arguments
1283 * promote if set, promote left type before comparision; used for
1284 * comparisions of arguments with parameters of old style
1286 * asgn left indirected type must have at least the same qualifiers
1287 * like right indirected type (for assignments and function
1289 * *warn set to 1 if an old style declaration was compared with
1290 * an incompatible prototype declaration
1293 eqtype(tp1, tp2, ignqual, promot, asgn, warn)
1295 int ignqual, promot, asgn, *warn;
1303 while (tp1 != NULL && tp2 != NULL) {
1309 } else if (t == CHAR || t == SCHAR) {
1311 } else if (t == UCHAR) {
1312 t = tflag ? UINT : INT;
1313 } else if (t == SHORT) {
1315 } else if (t == USHORT) {
1317 t = INT_MAX < USHRT_MAX || tflag ? UINT : INT;
1321 if (asgn && to == PTR) {
1322 if (indir == 1 && (t == VOID || tp2->t_tspec == VOID))
1326 if (t != tp2->t_tspec) {
1328 * Give pointer to types which differ only in
1329 * signedness a chance if not sflag and not hflag.
1331 if (sflag || hflag || to != PTR)
1333 if (styp(t) != styp(tp2->t_tspec))
1337 if (tp1->t_isenum && tp2->t_isenum) {
1338 if (tp1->t_istag && tp2->t_istag) {
1339 return (tp1->t_tag == tp2->t_tag);
1340 } else if (tp1->t_istynam && tp2->t_istynam) {
1341 return (tp1->t_tynam == tp2->t_tynam);
1348 * XXX Handle combinations of enum and int if eflag is set.
1349 * But note: enum and 0 should be allowed.
1352 if (asgn && indir == 1) {
1353 if (!tp1->t_const && tp2->t_const)
1355 if (!tp1->t_volatile && tp2->t_volatile)
1357 } else if (!ignqual && !tflag) {
1358 if (tp1->t_const != tp2->t_const)
1360 if (tp1->t_const != tp2->t_const)
1364 if (t == STRUCT || t == UNION) {
1365 if (tp1->t_istag && tp2->t_istag) {
1366 return (tp1->t_tag == tp2->t_tag);
1367 } else if (tp1->t_istynam && tp2->t_istynam) {
1368 return (tp1->t_tynam == tp2->t_tynam);
1374 if (t == ARRAY && tp1->t_dim != tp2->t_dim) {
1375 if (tp1->t_dim != 0 && tp2->t_dim != 0)
1380 if (tp1->t_proto && tp2->t_proto) {
1381 if (!eqargs(tp1, tp2, warn))
1383 } else if (tp1->t_proto) {
1384 if (!mnoarg(tp1, warn))
1386 } else if (tp2->t_proto) {
1387 if (!mnoarg(tp2, warn))
1394 ignqual = promot = 0;
1400 return (tp1 == tp2);
1404 * Compares arguments of two prototypes
1407 eqargs(tp1, tp2, warn)
1413 if (tp1->t_vararg != tp2->t_vararg)
1419 while (*a1 != NULL && *a2 != NULL) {
1421 if (eqtype(*a1, *a2, 1, 0, 0, warn) == 0)
1429 return (*a1 == *a2);
1433 * mnoarg() (matches functions with no argument type information)
1434 * returns 1 if all parameters of a prototype are compatible with
1435 * and old style function declaration.
1436 * This is the case if following conditions are met:
1437 * 1. the prototype must have a fixed number of parameters
1438 * 2. no parameter is of type float
1439 * 3. no parameter is converted to another type if integer promotion
1450 if (tp->t_vararg && warn != NULL)
1452 for (arg = tp->t_args; *arg != NULL; arg++) {
1453 if ((t = (*arg)->t_tspec) == FLOAT)
1455 if (t == CHAR || t == SCHAR || t == UCHAR)
1457 if (t == SHORT || t == USHORT)