1 /* $NetBSD: chk.c,v 1.15 2002/01/21 19:49:52 tv 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 #include <sys/cdefs.h>
36 #if defined(__RCSID) && !defined(lint)
37 __RCSID("$NetBSD: chk.c,v 1.15 2002/01/21 19:49:52 tv Exp $");
46 static void chkund(hte_t *);
47 static void chkdnu(hte_t *);
48 static void chkdnud(hte_t *);
49 static void chkmd(hte_t *);
50 static void chkvtui(hte_t *, sym_t *, sym_t *);
51 static void chkvtdi(hte_t *, sym_t *, sym_t *);
52 static void chkfaui(hte_t *, sym_t *, sym_t *);
53 static void chkau(hte_t *, int, sym_t *, sym_t *, pos_t *,
54 fcall_t *, fcall_t *, type_t *, type_t *);
55 static void chkrvu(hte_t *, sym_t *);
56 static void chkadecl(hte_t *, sym_t *, sym_t *);
57 static void printflike(hte_t *,fcall_t *, int, const char *, type_t **);
58 static void scanflike(hte_t *, fcall_t *, int, const char *, type_t **);
59 static void badfmt(hte_t *, fcall_t *);
60 static void inconarg(hte_t *, fcall_t *, int);
61 static void tofewarg(hte_t *, fcall_t *);
62 static void tomanyarg(hte_t *, fcall_t *);
63 static int eqtype(type_t *, type_t *, int, int, int, int *);
64 static int eqargs(type_t *, type_t *, int *);
65 static int mnoarg(type_t *, int *);
69 * If there is a symbol named "main", mark it as used.
76 if ((hte = hsearch("main", 0)) != NULL)
81 * Performs all tests for a single name
86 sym_t *sym, *def, *pdecl, *decl;
96 /* Get definition, prototype declaration and declaration */
97 def = pdecl = decl = NULL;
98 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
99 if (def == NULL && (sym->s_def == DEF || sym->s_def == TDEF))
101 if (pdecl == NULL && sym->s_def == DECL &&
102 TP(sym->s_type)->t_tspec == FUNC &&
103 TP(sym->s_type)->t_proto) {
106 if (decl == NULL && sym->s_def == DECL)
110 /* A prototype is better than an old style declaration. */
114 chkvtui(hte, def, decl);
116 chkvtdi(hte, def, decl);
118 chkfaui(hte, def, decl);
122 chkadecl(hte, def, decl);
126 * Print a warning if the name has been used, but not defined.
134 if (!hte->h_used || hte->h_def)
137 if ((fcall = hte->h_calls) != NULL) {
138 /* %s used( %s ), but not defined */
139 msg(0, hte->h_name, mkpos(&fcall->f_pos));
140 } else if ((usym = hte->h_usyms) != NULL) {
141 /* %s used( %s ), but not defined */
142 msg(0, hte->h_name, mkpos(&usym->u_pos));
147 * Print a warning if the name has been defined, but never used.
154 if (!hte->h_def || hte->h_used)
157 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
158 if (sym->s_def == DEF || sym->s_def == TDEF) {
159 /* %s defined( %s ), but never used */
160 msg(1, hte->h_name, mkpos(&sym->s_pos));
167 * Print a warning if the variable has been declared, but is not used
175 if (hte->h_syms == NULL || hte->h_used || hte->h_def)
179 if (TP(sym->s_type)->t_tspec == FUNC)
182 if (sym->s_def != DECL)
183 errx(1, "internal error: chkdnud() 1");
184 /* %s declared( %s ), but never used or defined */
185 msg(2, hte->h_name, mkpos(&sym->s_pos));
189 * Print a warning if there is more than one definition for
202 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
204 * ANSI C allows tentative definitions of the same name in
205 * only one compilation unit.
207 if (sym->s_def != DEF && (!sflag || sym->s_def != TDEF))
213 pos1 = xstrdup(mkpos(&def1->s_pos));
214 /* %s multiply defined\t%s :: %s */
215 msg(3, hte->h_name, pos1, mkpos(&sym->s_pos));
221 * Print a warning if the return value assumed for a function call
222 * differs from the return value of the function definition or
223 * function declaration.
225 * If no definition/declaration can be found, the assumed return values
226 * are always int. So there is no need to compare with another function
227 * call as it's done for function arguments.
230 chkvtui(hte_t *hte, sym_t *def, sym_t *decl)
235 /* LINTED (automatic hides external declaration: warn) */
239 if (hte->h_calls == NULL)
247 t1 = (tp1 = TP(def->s_type)->t_subt)->t_tspec;
248 for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
249 tp2 = TP(call->f_type)->t_subt;
250 eq = eqtype(tp1, tp2, 1, 0, 0, (warn = 0, &warn));
251 if (!call->f_rused) {
252 /* no return value used */
253 if ((t1 == STRUCT || t1 == UNION) && !eq) {
255 * If a function returns a struct or union it
256 * must be declared to return a struct or
257 * union, also if the return value is ignored.
258 * This is necessary because the caller must
259 * allocate stack space for the return value.
260 * If it does not, the return value would over-
262 * XXX Following massage may be confusing
263 * because it appears also if the return value
264 * was declared inconsistently. But this
265 * behaviour matches pcc based lint, so it is
268 pos1 = xstrdup(mkpos(&def->s_pos));
269 /* %s value must be decl. before use %s :: %s */
271 pos1, mkpos(&call->f_pos));
276 if (!eq || (sflag && warn)) {
277 pos1 = xstrdup(mkpos(&def->s_pos));
278 /* %s value used inconsistenty\t%s :: %s */
279 msg(4, hte->h_name, pos1, mkpos(&call->f_pos));
286 * Print a warning if a definition/declaration does not match another
287 * definition/declaration of the same name. For functions, only the
288 * types of return values are tested.
291 chkvtdi(hte_t *hte, sym_t *def, sym_t *decl)
295 /* LINTED (automatic hides external declaration: warn) */
304 tp1 = TP(def->s_type);
305 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
308 tp2 = TP(sym->s_type);
310 if (tp1->t_tspec == FUNC && tp2->t_tspec == FUNC) {
311 eq = eqtype(tp1->t_subt, tp2->t_subt, 1, 0, 0, &warn);
313 eq = eqtype(tp1, tp2, 0, 0, 0, &warn);
315 if (!eq || (sflag && warn)) {
316 pos1 = xstrdup(mkpos(&def->s_pos));
317 /* %s value declared inconsistently\t%s :: %s */
318 msg(5, hte->h_name, pos1, mkpos(&sym->s_pos));
325 * Print a warning if a function is called with arguments which does
326 * not match the function definition, declaration or another call
327 * of the same function.
330 chkfaui(hte_t *hte, sym_t *def, sym_t *decl)
332 type_t *tp1, *tp2, **ap1, **ap2;
334 fcall_t *calls, *call, *call1;
339 if ((calls = hte->h_calls) == NULL)
343 * If we find a function definition, we use this for comparison,
344 * otherwise the first prototype we can find. If there is no
345 * definition or prototype declaration, the first function call
351 if ((tp1 = TP(def->s_type))->t_tspec != FUNC)
354 } else if (decl != NULL && TP(decl->s_type)->t_proto) {
355 if ((tp1 = TP(decl->s_type))->t_tspec != FUNC)
357 pos1p = &decl->s_pos;
361 calls = calls->f_nxt;
362 if ((tp1 = TP(call1->f_type))->t_tspec != FUNC)
364 pos1p = &call1->f_pos;
368 for (call = calls; call != NULL; call = call->f_nxt) {
369 if ((tp2 = TP(call->f_type))->t_tspec != FUNC)
374 while (*ap1 != NULL && *ap2 != NULL) {
375 if (def != NULL && def->s_va && n >= def->s_nva)
378 chkau(hte, n, def, decl, pos1p, call1, call,
384 /* equal # of arguments */
385 } else if (def != NULL && def->s_va && n >= def->s_nva) {
387 * function definition with VARARGS; The # of
388 * arguments of the call must be at least as large
389 * as the parameter of VARARGS.
391 } else if (*ap2 != NULL && tp1->t_proto && tp1->t_vararg) {
393 * prototype with ... and function call with
394 * at least the same # of arguments as declared
398 pos1 = xstrdup(mkpos(pos1p));
399 /* %s: variable # of args\t%s :: %s */
400 msg(7, hte->h_name, pos1, mkpos(&call->f_pos));
405 /* perform SCANFLIKE/PRINTFLIKE tests */
406 if (def == NULL || (!def->s_prfl && !def->s_scfl))
408 as = def->s_prfl ? def->s_nprfl : def->s_nscfl;
409 for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) {
413 if (ai == NULL || !ai->a_fmt)
416 printflike(hte, call, n, ai->a_fstrg, ap2);
418 scanflike(hte, call, n, ai->a_fstrg, ap2);
424 * Check a single argument in a function call.
426 * hte a pointer to the hash table entry of the function
427 * n the number of the argument (1..)
428 * def the function definition or NULL
429 * decl prototype declaration, old style declaration or NULL
430 * pos1p position of definition, declaration of first call
431 * call1 first call, if both def and decl are old style def/decl
433 * arg1 currently checked argument of def/decl/call1
434 * arg2 currently checked argument of call
438 chkau(hte_t *hte, int n, sym_t *def, sym_t *decl, pos_t *pos1p,
439 fcall_t *call1, fcall_t *call, type_t *arg1, type_t *arg2)
441 /* LINTED (automatic hides external declaration: warn) */
442 int promote, asgn, warn;
448 * If a function definition is available (def != NULL), we compair the
449 * function call (call) with the definition. Otherwise, if a function
450 * definition is available and it is not an old style definition
451 * (decl != NULL && TP(decl->s_type)->t_proto), we compair the call
452 * with this declaration. Otherwise we compair it with the first
453 * call we have found (call1).
456 /* arg1 must be promoted if it stems from an old style definition */
457 promote = def != NULL && def->s_osdef;
460 * If we compair with a definition or declaration, we must perform
461 * the same checks for qualifiers in indirected types as in
464 asgn = def != NULL || (decl != NULL && TP(decl->s_type)->t_proto);
467 if (eqtype(arg1, arg2, 1, promote, asgn, &warn) && (!sflag || !warn))
471 * Other lint implementations print warnings as soon as the type
472 * of an argument does not match exactly the expected type. The
473 * result are lots of warnings which are really not necessary.
474 * We print a warning only if
475 * (0) at least one type is not an interger type and types differ
476 * (1) hflag is set and types differ
477 * (2) types differ, except in signedness
478 * If the argument is an integer constant whose msb is not set,
479 * signedness is ignored (e.g. 0 matches both signed and unsigned
480 * int). This is with and without hflag.
481 * If the argument is an integer constant with value 0 and the
482 * expected argument is of type pointer and the width of the
483 * interger constant is the same as the width of the pointer,
484 * no warning is printed.
488 if (isityp(t1) && isityp(t2) && !arg1->t_isenum && !arg2->t_isenum) {
491 * XXX Here is a problem: Althrough it is possible to
492 * pass an int where a char/short it expected, there
493 * may be loss in significant digits. We should first
494 * check for const arguments if they can be converted
495 * into the original parameter type.
499 } else if (t1 == CHAR || t1 == SCHAR) {
501 } else if (t1 == UCHAR) {
502 t1 = tflag ? UINT : INT;
503 } else if (t1 == SHORT) {
505 } else if (t1 == USHORT) {
507 t1 = INT_MAX < USHRT_MAX || tflag ? UINT : INT;
511 if (styp(t1) == styp(t2)) {
514 * types differ only in signedness; get information
519 * treat a definition like a call with variable
522 ai1 = call1 != NULL ? call1->f_args : NULL;
525 * if two calls are compared, ai1 is set to the
526 * information for the n-th argument, if this was
527 * a constant, otherwise to NULL
529 for ( ; ai1 != NULL; ai1 = ai1->a_nxt) {
534 * ai is set to the information of the n-th arg
535 * of the (second) call, if this was a constant,
538 for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) {
543 if (ai1 == NULL && ai == NULL) {
544 /* no constant at all */
547 } else if (ai1 == NULL || ai == NULL) {
551 if (ai->a_zero || ai->a_pcon)
552 /* same value in signed and unsigned */
554 /* value (not representation) differently */
557 * two constants, one signed, one unsigned;
558 * if the msb of one of the constants is set,
559 * the argument is used inconsistently.
561 if (!ai1->a_ncon && !ai->a_ncon)
566 } else if (t1 == PTR && isityp(t2)) {
567 for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) {
572 * Vendor implementations of lint (e.g. HP-UX, Digital UNIX)
573 * don't care about the size of the integer argument,
574 * only whether or not it is zero. We do the same.
576 if (ai != NULL && ai->a_zero)
580 pos1 = xstrdup(mkpos(pos1p));
581 /* %s, arg %d used inconsistently\t%s :: %s */
582 msg(6, hte->h_name, n, pos1, mkpos(&call->f_pos));
587 * Compare the types in the NULL-terminated array ap with the format
591 printflike(hte_t *hte, fcall_t *call, int n, const char *fmt, type_t **ap)
595 int fwidth, prec, left, sign, space, alt, zero;
596 tspec_t sz, t1, t2 = NOTSPEC;
605 tomanyarg(hte, call);
613 fwidth = prec = left = sign = space = alt = zero = 0;
622 } else if (fc == '+') {
626 } else if (fc == ' ') {
630 } else if (fc == '#') {
634 } else if (fc == '0') {
647 do { fc = *fp++; } while (isdigit(fc)) ;
648 } else if (fc == '*') {
651 if ((tp = *ap++) == NULL) {
656 if ((t1 = tp->t_tspec) != INT && (hflag || t1 != UINT))
657 inconarg(hte, call, n);
665 do { fc = *fp++; } while (isdigit(fc));
666 } else if (fc == '*') {
668 if ((tp = *ap++) == NULL) {
673 if (tp->t_tspec != INT)
674 inconarg(hte, call, n);
683 } else if (fc == 'l') {
685 } else if (fc == 'q') {
687 } else if (fc == 'L') {
694 if (sz != NOTSPEC || left || sign || space ||
695 alt || zero || prec || fwidth) {
707 if ((tp = *ap++) == NULL) {
712 if ((t1 = tp->t_tspec) == PTR)
713 t2 = tp->t_subt->t_tspec;
715 if (fc == 'd' || fc == 'i') {
716 if (alt || sz == LDOUBLE) {
722 if (t1 != LONG && (hflag || t1 != ULONG))
723 inconarg(hte, call, n);
724 } else if (sz == QUAD) {
725 if (t1 != QUAD && (hflag || t1 != UQUAD))
726 inconarg(hte, call, n);
729 * SHORT is always promoted to INT, USHORT
732 if (t1 != INT && (hflag || t1 != UINT))
733 inconarg(hte, call, n);
735 } else if (fc == 'o' || fc == 'u' || fc == 'x' || fc == 'X') {
736 if ((alt && fc == 'u') || sz == LDOUBLE)
740 if (t1 != ULONG && (hflag || t1 != LONG))
741 inconarg(hte, call, n);
742 } else if (sz == QUAD) {
743 if (t1 != UQUAD && (hflag || t1 != QUAD))
744 inconarg(hte, call, n);
745 } else if (sz == SHORT) {
746 /* USHORT was promoted to INT or UINT */
747 if (t1 != UINT && t1 != INT)
748 inconarg(hte, call, n);
750 if (t1 != UINT && (hflag || t1 != INT))
751 inconarg(hte, call, n);
753 } else if (fc == 'D' || fc == 'O' || fc == 'U') {
754 if ((alt && fc != 'O') || sz != NOTSPEC || !tflag)
762 } else if (fc == 'f' || fc == 'e' || fc == 'E' ||
763 fc == 'g' || fc == 'G') {
766 if (sz != DOUBLE && sz != LDOUBLE)
769 inconarg(hte, call, n);
770 } else if (fc == 'c') {
771 if (sz != NOTSPEC || alt || zero)
774 inconarg(hte, call, n);
775 } else if (fc == 's') {
776 if (sz != NOTSPEC || alt || zero)
779 (t2 != CHAR && t2 != UCHAR && t2 != SCHAR)) {
780 inconarg(hte, call, n);
782 } else if (fc == 'p') {
783 if (fwidth || prec || sz != NOTSPEC || alt || zero)
785 if (t1 != PTR || (hflag && t2 != VOID))
786 inconarg(hte, call, n);
787 } else if (fc == 'n') {
788 if (fwidth || prec || alt || zero || sz == LDOUBLE)
791 inconarg(hte, call, n);
792 } else if (sz == LONG) {
793 if (t2 != LONG && t2 != ULONG)
794 inconarg(hte, call, n);
795 } else if (sz == SHORT) {
796 if (t2 != SHORT && t2 != USHORT)
797 inconarg(hte, call, n);
799 if (t2 != INT && t2 != UINT)
800 inconarg(hte, call, n);
812 * Compare the types in the NULL-terminated array ap with the format
816 scanflike(hte_t *hte, fcall_t *call, int n, const char *fmt, type_t **ap)
821 tspec_t sz, t1 = NOTSPEC, t2 = NOTSPEC;
830 tomanyarg(hte, call);
849 do { fc = *fp++; } while (isdigit(fc));
854 } else if (fc == 'l') {
856 } else if (fc == 'q') {
858 } else if (fc == 'L') {
865 if (sz != NOTSPEC || noasgn || fwidth)
872 if ((tp = *ap++) == NULL) {
877 if ((t1 = tp->t_tspec) == PTR)
878 t2 = tp->t_subt->t_tspec;
881 if (fc == 'd' || fc == 'i' || fc == 'n') {
884 if (sz != SHORT && sz != LONG && sz != QUAD)
889 inconarg(hte, call, n);
890 } else if (t2 != styp(sz)) {
891 inconarg(hte, call, n);
892 } else if (hflag && t2 != sz) {
893 inconarg(hte, call, n);
894 } else if (tp->t_subt->t_const) {
895 inconarg(hte, call, n);
898 } else if (fc == 'o' || fc == 'u' || fc == 'x') {
903 } else if (sz == LONG) {
905 } else if (sz == QUAD) {
911 } else if (fc == 'D') {
912 if (sz != NOTSPEC || !tflag)
916 } else if (fc == 'O') {
917 if (sz != NOTSPEC || !tflag)
921 } else if (fc == 'X') {
923 * XXX valid in ANSI C, but in NetBSD's libc imple-
924 * mented as "lx". Thats why it should be avoided.
926 if (sz != NOTSPEC || !tflag)
930 } else if (fc == 'E') {
932 * XXX valid in ANSI C, but in NetBSD's libc imple-
933 * mented as "lf". Thats why it should be avoided.
935 if (sz != NOTSPEC || !tflag)
939 } else if (fc == 'F') {
940 /* XXX only for backward compatibility */
941 if (sz != NOTSPEC || !tflag)
945 } else if (fc == 'G') {
947 * XXX valid in ANSI C, but in NetBSD's libc not
950 if (sz != NOTSPEC && sz != LONG && sz != LDOUBLE)
953 } else if (fc == 'e' || fc == 'f' || fc == 'g') {
957 } else if (sz == LONG) {
959 } else if (sz != LDOUBLE) {
964 } else if (fc == 's' || fc == '[' || fc == 'c') {
968 if ((fc = *fp++) == '-') {
980 inconarg(hte, call, n);
981 } else if (t2 != CHAR && t2 != UCHAR &&
983 inconarg(hte, call, n);
986 } else if (fc == 'p') {
990 if (t1 != PTR || t2 != PTR) {
991 inconarg(hte, call, n);
992 } else if (tp->t_subt->t_subt->t_tspec!=VOID) {
994 inconarg(hte, call, n);
1007 badfmt(hte_t *hte, fcall_t *call)
1010 /* %s: malformed format string\t%s */
1011 msg(13, hte->h_name, mkpos(&call->f_pos));
1015 inconarg(hte_t *hte, fcall_t *call, int n)
1018 /* %s, arg %d inconsistent with format\t%s(%d) */
1019 msg(14, hte->h_name, n, mkpos(&call->f_pos));
1023 tofewarg(hte_t *hte, fcall_t *call)
1026 /* %s: too few args for format \t%s */
1027 msg(15, hte->h_name, mkpos(&call->f_pos));
1031 tomanyarg(hte_t *hte, fcall_t *call)
1034 /* %s: too many args for format \t%s */
1035 msg(16, hte->h_name, mkpos(&call->f_pos));
1040 * Print warnings for return values which are used, but not returned,
1041 * or return values which are always or sometimes ignored.
1044 chkrvu(hte_t *hte, sym_t *def)
1050 /* don't know wheter or not the functions returns a value */
1053 if (hte->h_calls == NULL)
1057 /* function has return value */
1059 for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
1060 used |= call->f_rused || call->f_rdisc;
1061 ignored |= !call->f_rused && !call->f_rdisc;
1064 * XXX as soon as we are able to disable single warnings
1065 * the following dependencies from hflag should be removed.
1066 * but for now I do'nt want to be botherd by this warnings
1067 * which are almost always useless.
1069 if (!used && ignored) {
1071 /* %s returns value which is always ignored */
1072 msg(8, hte->h_name);
1073 } else if (used && ignored) {
1075 /* %s returns value which is sometimes ign. */
1076 msg(9, hte->h_name);
1079 /* function has no return value */
1080 for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
1082 /* %s value is used( %s ), but none ret. */
1083 msg(10, hte->h_name, mkpos(&call->f_pos));
1089 * Print warnings for inconsistent argument declarations.
1092 chkadecl(hte_t *hte, sym_t *def, sym_t *decl)
1094 /* LINTED (automatic hides external declaration: warn) */
1095 int osdef, eq, warn, n;
1097 type_t **ap1, **ap2, *tp1, *tp2;
1103 osdef = def->s_osdef;
1105 } else if (decl != NULL && TP(decl->s_type)->t_proto) {
1110 if (TP(sym1->s_type)->t_tspec != FUNC)
1114 * XXX Prototypes should also be compared with old style function
1118 for (sym = hte->h_syms; sym != NULL; sym = sym->s_nxt) {
1119 if (sym == sym1 || !TP(sym->s_type)->t_proto)
1121 ap1 = TP(sym1->s_type)->t_args;
1122 ap2 = TP(sym->s_type)->t_args;
1124 while (*ap1 != NULL && *ap2 != NULL) {
1126 eq = eqtype(*ap1, *ap2, 1, osdef, 0, &warn);
1128 pos1 = xstrdup(mkpos(&sym1->s_pos));
1129 pos2 = mkpos(&sym->s_pos);
1130 /* %s, arg %d declared inconsistently ... */
1131 msg(11, hte->h_name, n + 1, pos1, pos2);
1139 tp1 = TP(sym1->s_type);
1140 tp2 = TP(sym->s_type);
1141 if (tp1->t_vararg == tp2->t_vararg)
1143 if (tp2->t_vararg &&
1144 sym1->s_va && sym1->s_nva == n && !sflag) {
1148 /* %s: variable # of args declared\t%s :: %s */
1149 pos1 = xstrdup(mkpos(&sym1->s_pos));
1150 msg(12, hte->h_name, pos1, mkpos(&sym->s_pos));
1157 * Check compatibility of two types. Returns 1 if types are compatible,
1160 * ignqual if set, ignore qualifiers of outhermost type; used for
1161 * function arguments
1162 * promote if set, promote left type before comparison; used for
1163 * comparisons of arguments with parameters of old style
1165 * asgn left indirected type must have at least the same qualifiers
1166 * like right indirected type (for assignments and function
1168 * *warn set to 1 if an old style declaration was compared with
1169 * an incompatible prototype declaration
1172 eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int asgn, int *warn)
1180 while (tp1 != NULL && tp2 != NULL) {
1186 } else if (t == CHAR || t == SCHAR) {
1188 } else if (t == UCHAR) {
1189 t = tflag ? UINT : INT;
1190 } else if (t == SHORT) {
1192 } else if (t == USHORT) {
1194 t = INT_MAX < USHRT_MAX || tflag ? UINT : INT;
1198 if (asgn && to == PTR) {
1199 if (indir == 1 && (t == VOID || tp2->t_tspec == VOID))
1203 if (t != tp2->t_tspec) {
1205 * Give pointer to types which differ only in
1206 * signedness a chance if not sflag and not hflag.
1208 if (sflag || hflag || to != PTR)
1210 if (styp(t) != styp(tp2->t_tspec))
1214 if (tp1->t_isenum && tp2->t_isenum) {
1215 if (tp1->t_istag && tp2->t_istag) {
1216 return (tp1->t_tag == tp2->t_tag);
1217 } else if (tp1->t_istynam && tp2->t_istynam) {
1218 return (tp1->t_tynam == tp2->t_tynam);
1219 } else if (tp1->t_isuniqpos && tp2->t_isuniqpos) {
1220 return (tp1->t_uniqpos.p_line ==
1221 tp2->t_uniqpos.p_line &&
1222 tp1->t_uniqpos.p_file ==
1223 tp2->t_uniqpos.p_file &&
1224 tp1->t_uniqpos.p_uniq ==
1225 tp2->t_uniqpos.p_uniq);
1232 * XXX Handle combinations of enum and int if eflag is set.
1233 * But note: enum and 0 should be allowed.
1236 if (asgn && indir == 1) {
1237 if (!tp1->t_const && tp2->t_const)
1239 if (!tp1->t_volatile && tp2->t_volatile)
1241 } else if (!ignqual && !tflag) {
1242 if (tp1->t_const != tp2->t_const)
1244 if (tp1->t_const != tp2->t_const)
1248 if (t == STRUCT || t == UNION) {
1249 if (tp1->t_istag && tp2->t_istag) {
1250 return (tp1->t_tag == tp2->t_tag);
1251 } else if (tp1->t_istynam && tp2->t_istynam) {
1252 return (tp1->t_tynam == tp2->t_tynam);
1253 } else if (tp1->t_isuniqpos && tp2->t_isuniqpos) {
1254 return (tp1->t_uniqpos.p_line ==
1255 tp2->t_uniqpos.p_line &&
1256 tp1->t_uniqpos.p_file ==
1257 tp2->t_uniqpos.p_file &&
1258 tp1->t_uniqpos.p_uniq ==
1259 tp2->t_uniqpos.p_uniq);
1265 if (t == ARRAY && tp1->t_dim != tp2->t_dim) {
1266 if (tp1->t_dim != 0 && tp2->t_dim != 0)
1271 if (tp1->t_proto && tp2->t_proto) {
1272 if (!eqargs(tp1, tp2, warn))
1274 } else if (tp1->t_proto) {
1275 if (!mnoarg(tp1, warn))
1277 } else if (tp2->t_proto) {
1278 if (!mnoarg(tp2, warn))
1285 ignqual = promot = 0;
1291 return (tp1 == tp2);
1295 * Compares arguments of two prototypes
1298 eqargs(type_t *tp1, type_t *tp2, int *warn)
1302 if (tp1->t_vararg != tp2->t_vararg)
1308 while (*a1 != NULL && *a2 != NULL) {
1310 if (eqtype(*a1, *a2, 1, 0, 0, warn) == 0)
1318 return (*a1 == *a2);
1322 * mnoarg() (matches functions with no argument type information)
1323 * returns 1 if all parameters of a prototype are compatible with
1324 * and old style function declaration.
1325 * This is the case if following conditions are met:
1326 * 1. the prototype must have a fixed number of parameters
1327 * 2. no parameter is of type float
1328 * 3. no parameter is converted to another type if integer promotion
1332 mnoarg(type_t *tp, int *warn)
1337 if (tp->t_vararg && warn != NULL)
1339 for (arg = tp->t_args; *arg != NULL; arg++) {
1340 if ((t = (*arg)->t_tspec) == FLOAT)
1342 if (t == CHAR || t == SCHAR || t == UCHAR)
1344 if (t == SHORT || t == USHORT)