aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/xlint/lint2/chk.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/xlint/lint2/chk.c')
-rw-r--r--usr.bin/xlint/lint2/chk.c302
1 files changed, 94 insertions, 208 deletions
diff --git a/usr.bin/xlint/lint2/chk.c b/usr.bin/xlint/lint2/chk.c
index 0aac8529b3c8..46923f91101c 100644
--- a/usr.bin/xlint/lint2/chk.c
+++ b/usr.bin/xlint/lint2/chk.c
@@ -1,6 +1,7 @@
-/* $NetBSD: chk.c,v 1.2 1995/07/03 21:24:42 cgd Exp $ */
+/* $NetBSD: chk.c,v 1.15 2002/01/21 19:49:52 tv Exp $ */
/*
+ * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@@ -31,138 +32,44 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef lint
-static char rcsid[] = "$NetBSD: chk.c,v 1.2 1995/07/03 21:24:42 cgd Exp $";
+#include <sys/cdefs.h>
+#if defined(__RCSID) && !defined(lint)
+__RCSID("$NetBSD: chk.c,v 1.15 2002/01/21 19:49:52 tv Exp $");
#endif
-#include <stdlib.h>
#include <ctype.h>
#include <limits.h>
-#include <err.h>
+#include <stdlib.h>
#include "lint2.h"
-/* various type information */
-ttab_t ttab[NTSPEC];
-
-
-static void chkund __P((hte_t *));
-static void chkdnu __P((hte_t *));
-static void chkdnud __P((hte_t *));
-static void chkmd __P((hte_t *));
-static void chkvtui __P((hte_t *, sym_t *, sym_t *));
-static void chkvtdi __P((hte_t *, sym_t *, sym_t *));
-static void chkfaui __P((hte_t *, sym_t *, sym_t *));
-static void chkau __P((hte_t *, int, sym_t *, sym_t *, pos_t *,
- fcall_t *, fcall_t *, type_t *, type_t *));
-static void chkrvu __P((hte_t *, sym_t *));
-static void chkadecl __P((hte_t *, sym_t *, sym_t *));
-static void printflike __P((hte_t *,fcall_t *, int,
- const char *, type_t **));
-static void scanflike __P((hte_t *, fcall_t *, int,
- const char *, type_t **));
-static void badfmt __P((hte_t *, fcall_t *));
-static void inconarg __P((hte_t *, fcall_t *, int));
-static void tofewarg __P((hte_t *, fcall_t *));
-static void tomanyarg __P((hte_t *, fcall_t *));
-static int eqtype __P((type_t *, type_t *, int, int, int, int *));
-static int eqargs __P((type_t *, type_t *, int *));
-static int mnoarg __P((type_t *, int *));
-
-
-void
-inittyp()
-{
- int i;
- static struct {
- tspec_t it_tspec;
- ttab_t it_ttab;
- } ittab[] = {
- { SIGNED, { 0, 0,
- SIGNED, UNSIGN,
- 0, 0, 0, 0, 0, "signed" } },
- { UNSIGN, { 0, 0,
- SIGNED, UNSIGN,
- 0, 0, 0, 0, 0, "unsigned" } },
- { CHAR, { CHAR_BIT, CHAR_BIT,
- SCHAR, UCHAR,
- 1, 0, 0, 1, 1, "char" } },
- { SCHAR, { CHAR_BIT, CHAR_BIT,
- SCHAR, UCHAR,
- 1, 0, 0, 1, 1, "signed char" } },
- { UCHAR, { CHAR_BIT, CHAR_BIT,
- SCHAR, UCHAR,
- 1, 1, 0, 1, 1, "unsigned char" } },
- { SHORT, { sizeof (short) * CHAR_BIT, 2 * CHAR_BIT,
- SHORT, USHORT,
- 1, 0, 0, 1, 1, "short" } },
- { USHORT, { sizeof (u_short) * CHAR_BIT, 2 * CHAR_BIT,
- SHORT, USHORT,
- 1, 1, 0, 1, 1, "unsigned short" } },
- { INT, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT,
- INT, UINT,
- 1, 0, 0, 1, 1, "int" } },
- { UINT, { sizeof (u_int) * CHAR_BIT, 3 * CHAR_BIT,
- INT, UINT,
- 1, 1, 0, 1, 1, "unsigned int" } },
- { LONG, { sizeof (long) * CHAR_BIT, 4 * CHAR_BIT,
- LONG, ULONG,
- 1, 0, 0, 1, 1, "long" } },
- { ULONG, { sizeof (u_long) * CHAR_BIT, 4 * CHAR_BIT,
- LONG, ULONG,
- 1, 1, 0, 1, 1, "unsigned long" } },
- { QUAD, { sizeof (quad_t) * CHAR_BIT, 8 * CHAR_BIT,
- QUAD, UQUAD,
- 1, 0, 0, 1, 1, "long long" } },
- { UQUAD, { sizeof (u_quad_t) * CHAR_BIT, 8 * CHAR_BIT,
- QUAD, UQUAD,
- 1, 1, 0, 1, 1, "unsigned long long" } },
- { FLOAT, { sizeof (float) * CHAR_BIT, 4 * CHAR_BIT,
- FLOAT, FLOAT,
- 0, 0, 1, 1, 1, "float" } },
- { DOUBLE, { sizeof (double) * CHAR_BIT, 8 * CHAR_BIT,
- DOUBLE, DOUBLE,
- 0, 0, 1, 1, 1, "double" } },
- { LDOUBLE, { sizeof (ldbl_t) * CHAR_BIT, 10 * CHAR_BIT,
- LDOUBLE, LDOUBLE,
- 0, 0, 1, 1, 1, "long double" } },
- { VOID, { -1, -1,
- VOID, VOID,
- 0, 0, 0, 0, 0, "void" } },
- { STRUCT, { -1, -1,
- STRUCT, STRUCT,
- 0, 0, 0, 0, 0, "struct" } },
- { UNION, { -1, -1,
- UNION, UNION,
- 0, 0, 0, 0, 0, "union" } },
- { ENUM, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT,
- ENUM, ENUM,
- 1, 0, 0, 1, 1, "enum" } },
- { PTR, { sizeof (void *) * CHAR_BIT, 4 * CHAR_BIT,
- PTR, PTR,
- 0, 1, 0, 0, 1, "pointer" } },
- { ARRAY, { -1, -1,
- ARRAY, ARRAY,
- 0, 0, 0, 0, 0, "array" } },
- { FUNC, { -1, -1,
- FUNC, FUNC,
- 0, 0, 0, 0, 0, "function" } },
- };
-
- for (i = 0; i < sizeof (ittab) / sizeof (ittab[0]); i++)
- STRUCT_ASSIGN(ttab[ittab[i].it_tspec], ittab[i].it_ttab);
- if (!pflag) {
- for (i = 0; i < NTSPEC; i++)
- ttab[i].tt_psz = ttab[i].tt_sz;
- }
-}
+static void chkund(hte_t *);
+static void chkdnu(hte_t *);
+static void chkdnud(hte_t *);
+static void chkmd(hte_t *);
+static void chkvtui(hte_t *, sym_t *, sym_t *);
+static void chkvtdi(hte_t *, sym_t *, sym_t *);
+static void chkfaui(hte_t *, sym_t *, sym_t *);
+static void chkau(hte_t *, int, sym_t *, sym_t *, pos_t *,
+ fcall_t *, fcall_t *, type_t *, type_t *);
+static void chkrvu(hte_t *, sym_t *);
+static void chkadecl(hte_t *, sym_t *, sym_t *);
+static void printflike(hte_t *,fcall_t *, int, const char *, type_t **);
+static void scanflike(hte_t *, fcall_t *, int, const char *, type_t **);
+static void badfmt(hte_t *, fcall_t *);
+static void inconarg(hte_t *, fcall_t *, int);
+static void tofewarg(hte_t *, fcall_t *);
+static void tomanyarg(hte_t *, fcall_t *);
+static int eqtype(type_t *, type_t *, int, int, int, int *);
+static int eqargs(type_t *, type_t *, int *);
+static int mnoarg(type_t *, int *);
/*
* If there is a symbol named "main", mark it as used.
*/
void
-mainused()
+mainused(void)
{
hte_t *hte;
@@ -174,8 +81,7 @@ mainused()
* Performs all tests for a single name
*/
void
-chkname(hte)
- hte_t *hte;
+chkname(hte_t *hte)
{
sym_t *sym, *def, *pdecl, *decl;
@@ -220,8 +126,7 @@ chkname(hte)
* Print a warning if the name has been used, but not defined.
*/
static void
-chkund(hte)
- hte_t *hte;
+chkund(hte_t *hte)
{
fcall_t *fcall;
usym_t *usym;
@@ -242,8 +147,7 @@ chkund(hte)
* Print a warning if the name has been defined, but never used.
*/
static void
-chkdnu(hte)
- hte_t *hte;
+chkdnu(hte_t *hte)
{
sym_t *sym;
@@ -260,33 +164,33 @@ chkdnu(hte)
}
/*
- * Print a warning if the name has been declared, but is not used
+ * Print a warning if the variable has been declared, but is not used
* or defined.
*/
static void
-chkdnud(hte)
- hte_t *hte;
+chkdnud(hte_t *hte)
{
sym_t *sym;
if (hte->h_syms == NULL || hte->h_used || hte->h_def)
return;
-
- if ((sym = hte->h_syms) != NULL) {
- if (sym->s_def != DECL)
- errx(1, "internal error: chkdnud() 1");
- /* %s declared( %s ), but never used or defined */
- msg(2, hte->h_name, mkpos(&sym->s_pos));
- }
+
+ sym = hte->h_syms;
+ if (TP(sym->s_type)->t_tspec == FUNC)
+ return;
+
+ if (sym->s_def != DECL)
+ errx(1, "internal error: chkdnud() 1");
+ /* %s declared( %s ), but never used or defined */
+ msg(2, hte->h_name, mkpos(&sym->s_pos));
}
/*
- * Print a warning if there is more then one definition for
+ * Print a warning if there is more than one definition for
* this name.
*/
static void
-chkmd(hte)
- hte_t *hte;
+chkmd(hte_t *hte)
{
sym_t *sym, *def1;
char *pos1;
@@ -323,9 +227,7 @@ chkmd(hte)
* call as it's done for function arguments.
*/
static void
-chkvtui(hte, def, decl)
- hte_t *hte;
- sym_t *def, *decl;
+chkvtui(hte_t *hte, sym_t *def, sym_t *decl)
{
fcall_t *call;
char *pos1;
@@ -386,9 +288,7 @@ chkvtui(hte, def, decl)
* types of return values are tested.
*/
static void
-chkvtdi(hte, def, decl)
- hte_t *hte;
- sym_t *def, *decl;
+chkvtdi(hte_t *hte, sym_t *def, sym_t *decl)
{
sym_t *sym;
type_t *tp1, *tp2;
@@ -427,12 +327,10 @@ chkvtdi(hte, def, decl)
* of the same function.
*/
static void
-chkfaui(hte, def, decl)
- hte_t *hte;
- sym_t *def, *decl;
+chkfaui(hte_t *hte, sym_t *def, sym_t *decl)
{
type_t *tp1, *tp2, **ap1, **ap2;
- pos_t *pos1p;
+ pos_t *pos1p = NULL;
fcall_t *calls, *call, *call1;
int n, as;
char *pos1;
@@ -442,7 +340,7 @@ chkfaui(hte, def, decl)
return;
/*
- * If we find a function definition, we use this for comparision,
+ * If we find a function definition, we use this for comparison,
* otherwise the first prototype we can find. If there is no
* definition or prototype declaration, the first function call
* is used.
@@ -537,13 +435,8 @@ chkfaui(hte, def, decl)
*
*/
static void
-chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2)
- hte_t *hte;
- int n;
- sym_t *def, *decl;
- pos_t *pos1p;
- fcall_t *call1, *call;
- type_t *arg1, *arg2;
+chkau(hte_t *hte, int n, sym_t *def, sym_t *decl, pos_t *pos1p,
+ fcall_t *call1, fcall_t *call, type_t *arg1, type_t *arg2)
{
/* LINTED (automatic hides external declaration: warn) */
int promote, asgn, warn;
@@ -577,7 +470,7 @@ chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2)
/*
* Other lint implementations print warnings as soon as the type
* of an argument does not match exactly the expected type. The
- * result are lots of warnings which are really not neccessary.
+ * result are lots of warnings which are really not necessary.
* We print a warning only if
* (0) at least one type is not an interger type and types differ
* (1) hflag is set and types differ
@@ -670,11 +563,16 @@ chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2)
}
}
- } else if (t1 == PTR && isityp(t2) && psize(t1) == psize(t2)) {
+ } else if (t1 == PTR && isityp(t2)) {
for (ai = call->f_args; ai != NULL; ai = ai->a_nxt) {
if (ai->a_num == n)
break;
}
+ /*
+ * Vendor implementations of lint (e.g. HP-UX, Digital UNIX)
+ * don't care about the size of the integer argument,
+ * only whether or not it is zero. We do the same.
+ */
if (ai != NULL && ai->a_zero)
return;
}
@@ -690,17 +588,12 @@ chkau(hte, n, def, decl, pos1p, call1, call, arg1, arg2)
* string fmt.
*/
static void
-printflike(hte, call, n, fmt, ap)
- hte_t *hte;
- fcall_t *call;
- int n;
- const char *fmt;
- type_t **ap;
+printflike(hte_t *hte, fcall_t *call, int n, const char *fmt, type_t **ap)
{
const char *fp;
int fc;
int fwidth, prec, left, sign, space, alt, zero;
- tspec_t sz, t1, t2;
+ tspec_t sz, t1, t2 = NOTSPEC;
type_t *tp;
fp = fmt;
@@ -920,18 +813,13 @@ printflike(hte, call, n, fmt, ap)
* string fmt.
*/
static void
-scanflike(hte, call, n, fmt, ap)
- hte_t *hte;
- fcall_t *call;
- int n;
- const char *fmt;
- type_t **ap;
+scanflike(hte_t *hte, fcall_t *call, int n, const char *fmt, type_t **ap)
{
const char *fp;
int fc;
int noasgn, fwidth;
- tspec_t sz, t1, t2;
- type_t *tp;
+ tspec_t sz, t1 = NOTSPEC, t2 = NOTSPEC;
+ type_t *tp = NULL;
fp = fmt;
fc = *fp++;
@@ -955,7 +843,7 @@ scanflike(hte, call, n, fmt, ap)
noasgn = 1;
fc = *fp++;
}
-
+
if (isdigit(fc)) {
fwidth = 1;
do { fc = *fp++; } while (isdigit(fc));
@@ -1116,38 +1004,33 @@ scanflike(hte, call, n, fmt, ap)
}
static void
-badfmt(hte, call)
- hte_t *hte;
- fcall_t *call;
+badfmt(hte_t *hte, fcall_t *call)
{
+
/* %s: malformed format string\t%s */
msg(13, hte->h_name, mkpos(&call->f_pos));
}
static void
-inconarg(hte, call, n)
- hte_t *hte;
- fcall_t *call;
- int n;
+inconarg(hte_t *hte, fcall_t *call, int n)
{
+
/* %s, arg %d inconsistent with format\t%s(%d) */
msg(14, hte->h_name, n, mkpos(&call->f_pos));
}
static void
-tofewarg(hte, call)
- hte_t *hte;
- fcall_t *call;
+tofewarg(hte_t *hte, fcall_t *call)
{
+
/* %s: too few args for format \t%s */
msg(15, hte->h_name, mkpos(&call->f_pos));
}
static void
-tomanyarg(hte, call)
- hte_t *hte;
- fcall_t *call;
+tomanyarg(hte_t *hte, fcall_t *call)
{
+
/* %s: too many args for format \t%s */
msg(16, hte->h_name, mkpos(&call->f_pos));
}
@@ -1158,9 +1041,7 @@ tomanyarg(hte, call)
* or return values which are always or sometimes ignored.
*/
static void
-chkrvu(hte, def)
- hte_t *hte;
- sym_t *def;
+chkrvu(hte_t *hte, sym_t *def)
{
fcall_t *call;
int used, ignored;
@@ -1176,7 +1057,7 @@ chkrvu(hte, def)
/* function has return value */
used = ignored = 0;
for (call = hte->h_calls; call != NULL; call = call->f_nxt) {
- used |= call->f_rused;
+ used |= call->f_rused || call->f_rdisc;
ignored |= !call->f_rused && !call->f_rdisc;
}
/*
@@ -1208,9 +1089,7 @@ chkrvu(hte, def)
* Print warnings for inconsistent argument declarations.
*/
static void
-chkadecl(hte, def, decl)
- hte_t *hte;
- sym_t *def, *decl;
+chkadecl(hte_t *hte, sym_t *def, sym_t *decl)
{
/* LINTED (automatic hides external declaration: warn) */
int osdef, eq, warn, n;
@@ -1280,8 +1159,8 @@ chkadecl(hte, def, decl)
*
* ignqual if set, ignore qualifiers of outhermost type; used for
* function arguments
- * promote if set, promote left type before comparision; used for
- * comparisions of arguments with parameters of old style
+ * promote if set, promote left type before comparison; used for
+ * comparisons of arguments with parameters of old style
* definitions
* asgn left indirected type must have at least the same qualifiers
* like right indirected type (for assignments and function
@@ -1290,9 +1169,7 @@ chkadecl(hte, def, decl)
* an incompatible prototype declaration
*/
static int
-eqtype(tp1, tp2, ignqual, promot, asgn, warn)
- type_t *tp1, *tp2;
- int ignqual, promot, asgn, *warn;
+eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int asgn, int *warn)
{
tspec_t t, to;
int indir;
@@ -1322,7 +1199,7 @@ eqtype(tp1, tp2, ignqual, promot, asgn, warn)
if (indir == 1 && (t == VOID || tp2->t_tspec == VOID))
return (1);
}
-
+
if (t != tp2->t_tspec) {
/*
* Give pointer to types which differ only in
@@ -1339,6 +1216,13 @@ eqtype(tp1, tp2, ignqual, promot, asgn, warn)
return (tp1->t_tag == tp2->t_tag);
} else if (tp1->t_istynam && tp2->t_istynam) {
return (tp1->t_tynam == tp2->t_tynam);
+ } else if (tp1->t_isuniqpos && tp2->t_isuniqpos) {
+ return (tp1->t_uniqpos.p_line ==
+ tp2->t_uniqpos.p_line &&
+ tp1->t_uniqpos.p_file ==
+ tp2->t_uniqpos.p_file &&
+ tp1->t_uniqpos.p_uniq ==
+ tp2->t_uniqpos.p_uniq);
} else {
return (0);
}
@@ -1366,6 +1250,13 @@ eqtype(tp1, tp2, ignqual, promot, asgn, warn)
return (tp1->t_tag == tp2->t_tag);
} else if (tp1->t_istynam && tp2->t_istynam) {
return (tp1->t_tynam == tp2->t_tynam);
+ } else if (tp1->t_isuniqpos && tp2->t_isuniqpos) {
+ return (tp1->t_uniqpos.p_line ==
+ tp2->t_uniqpos.p_line &&
+ tp1->t_uniqpos.p_file ==
+ tp2->t_uniqpos.p_file &&
+ tp1->t_uniqpos.p_uniq ==
+ tp2->t_uniqpos.p_uniq);
} else {
return (0);
}
@@ -1404,9 +1295,7 @@ eqtype(tp1, tp2, ignqual, promot, asgn, warn)
* Compares arguments of two prototypes
*/
static int
-eqargs(tp1, tp2, warn)
- type_t *tp1, *tp2;
- int *warn;
+eqargs(type_t *tp1, type_t *tp2, int *warn)
{
type_t **a1, **a2;
@@ -1440,9 +1329,7 @@ eqargs(tp1, tp2, warn)
* is applied on it
*/
static int
-mnoarg(tp, warn)
- type_t *tp;
- int *warn;
+mnoarg(type_t *tp, int *warn)
{
type_t **arg;
tspec_t t;
@@ -1459,4 +1346,3 @@ mnoarg(tp, warn)
}
return (1);
}
-