From bd1445ea08135a120ede54606308afa17aa6c316 Mon Sep 17 00:00:00 2001 From: Chad Loder Date: Tue, 25 Apr 2006 01:25:42 +0000 Subject: Rather than use the psize() macro everywhere (portable size macro which only makes sense when -p option is specified to lint), add a new concept and macro called rank(), which corresponds to the C99 definition of rank for integral types. This has one main benefit, which is that on ILP32 platforms, if -p was not specified, lint did not warn when the code converted from long to int, because they are the same size. This is fixed. While here, get rid of a false positive with warning 259, when converting from an unsigned char to an int, for example. --- usr.bin/xlint/lint1/decl.c | 50 +++++++++++++++++++++++----------------------- usr.bin/xlint/lint1/lint.h | 4 +++- usr.bin/xlint/lint1/tree.c | 32 ++++++++++++++++------------- usr.bin/xlint/lint2/chk.c | 50 +++++++++++++++++++++++----------------------- 4 files changed, 71 insertions(+), 65 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/xlint/lint1/decl.c b/usr.bin/xlint/lint1/decl.c index 449baa6b2b7..19c9b167436 100644 --- a/usr.bin/xlint/lint1/decl.c +++ b/usr.bin/xlint/lint1/decl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: decl.c,v 1.20 2006/03/08 07:18:51 moritz Exp $ */ +/* $OpenBSD: decl.c,v 1.21 2006/04/25 01:25:40 cloder Exp $ */ /* $NetBSD: decl.c,v 1.11 1995/10/02 17:34:16 jpo Exp $ */ /* @@ -33,7 +33,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: decl.c,v 1.20 2006/03/08 07:18:51 moritz Exp $"; +static char rcsid[] = "$OpenBSD: decl.c,v 1.21 2006/04/25 01:25:40 cloder Exp $"; #endif #include @@ -91,73 +91,73 @@ initdecl(void) tspec_t it_tspec; ttab_t it_ttab; } ittab[] = { - { SIGNED, { 0, 0, + { SIGNED, { 0, 0, 0, SIGNED, UNSIGN, 0, 0, 0, 0, 0, "signed" } }, - { UNSIGN, { 0, 0, + { UNSIGN, { 0, 0, 0, SIGNED, UNSIGN, 0, 0, 0, 0, 0, "unsigned" } }, - { CHAR, { CHAR_BIT, CHAR_BIT, + { CHAR, { CHAR_BIT, CHAR_BIT, 20, SCHAR, UCHAR, 1, 0, 0, 1, 1, "char" } }, - { SCHAR, { CHAR_BIT, CHAR_BIT, + { SCHAR, { CHAR_BIT, CHAR_BIT, 20, SCHAR, UCHAR, 1, 0, 0, 1, 1, "signed char" } }, - { UCHAR, { CHAR_BIT, CHAR_BIT, + { UCHAR, { CHAR_BIT, CHAR_BIT, 20, SCHAR, UCHAR, 1, 1, 0, 1, 1, "unsigned char" } }, - { SHORT, { sizeof (short) * CHAR_BIT, 2 * CHAR_BIT, + { SHORT, { sizeof (short) * CHAR_BIT, 2 * CHAR_BIT, 30, SHORT, USHORT, 1, 0, 0, 1, 1, "short" } }, - { USHORT, { sizeof (u_short) * CHAR_BIT, 2 * CHAR_BIT, + { USHORT, { sizeof (u_short) * CHAR_BIT, 2 * CHAR_BIT, 30, SHORT, USHORT, 1, 1, 0, 1, 1, "unsigned short" } }, - { INT, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT, + { INT, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT, 40, INT, UINT, 1, 0, 0, 1, 1, "int" } }, - { UINT, { sizeof (u_int) * CHAR_BIT, 3 * CHAR_BIT, + { UINT, { sizeof (u_int) * CHAR_BIT, 3 * CHAR_BIT, 40, INT, UINT, 1, 1, 0, 1, 1, "unsigned int" } }, - { LONG, { sizeof (long) * CHAR_BIT, 4 * CHAR_BIT, + { LONG, { sizeof (long) * CHAR_BIT, 4 * CHAR_BIT, 50, LONG, ULONG, 1, 0, 0, 1, 1, "long" } }, - { ULONG, { sizeof (u_long) * CHAR_BIT, 4 * CHAR_BIT, + { ULONG, { sizeof (u_long) * CHAR_BIT, 4 * CHAR_BIT, 50, LONG, ULONG, 1, 1, 0, 1, 1, "unsigned long" } }, - { QUAD, { sizeof (quad_t) * CHAR_BIT, 8 * CHAR_BIT, + { QUAD, { sizeof (quad_t) * CHAR_BIT, 8 * CHAR_BIT, 60, QUAD, UQUAD, 1, 0, 0, 1, 1, "long long" } }, - { UQUAD, { sizeof (u_quad_t) * CHAR_BIT, 8 * CHAR_BIT, + { UQUAD, { sizeof (u_quad_t) * CHAR_BIT, 8 * CHAR_BIT, 60, QUAD, UQUAD, 1, 1, 0, 1, 1, "unsigned long long" } }, - { FLOAT, { sizeof (float) * CHAR_BIT, 4 * CHAR_BIT, + { FLOAT, { sizeof (float) * CHAR_BIT, 4 * CHAR_BIT, -1, FLOAT, FLOAT, 0, 0, 1, 1, 1, "float" } }, - { DOUBLE, { sizeof (double) * CHAR_BIT, 8 * CHAR_BIT, + { DOUBLE, { sizeof (double) * CHAR_BIT, 8 * CHAR_BIT, -1, DOUBLE, DOUBLE, 0, 0, 1, 1, 1, "double" } }, - { LDOUBLE, { sizeof (ldbl_t) * CHAR_BIT, 10 * CHAR_BIT, + { LDOUBLE, { sizeof (ldbl_t) * CHAR_BIT, 10 * CHAR_BIT, -1, LDOUBLE, LDOUBLE, 0, 0, 1, 1, 1, "long double" } }, - { VOID, { -1, -1, + { VOID, { -1, -1, -1, VOID, VOID, 0, 0, 0, 0, 0, "void" } }, - { STRUCT, { -1, -1, + { STRUCT, { -1, -1, -1, STRUCT, STRUCT, 0, 0, 0, 0, 0, "struct" } }, - { UNION, { -1, -1, + { UNION, { -1, -1, -1, UNION, UNION, 0, 0, 0, 0, 0, "union" } }, - { ENUM, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT, + { ENUM, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT, 40, ENUM, ENUM, 1, 0, 0, 1, 1, "enum" } }, - { PTR, { sizeof (void *) * CHAR_BIT, 4 * CHAR_BIT, + { PTR, { sizeof (void *) * CHAR_BIT, 4 * CHAR_BIT, -1, PTR, PTR, 0, 1, 0, 0, 1, "pointer" } }, - { ARRAY, { -1, -1, + { ARRAY, { -1, -1, -1, ARRAY, ARRAY, 0, 0, 0, 0, 0, "array" } }, - { FUNC, { -1, -1, + { FUNC, { -1, -1, -1, FUNC, FUNC, 0, 0, 0, 0, 0, "function" } }, }; diff --git a/usr.bin/xlint/lint1/lint.h b/usr.bin/xlint/lint1/lint.h index ff2589e1777..4948c59290c 100644 --- a/usr.bin/xlint/lint1/lint.h +++ b/usr.bin/xlint/lint1/lint.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lint.h,v 1.4 2006/03/08 07:18:51 moritz Exp $ */ +/* $OpenBSD: lint.h,v 1.5 2006/04/25 01:25:41 cloder Exp $ */ /* $NetBSD: lint.h,v 1.2 1995/07/03 21:24:18 cgd Exp $ */ /* @@ -76,6 +76,7 @@ typedef struct { int tt_sz; /* size in bits */ int tt_psz; /* size, different from tt_sz if pflag is set */ + int tt_rank; /* rank (C99), similar to tt_psz */ tspec_t tt_styp; /* signed counterpart */ tspec_t tt_utyp; /* unsigned counterpart */ u_int tt_isityp : 1; /* 1 if integer type */ @@ -88,6 +89,7 @@ typedef struct { #define size(t) (ttab[t].tt_sz) #define psize(t) (ttab[t].tt_psz) +#define rank(t) (ttab[t].tt_rank) #define styp(t) (ttab[t].tt_styp) #define utyp(t) (ttab[t].tt_utyp) #define isityp(t) (ttab[t].tt_isityp) diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index 450c0771f77..15862a3766d 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.c,v 1.35 2006/04/18 04:10:05 cloder Exp $ */ +/* $OpenBSD: tree.c,v 1.36 2006/04/25 01:25:41 cloder Exp $ */ /* $NetBSD: tree.c,v 1.12 1995/10/02 17:37:57 jpo Exp $ */ /* @@ -33,7 +33,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: tree.c,v 1.35 2006/04/18 04:10:05 cloder Exp $"; +static char rcsid[] = "$OpenBSD: tree.c,v 1.36 2006/04/25 01:25:41 cloder Exp $"; #endif #include @@ -1723,7 +1723,7 @@ ptconv(farg_t *farg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn) if (ptn->tn_op == CON && isityp(nt) && styp(nt) == styp(ot) && msb(ptn->tn_val->v_quad, ot, -1) == 0) { /* ok */ - } else { + } else if (ptn->tn_op != CON) { /* %s arg #%d: converted from '%s' to '%s' */ warning(259, funcname(farg->fa_func), arg, tyname(tn->tn_type), tyname(tp)); @@ -1761,17 +1761,21 @@ iiconv(op_t op, farg_t *farg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn) } #endif - if (psize(nt) < psize(ot) && - (ot == LONG || ot == ULONG || ot == QUAD || ot == UQUAD || - aflag > 1)) { - /* conversion from '%s' to '%s' may lose accuracy */ - if (aflag) { - if (op == FARG) { - warning(298, funcname(farg->fa_func), arg, - tyname(tn->tn_type), tyname(tp)); - } else { - warning(132, tyname(tn->tn_type), tyname(tp)); - } + if (rank(nt) < rank(ot)) { + /* coercion from greater to lesser width */ + if (op == FARG) { + warning(298, funcname(farg->fa_func), arg, + tyname(tn->tn_type), tyname(tp)); + } else { + warning(132, tyname(tn->tn_type), tyname(tp)); + } + } else if (isutyp(nt) != isutyp(ot) && rank(nt) == rank(ot)) { + /* coercion to same width but with signedness change */ + if (op == FARG) { + warning(298, funcname(farg->fa_func), arg, + tyname(tn->tn_type), tyname(tp)); + } else { + warning(132, tyname(tn->tn_type), tyname(tp)); } } } diff --git a/usr.bin/xlint/lint2/chk.c b/usr.bin/xlint/lint2/chk.c index b91559d7aa6..fe9bc37d30f 100644 --- a/usr.bin/xlint/lint2/chk.c +++ b/usr.bin/xlint/lint2/chk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: chk.c,v 1.12 2005/12/10 20:26:10 cloder Exp $ */ +/* $OpenBSD: chk.c,v 1.13 2006/04/25 01:25:41 cloder Exp $ */ /* $NetBSD: chk.c,v 1.2 1995/07/03 21:24:42 cgd Exp $ */ /* @@ -33,7 +33,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: chk.c,v 1.12 2005/12/10 20:26:10 cloder Exp $"; +static char rcsid[] = "$OpenBSD: chk.c,v 1.13 2006/04/25 01:25:41 cloder Exp $"; #endif #include @@ -77,73 +77,73 @@ inittyp(void) tspec_t it_tspec; ttab_t it_ttab; } ittab[] = { - { SIGNED, { 0, 0, + { SIGNED, { 0, 0, 0, SIGNED, UNSIGN, 0, 0, 0, 0, 0, "signed" } }, - { UNSIGN, { 0, 0, + { UNSIGN, { 0, 0, 0, SIGNED, UNSIGN, 0, 0, 0, 0, 0, "unsigned" } }, - { CHAR, { CHAR_BIT, CHAR_BIT, + { CHAR, { CHAR_BIT, CHAR_BIT, 20, SCHAR, UCHAR, 1, 0, 0, 1, 1, "char" } }, - { SCHAR, { CHAR_BIT, CHAR_BIT, + { SCHAR, { CHAR_BIT, CHAR_BIT, 20, SCHAR, UCHAR, 1, 0, 0, 1, 1, "signed char" } }, - { UCHAR, { CHAR_BIT, CHAR_BIT, + { UCHAR, { CHAR_BIT, CHAR_BIT, 20, SCHAR, UCHAR, 1, 1, 0, 1, 1, "unsigned char" } }, - { SHORT, { sizeof (short) * CHAR_BIT, 2 * CHAR_BIT, + { SHORT, { sizeof (short) * CHAR_BIT, 2 * CHAR_BIT, 30, SHORT, USHORT, 1, 0, 0, 1, 1, "short" } }, - { USHORT, { sizeof (u_short) * CHAR_BIT, 2 * CHAR_BIT, + { USHORT, { sizeof (u_short) * CHAR_BIT, 2 * CHAR_BIT, 30, SHORT, USHORT, 1, 1, 0, 1, 1, "unsigned short" } }, - { INT, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT, + { INT, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT, 40, INT, UINT, 1, 0, 0, 1, 1, "int" } }, - { UINT, { sizeof (u_int) * CHAR_BIT, 3 * CHAR_BIT, + { UINT, { sizeof (u_int) * CHAR_BIT, 3 * CHAR_BIT, 40, INT, UINT, 1, 1, 0, 1, 1, "unsigned int" } }, - { LONG, { sizeof (long) * CHAR_BIT, 4 * CHAR_BIT, + { LONG, { sizeof (long) * CHAR_BIT, 4 * CHAR_BIT, 50, LONG, ULONG, 1, 0, 0, 1, 1, "long" } }, - { ULONG, { sizeof (u_long) * CHAR_BIT, 4 * CHAR_BIT, + { ULONG, { sizeof (u_long) * CHAR_BIT, 4 * CHAR_BIT, 50, LONG, ULONG, 1, 1, 0, 1, 1, "unsigned long" } }, - { QUAD, { sizeof (quad_t) * CHAR_BIT, 8 * CHAR_BIT, + { QUAD, { sizeof (quad_t) * CHAR_BIT, 8 * CHAR_BIT, 60, QUAD, UQUAD, 1, 0, 0, 1, 1, "long long" } }, - { UQUAD, { sizeof (u_quad_t) * CHAR_BIT, 8 * CHAR_BIT, + { UQUAD, { sizeof (u_quad_t) * CHAR_BIT, 8 * CHAR_BIT, 60, QUAD, UQUAD, 1, 1, 0, 1, 1, "unsigned long long" } }, - { FLOAT, { sizeof (float) * CHAR_BIT, 4 * CHAR_BIT, + { FLOAT, { sizeof (float) * CHAR_BIT, 4 * CHAR_BIT, -1, FLOAT, FLOAT, 0, 0, 1, 1, 1, "float" } }, - { DOUBLE, { sizeof (double) * CHAR_BIT, 8 * CHAR_BIT, + { DOUBLE, { sizeof (double) * CHAR_BIT, 8 * CHAR_BIT, -1, DOUBLE, DOUBLE, 0, 0, 1, 1, 1, "double" } }, - { LDOUBLE, { sizeof (ldbl_t) * CHAR_BIT, 10 * CHAR_BIT, + { LDOUBLE, { sizeof (ldbl_t) * CHAR_BIT, 10 * CHAR_BIT, -1, LDOUBLE, LDOUBLE, 0, 0, 1, 1, 1, "long double" } }, - { VOID, { -1, -1, + { VOID, { -1, -1, -1, VOID, VOID, 0, 0, 0, 0, 0, "void" } }, - { STRUCT, { -1, -1, + { STRUCT, { -1, -1, -1, STRUCT, STRUCT, 0, 0, 0, 0, 0, "struct" } }, - { UNION, { -1, -1, + { UNION, { -1, -1, -1, UNION, UNION, 0, 0, 0, 0, 0, "union" } }, - { ENUM, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT, + { ENUM, { sizeof (int) * CHAR_BIT, 3 * CHAR_BIT, 40, ENUM, ENUM, 1, 0, 0, 1, 1, "enum" } }, - { PTR, { sizeof (void *) * CHAR_BIT, 4 * CHAR_BIT, + { PTR, { sizeof (void *) * CHAR_BIT, 4 * CHAR_BIT, -1, PTR, PTR, 0, 1, 0, 0, 1, "pointer" } }, - { ARRAY, { -1, -1, + { ARRAY, { -1, -1, -1, ARRAY, ARRAY, 0, 0, 0, 0, 0, "array" } }, - { FUNC, { -1, -1, + { FUNC, { -1, -1, -1, FUNC, FUNC, 0, 0, 0, 0, 0, "function" } }, }; -- cgit v1.2.3