diff options
author | markm <markm@FreeBSD.org> | 2002-03-03 13:17:00 +0000 |
---|---|---|
committer | markm <markm@FreeBSD.org> | 2002-03-03 13:17:00 +0000 |
commit | a9c0aaa0e8a6efa66f2c4364b24f1bf7520d9a53 (patch) | |
tree | 9ca989e7577c4407884daecc9836097ae6fccce0 /usr.bin/xlint/lint1 | |
parent | 97ea65b2cb83e7b5b2c4afcacc3a185482457c2a (diff) | |
download | FreeBSD-src-a9c0aaa0e8a6efa66f2c4364b24f1bf7520d9a53.zip FreeBSD-src-a9c0aaa0e8a6efa66f2c4364b24f1bf7520d9a53.tar.gz |
Import of NetBSD's (x)lint, snapshotted at 2002-3-3.
Diffstat (limited to 'usr.bin/xlint/lint1')
-rw-r--r-- | usr.bin/xlint/lint1/Makefile | 58 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/cgram.y | 210 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/decl.c | 521 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/emit1.c | 73 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/err.c | 128 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/externs1.h | 308 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/func.c | 180 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/init.c | 53 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/lint1.h | 50 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/main1.c | 70 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/makeman | 94 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/mem1.c | 80 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/op.h | 2 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/scan.l | 297 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/tree.c | 611 |
15 files changed, 1496 insertions, 1239 deletions
diff --git a/usr.bin/xlint/lint1/Makefile b/usr.bin/xlint/lint1/Makefile index d5e519a..6c8a68f 100644 --- a/usr.bin/xlint/lint1/Makefile +++ b/usr.bin/xlint/lint1/Makefile @@ -1,19 +1,49 @@ -# $NetBSD: Makefile,v 1.3 1995/07/04 01:53:05 cgd Exp $ +# $NetBSD: Makefile,v 1.25 2002/02/01 01:32:20 ross Exp $ -PROG= lint1 -SRCS= cgram.c scan.c mem1.c mem.c err.c main1.c decl.c tree.c func.c \ - init.c emit.c emit1.c -NOMAN= -LDADD+= -ll -DPADD+= ${LIBL} -YFLAGS= -d -CFLAGS+=-I. -LINTFLAGS=-aehpz -CLEANFILES+=y.tab.h cgram.c scan.c +.include <bsd.own.mk> -BINDIR= /usr/libexec +PROG= lint1 +SRCS= cgram.y scan.l mem1.c mem.c err.c main1.c decl.c tree.c func.c \ + init.c emit.c emit1.c inittyp.c +MAN= lint.7 +YHEADER= -# XXX: -O causes the gcc to die on the i386, when compiling tree.o -CFLAGS+= -DXXX_BROKEN_GCC +CPPFLAGS+= -I${.CURDIR} -I. + +.if ${OBJECT_FMT} == "a.out" +CPPFLAGS+= -DTARGET_OBJFMT_AOUT +.elif ${OBJECT_FMT} == "COFF" +CPPFLAGS+= -DTARGET_OBJFMT_COFF +.elif ${OBJECT_FMT} == "ELF" +CPPFLAGS+= -DTARGET_OBJFMT_ELF +.else +.BEGIN: + @echo "Unrecognized OBJECT_FMT ${OBJECT_FMT}" + @false +.endif + +LINTFLAGS= -aehpz +WFORMAT=1 #hopeless +BINDIR= /usr/libexec + +scan.c: cgram.h + +CLEANFILES+= ${MAN} + +.if ${USETOOLS} == "yes" +LINT1= ${TOOLDIR}/libexec/${MACHINE_GNU_PLATFORM}-lint1 +.endif +LINT1?= ./${PROG} + +${MAN}: makeman ${LINT1:C/^\.\///} Makefile + sh ${.ALLSRC:M*makeman} ${LINT1} -m >${.TARGET} + +LDADD+= -lm +DPADD+= ${LIBM} + +.ifndef HOSTPROG +LDADD+= -ll +DPADD+= ${LIBL} .include <bsd.prog.mk> +.endif diff --git a/usr.bin/xlint/lint1/cgram.y b/usr.bin/xlint/lint1/cgram.y index e65584a..9fdc58c 100644 --- a/usr.bin/xlint/lint1/cgram.y +++ b/usr.bin/xlint/lint1/cgram.y @@ -1,7 +1,8 @@ %{ -/* $NetBSD: cgram.y,v 1.8 1995/10/02 17:31:35 jpo Exp $ */ +/* $NetBSD: cgram.y,v 1.23 2002/01/31 19:36:53 tv Exp $ */ /* + * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. * Copyright (c) 1994, 1995 Jochen Pohl * All Rights Reserved. * @@ -32,11 +33,13 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static char rcsid[] = "$NetBSD: cgram.y,v 1.8 1995/10/02 17:31:35 jpo Exp $"; +#include <sys/cdefs.h> +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: cgram.y,v 1.23 2002/01/31 19:36:53 tv Exp $"); #endif #include <stdlib.h> +#include <string.h> #include <limits.h> #include "lint1.h" @@ -55,10 +58,52 @@ int blklev; */ int mblklev; -static int toicon __P((tnode_t *)); -static void idecl __P((sym_t *, int)); -static void ignuptorp __P((void)); +/* + * Save the no-warns state and restore it to avoid the problem where + * if (expr) { stmt } / * NOLINT * / stmt; + */ +static int onowarn = -1; + +static int toicon(tnode_t *); +static void idecl(sym_t *, int, sbuf_t *); +static void ignuptorp(void); + +#ifdef DEBUG +static __inline void CLRWFLGS(void); +static __inline void CLRWFLGS(void) +{ + printf("%s, %d: clear flags %s %d\n", curr_pos.p_file, + curr_pos.p_line, __FILE__, __LINE__); + clrwflgs(); + onowarn = -1; +} +static __inline void SAVE(void); +static __inline void SAVE(void) +{ + if (onowarn != -1) + abort(); + printf("%s, %d: save flags %s %d = %d\n", curr_pos.p_file, + curr_pos.p_line, __FILE__, __LINE__, nowarn); + onowarn = nowarn; +} + +static __inline void RESTORE(void); +static __inline void RESTORE(void) +{ + if (onowarn != -1) { + nowarn = onowarn; + printf("%s, %d: restore flags %s %d = %d\n", curr_pos.p_file, + curr_pos.p_line, __FILE__, __LINE__, nowarn); + onowarn = -1; + } else + CLRWFLGS(); +} +#else +#define CLRWFLGS() clrwflgs(), onowarn = -1 +#define SAVE() onowarn = nowarn +#define RESTORE() (void)(onowarn == -1 ? (clrwflgs(), 0) : (nowarn = onowarn)) +#endif %} %union { @@ -129,6 +174,7 @@ static void ignuptorp __P((void)); %token T_BREAK %token T_RETURN %token T_ASM +%token T_SYMBOLRENAME %left T_COMMA %right T_ASSIGN T_OPASS @@ -205,6 +251,7 @@ static void ignuptorp __P((void)); %type <y_tnode> opt_expr %type <y_strg> string %type <y_strg> string2 +%type <y_sb> opt_asm_or_symbolrename %% @@ -228,13 +275,14 @@ translation_unit: ; ext_decl: - func_def { + asm_stmnt + | func_def { glclup(0); - clrwflgs(); + CLRWFLGS(); } | data_def { glclup(0); - clrwflgs(); + CLRWFLGS(); } ; @@ -278,7 +326,7 @@ data_def: } | declspecs deftyp type_init_decls T_SEMI | error T_SEMI { - globclup(); + globclup(); } | error T_RBRACE { globclup(); @@ -712,7 +760,7 @@ enums_with_opt_comma: error(54); } else { /* trailing "," prohibited in enum declaration */ - warning(54); + (void)gnuism(54); } $$ = $1; } @@ -757,24 +805,24 @@ type_init_decls: ; notype_init_decl: - notype_decl opt_asm_spec { - idecl($1, 0); + notype_decl opt_asm_or_symbolrename { + idecl($1, 0, $2); chksz($1); } - | notype_decl opt_asm_spec { - idecl($1, 1); + | notype_decl opt_asm_or_symbolrename { + idecl($1, 1, $2); } T_ASSIGN initializer { chksz($1); } ; type_init_decl: - type_decl opt_asm_spec { - idecl($1, 0); + type_decl opt_asm_or_symbolrename { + idecl($1, 0, $2); chksz($1); } - | type_decl opt_asm_spec { - idecl($1, 1); + | type_decl opt_asm_or_symbolrename { + idecl($1, 1, $2); } T_ASSIGN initializer { chksz($1); } @@ -1015,10 +1063,10 @@ vararg_parameter_type_list: ; parameter_type_list: - parameter_declaration opt_asm_spec { + parameter_declaration { $$ = $1; } - | parameter_type_list T_COMMA parameter_declaration opt_asm_spec { + | parameter_type_list T_COMMA parameter_declaration { $$ = lnklst($1, $3); } ; @@ -1051,10 +1099,16 @@ parameter_declaration: } ; -opt_asm_spec: - /* empty */ +opt_asm_or_symbolrename: /* expect only one */ + /* empty */ { + $$ = NULL; + } | T_ASM T_LPARN T_STRING T_RPARN { freeyyv(&$3, T_STRING); + $$ = NULL; + } + | T_SYMBOLRENAME T_LPARN T_NAME T_RPARN { + $$ = $3; } ; @@ -1212,15 +1266,11 @@ opt_stmnt_list: ; stmnt_list: - stmnt { - clrwflgs(); - } + stmnt | stmnt_list stmnt { - clrwflgs(); - } - | stmnt_list error T_SEMI { - clrwflgs(); + RESTORE(); } + | stmnt_list error T_SEMI ; expr_stmnt: @@ -1235,21 +1285,27 @@ expr_stmnt: selection_stmnt: if_without_else { + SAVE(); if2(); if3(0); } | if_without_else T_ELSE { + SAVE(); if2(); } stmnt { + CLRWFLGS(); if3(1); } | if_without_else T_ELSE error { + CLRWFLGS(); if3(0); } | switch_expr stmnt { + CLRWFLGS(); switch2(); } | switch_expr error { + CLRWFLGS(); switch2(); } ; @@ -1262,35 +1318,46 @@ if_without_else: if_expr: T_IF T_LPARN expr T_RPARN { if1($3); - clrwflgs(); + CLRWFLGS(); } ; switch_expr: T_SWITCH T_LPARN expr T_RPARN { switch1($3); - clrwflgs(); + CLRWFLGS(); + } + ; + +do_stmnt: + do stmnt { + CLRWFLGS(); } ; iteration_stmnt: while_expr stmnt { + CLRWFLGS(); while2(); } | while_expr error { + CLRWFLGS(); while2(); } - | do stmnt do_while_expr { - do2($3); + | do_stmnt do_while_expr { + do2($2); ftflg = 0; } | do error { + CLRWFLGS(); do2(NULL); } | for_exprs stmnt { + CLRWFLGS(); for2(); } | for_exprs error { + CLRWFLGS(); for2(); } ; @@ -1298,7 +1365,7 @@ iteration_stmnt: while_expr: T_WHILE T_LPARN expr T_RPARN { while1($3); - clrwflgs(); + CLRWFLGS(); } ; @@ -1317,7 +1384,7 @@ do_while_expr: for_exprs: T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN { for1($3, $5, $7); - clrwflgs(); + CLRWFLGS(); } ; @@ -1375,10 +1442,10 @@ read_until_rparn: declaration_list: declaration { - clrwflgs(); + CLRWFLGS(); } | declaration_list declaration { - clrwflgs(); + CLRWFLGS(); } ; @@ -1441,7 +1508,7 @@ expr: term: T_NAME { - /* XXX realy neccessary? */ + /* XXX really necessary? */ if (yychar < 0) yychar = yylex(); $$ = getnnode(getsym($1), yychar); @@ -1565,15 +1632,34 @@ identifier: /* ARGSUSED */ int -yyerror(msg) - char *msg; +yyerror(char *msg) { + error(249); if (++sytxerr >= 5) norecover(); return (0); } +static inline int uq_gt(uint64_t, uint64_t); +static inline int q_gt(int64_t, int64_t); + +static inline int +uq_gt(uint64_t a, uint64_t b) +{ + + return (a > b); +} + +static inline int +q_gt(int64_t a, int64_t b) +{ + + return (a > b); +} + +#define q_lt(a, b) q_gt(b, a) + /* * Gets a node for a constant and returns the value of this constant * as integer. @@ -1584,8 +1670,7 @@ yyerror(msg) * expressions, it frees the memory used for the expression. */ static int -toicon(tn) - tnode_t *tn; +toicon(tnode_t *tn) { int i; tspec_t t; @@ -1607,12 +1692,14 @@ toicon(tn) } else { i = (int)v->v_quad; if (isutyp(t)) { - if ((u_quad_t)v->v_quad > INT_MAX) { + if (uq_gt((uint64_t)v->v_quad, + (uint64_t)INT_MAX)) { /* integral constant too large */ warning(56); } } else { - if (v->v_quad > INT_MAX || v->v_quad < INT_MIN) { + if (q_gt(v->v_quad, (int64_t)INT_MAX) || + q_lt(v->v_quad, (int64_t)INT_MIN)) { /* integral constant too large */ warning(56); } @@ -1623,25 +1710,46 @@ toicon(tn) } static void -idecl(decl, initflg) - sym_t *decl; - int initflg; +idecl(sym_t *decl, int initflg, sbuf_t *rename) { + char *s; + initerr = 0; initsym = decl; switch (dcs->d_ctx) { case EXTERN: + if (rename != NULL) { + if (decl->s_rename != NULL) + lerror("idecl() 1"); + + s = getlblk(1, rename->sb_len + 1); + (void)memcpy(s, rename->sb_name, rename->sb_len + 1); + decl->s_rename = s; + freeyyv(&rename, T_NAME); + } decl1ext(decl, initflg); break; case ARG: + if (rename != NULL) { + /* symbol renaming can't be used on function arguments */ + error(310); + freeyyv(&rename, T_NAME); + break; + } (void)decl1arg(decl, initflg); break; case AUTO: + if (rename != NULL) { + /* symbol renaming can't be used on automatic variables */ + error(311); + freeyyv(&rename, T_NAME); + break; + } decl1loc(decl, initflg); break; default: - lerror("idecl()"); + lerror("idecl() 2"); } if (initflg && !initerr) @@ -1652,8 +1760,8 @@ idecl(decl, initflg) * Discard all input tokens up to and including the next * unmatched right paren */ -void -ignuptorp() +static void +ignuptorp(void) { int level; diff --git a/usr.bin/xlint/lint1/decl.c b/usr.bin/xlint/lint1/decl.c index fa023b7..a77a561 100644 --- a/usr.bin/xlint/lint1/decl.c +++ b/usr.bin/xlint/lint1/decl.c @@ -1,6 +1,7 @@ -/* $NetBSD: decl.c,v 1.11 1995/10/02 17:34:16 jpo Exp $ */ +/* $NetBSD: decl.c,v 1.29 2002/01/18 21:01:39 thorpej Exp $ */ /* + * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. * Copyright (c) 1994, 1995 Jochen Pohl * All Rights Reserved. * @@ -31,8 +32,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static char rcsid[] = "$NetBSD: decl.c,v 1.11 1995/10/02 17:34:16 jpo Exp $"; +#include <sys/cdefs.h> +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: decl.c,v 1.29 2002/01/18 21:01:39 thorpej Exp $"); #endif #include <sys/param.h> @@ -44,9 +46,6 @@ static char rcsid[] = "$NetBSD: decl.c,v 1.11 1995/10/02 17:34:16 jpo Exp $"; const char *unnamed = "<unnamed>"; -/* contains various information and classification on types */ -ttab_t ttab[NTSPEC]; - /* shared type structures for arithmtic types and void */ static type_t *typetab; @@ -59,107 +58,33 @@ int enumval; */ dinfo_t *dcs; -static type_t *tdeferr __P((type_t *, tspec_t)); -static void settdsym __P((type_t *, sym_t *)); -static tspec_t mrgtspec __P((tspec_t, tspec_t)); -static void align __P((int, int)); -static sym_t *newtag __P((sym_t *, scl_t, int, int)); -static int eqargs __P((type_t *, type_t *, int *)); -static int mnoarg __P((type_t *, int *)); -static int chkosdef __P((sym_t *, sym_t *)); -static int chkptdecl __P((sym_t *, sym_t *)); -static sym_t *nsfunc __P((sym_t *, sym_t *)); -static void osfunc __P((sym_t *, sym_t *)); -static void ledecl __P((sym_t *)); -static int chkinit __P((sym_t *)); -static void chkausg __P((int, sym_t *)); -static void chkvusg __P((int, sym_t *)); -static void chklusg __P((sym_t *)); -static void chktusg __P((sym_t *)); -static void chkglvar __P((sym_t *)); -static void glchksz __P((sym_t *)); +static type_t *tdeferr(type_t *, tspec_t); +static void settdsym(type_t *, sym_t *); +static tspec_t mrgtspec(tspec_t, tspec_t); +static void align(int, int); +static sym_t *newtag(sym_t *, scl_t, int, int); +static int eqargs(type_t *, type_t *, int *); +static int mnoarg(type_t *, int *); +static int chkosdef(sym_t *, sym_t *); +static int chkptdecl(sym_t *, sym_t *); +static sym_t *nsfunc(sym_t *, sym_t *); +static void osfunc(sym_t *, sym_t *); +static void ledecl(sym_t *); +static int chkinit(sym_t *); +static void chkausg(int, sym_t *); +static void chkvusg(int, sym_t *); +static void chklusg(sym_t *); +static void chktusg(sym_t *); +static void chkglvar(sym_t *); +static void glchksz(sym_t *); /* * initializes all global vars used in declarations */ void -initdecl() -{ - 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" } }, - }; +initdecl(void) +{ + int i; /* declaration stack */ dcs = xcalloc(1, sizeof (dinfo_t)); @@ -167,13 +92,8 @@ initdecl() dcs->d_ldlsym = &dcs->d_dlsyms; /* type information and classification */ - 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; - } - + inittyp(); + /* shared type structures */ typetab = xcalloc(NTSPEC, sizeof (type_t)); for (i = 0; i < NTSPEC; i++) @@ -208,15 +128,14 @@ initdecl() * if it is to be modified (adding qualifiers or anything else). */ type_t * -gettyp(t) - tspec_t t; +gettyp(tspec_t t) { + return (&typetab[t]); } type_t * -duptyp(tp) - const type_t *tp; +duptyp(const type_t *tp) { type_t *ntp; @@ -230,8 +149,7 @@ duptyp(tp) * allocated memory should be freed after the expr). */ type_t * -tduptyp(tp) - const type_t *tp; +tduptyp(const type_t *tp) { type_t *ntp; @@ -245,8 +163,7 @@ tduptyp(tp) * struct, union or enum type. */ int -incompl(tp) - type_t *tp; +incompl(type_t *tp) { tspec_t t; @@ -267,9 +184,7 @@ incompl(tp) * types. */ void -setcompl(tp, ic) - type_t *tp; - int ic; +setcompl(type_t *tp, int ic) { tspec_t t; @@ -290,9 +205,9 @@ setcompl(tp, ic) * storage classes. */ void -addscl(sc) - scl_t sc; +addscl(scl_t sc) { + if (sc == INLINE) { if (dcs->d_inline) /* duplicate '%s' */ @@ -327,8 +242,7 @@ addscl(sc) * struct/union/enum tag. */ void -addtype(tp) - type_t *tp; +addtype(type_t *tp) { tspec_t t; @@ -394,7 +308,7 @@ addtype(tp) /* remeber specifiers "signed" and "unsigned" in dcs->d_smod */ if (dcs->d_smod != NOTSPEC) /* - * more then one "signed" and/or "unsigned"; print + * more than one "signed" and/or "unsigned"; print * an error in deftyp() */ dcs->d_terr = 1; @@ -411,7 +325,7 @@ addtype(tp) } else { /* * remember specifiers "void", "char", "int", "float" or - * "double" int dcs->d_atyp + * "double" int dcs->d_atyp */ if (dcs->d_atyp != NOTSPEC) /* more than one, print error in deftyp() */ @@ -425,9 +339,7 @@ addtype(tp) * and other specifiers (except struct, union, enum, typedef name) */ static type_t * -tdeferr(td, t) - type_t *td; - tspec_t t; +tdeferr(type_t *td, tspec_t t) { tspec_t t2; @@ -479,6 +391,30 @@ tdeferr(td, t) } break; /* LINTED (enumeration values not handled in switch) */ + case NOTSPEC: + case USHORT: + case UCHAR: + case SCHAR: + case CHAR: + case FUNC: + case ARRAY: + case PTR: + case ENUM: + case UNION: + case STRUCT: + case VOID: + case LDOUBLE: + case DOUBLE: + case FLOAT: + case UQUAD: + case QUAD: + case ULONG: + case UINT: + case INT: + break; + + case NTSPEC: /* this value unused */ + break; } /* Anything other is not accepted. */ @@ -492,14 +428,12 @@ tdeferr(td, t) * or enum tag if the typedef name is the first defined for this tag. * * If the tag is unnamed, the typdef name is used for identification - * of this tag in lint2. Although its possible that more then one typedef + * of this tag in lint2. Although its possible that more than one typedef * name is defined for one tag, the first name defined should be unique * if the tag is unnamed. */ static void -settdsym(tp, sym) - type_t *tp; - sym_t *sym; +settdsym(type_t *tp, sym_t *sym) { tspec_t t; @@ -517,13 +451,13 @@ settdsym(tp, sym) * (and not the declarator) in the top element of the declaration stack. * Also detect multiple qualifiers of the same kind. - * The rememberd qualifier is used by deftyp() to construct the type + * The remembered qualifier is used by deftyp() to construct the type * for all declarators. */ void -addqual(q) - tqual_t q; +addqual(tqual_t q) { + if (q == CONST) { if (dcs->d_const) { /* duplicate "%s" */ @@ -546,8 +480,7 @@ addqual(q) * argument declaration lists ...) */ void -pushdecl(sc) - scl_t sc; +pushdecl(scl_t sc) { dinfo_t *di; @@ -566,7 +499,7 @@ pushdecl(sc) * Go back to previous declaration level */ void -popdecl() +popdecl(void) { dinfo_t *di; @@ -651,7 +584,7 @@ popdecl() * global declarations/definitions. */ void -setasm() +setasm(void) { dinfo_t *di; @@ -664,8 +597,9 @@ setasm() * will be used by the next declaration */ void -clrtyp() +clrtyp(void) { + dcs->d_atyp = dcs->d_smod = dcs->d_lmod = NOTSPEC; dcs->d_scl = NOSCL; dcs->d_type = NULL; @@ -683,7 +617,7 @@ clrtyp() * context. */ void -deftyp() +deftyp(void) { tspec_t t, s, l; type_t *tp; @@ -799,9 +733,9 @@ deftyp() * Merge type specifiers (char, ..., long long, signed, unsigned). */ static tspec_t -mrgtspec(t, s) - tspec_t t, s; +mrgtspec(tspec_t t, tspec_t s) { + if (s == SIGNED || s == UNSIGN) { if (t == CHAR) { t = s == SIGNED ? SCHAR : UCHAR; @@ -827,17 +761,18 @@ mrgtspec(t, s) * if name is not NULL. */ int -length(tp, name) - type_t *tp; - const char *name; +length(type_t *tp, const char *name) { int elem, elsz; elem = 1; - while (tp->t_tspec == ARRAY) { + while (tp && tp->t_tspec == ARRAY) { elem *= tp->t_dim; tp = tp->t_subt; } + if (tp == NULL) + return -1; + switch (tp->t_tspec) { case FUNC: /* compiler takes size of function */ @@ -870,15 +805,17 @@ length(tp, name) * Get the alignment of the given Type in bits. */ int -getbound(tp) - type_t *tp; +getbound(type_t *tp) { int a; tspec_t t; - while (tp->t_tspec == ARRAY) + while (tp && tp->t_tspec == ARRAY) tp = tp->t_subt; + if (tp == NULL) + return -1; + if ((t = tp->t_tspec) == STRUCT || t == UNION) { a = tp->t_str->align; } else if (t == FUNC) { @@ -902,8 +839,7 @@ getbound(tp) * struct/union/enum elements and parameters. */ sym_t * -lnklst(l1, l2) - sym_t *l1, *l2; +lnklst(sym_t *l1, sym_t *l2) { sym_t *l; @@ -925,8 +861,7 @@ lnklst(l1, l2) * - void types other than type of function or pointer */ void -chktyp(sym) - sym_t *sym; +chktyp(sym_t *sym) { tspec_t to, t; type_t **tpp, *tp; @@ -1018,12 +953,12 @@ chktyp(sym) * Process the declarator of a struct/union element. */ sym_t * -decl1str(dsym) - sym_t *dsym; +decl1str(sym_t *dsym) { type_t *tp; tspec_t t; - int sz, o, len; + int sz, len; + int o = 0; /* Appease gcc */ scl_t sc; if ((sc = dsym->s_scl) != MOS && sc != MOU) @@ -1053,25 +988,38 @@ decl1str(dsym) */ if (t == CHAR || t == UCHAR || t == SCHAR || t == SHORT || t == USHORT || t == ENUM) { - if (sflag) { - /* bit-field type '%s' invalid in ANSI C */ - warning(273, tyname(tp)); - } else if (pflag) { - /* nonportable bit-field type */ - warning(34); + if (bitfieldtype_ok == 0) { + if (sflag) { + /* + * bit-field type '%s' invalid in + * ANSI C + */ + warning(273, tyname(tp)); + } else if (pflag) { + /* nonportable bit-field type */ + warning(34); + } } } else if (t == INT && dcs->d_smod == NOTSPEC) { - if (pflag) { + if (pflag && bitfieldtype_ok == 0) { /* nonportable bit-field type */ warning(34); } } else if (t != INT && t != UINT) { - /* illegal bit-field type */ - error(35); - sz = tp->t_flen; - dsym->s_type = tp = duptyp(gettyp(t = INT)); - if ((tp->t_flen = sz) > size(t)) - tp->t_flen = size(t); + /* + * Non-integer types are always illegal for + * bitfields, regardless of BITFIELDTYPE. + * Integer types not dealt with above are + * okay only if BITFIELDTYPE is in effect. + */ + if (bitfieldtype_ok == 0 || isityp(t) == 0) { + /* illegal bit-field type */ + error(35); + sz = tp->t_flen; + dsym->s_type = tp = duptyp(gettyp(t = INT)); + if ((tp->t_flen = sz) > size(t)) + tp->t_flen = size(t); + } } if ((len = tp->t_flen) < 0 || len > size(t)) { /* illegal bit-field size */ @@ -1127,6 +1075,12 @@ decl1str(dsym) chkfdef(dsym, 0); + /* + * Clear the BITFIELDTYPE indicator after processing each + * structure element. + */ + bitfieldtype_ok = 0; + return (dsym); } @@ -1136,8 +1090,7 @@ decl1str(dsym) * al contains the required alignment, len the length of a bit-field. */ static void -align(al, len) - int al, len; +align(int al, int len) { int no; @@ -1148,7 +1101,7 @@ align(al, len) */ if (al > dcs->d_stralign) dcs->d_stralign = al; - + no = (dcs->d_offset + (al - 1)) & ~(al - 1); if (len == 0 || dcs->d_offset + len > no) dcs->d_offset = no; @@ -1158,16 +1111,15 @@ align(al, len) * Remember the width of the field in its type structure. */ sym_t * -bitfield(dsym, len) - sym_t *dsym; - int len; +bitfield(sym_t *dsym, int len) { + if (dsym == NULL) { dsym = getblk(sizeof (sym_t)); dsym->s_name = unnamed; dsym->s_kind = FMOS; dsym->s_scl = MOS; - dsym->s_type = gettyp(INT); + dsym->s_type = gettyp(UINT); dsym->s_blklev = -1; } dsym->s_type = duptyp(dsym->s_type); @@ -1184,14 +1136,14 @@ bitfield(dsym, len) * will be at the top of the list. */ pqinf_t * -mergepq(p1, p2) - pqinf_t *p1, *p2; +mergepq(pqinf_t *p1, pqinf_t *p2) { pqinf_t *p; if (p2->p_pcnt != 0) { /* left '*' at the end of the list */ - for (p = p2; p->p_nxt != NULL; p = p->p_nxt) ; + for (p = p2; p->p_nxt != NULL; p = p->p_nxt) + continue; p->p_nxt = p1; return (p2); } else { @@ -1223,16 +1175,16 @@ mergepq(p1, p2) * declarator. The new type extension is inserted between both. */ sym_t * -addptr(decl, pi) - sym_t *decl; - pqinf_t *pi; +addptr(sym_t *decl, pqinf_t *pi) { type_t **tpp, *tp; pqinf_t *npi; tpp = &decl->s_type; - while (*tpp != dcs->d_type) + while (*tpp && *tpp != dcs->d_type) tpp = &(*tpp)->t_subt; + if (*tpp == NULL) + return decl; while (pi != NULL) { *tpp = tp = getblk(sizeof (type_t)); @@ -1252,15 +1204,15 @@ addptr(decl, pi) * n is the specified dimension */ sym_t * -addarray(decl, dim, n) - sym_t *decl; - int dim, n; +addarray(sym_t *decl, int dim, int n) { type_t **tpp, *tp; tpp = &decl->s_type; - while (*tpp != dcs->d_type) + while (*tpp && *tpp != dcs->d_type) tpp = &(*tpp)->t_subt; + if (*tpp == NULL) + return decl; *tpp = tp = getblk(sizeof (type_t)); tp->t_tspec = ARRAY; @@ -1283,8 +1235,7 @@ addarray(decl, dim, n) } sym_t * -addfunc(decl, args) - sym_t *decl, *args; +addfunc(sym_t *decl, sym_t *args) { type_t **tpp, *tp; @@ -1314,8 +1265,10 @@ addfunc(decl, args) } tpp = &decl->s_type; - while (*tpp != dcs->d_nxt->d_type) + while (*tpp && *tpp != dcs->d_nxt->d_type) tpp = &(*tpp)->t_subt; + if (*tpp == NULL) + return decl; *tpp = tp = getblk(sizeof (type_t)); tp->t_tspec = FUNC; @@ -1332,8 +1285,7 @@ addfunc(decl, args) */ /* ARGSUSED */ static sym_t * -nsfunc(decl, args) - sym_t *decl, *args; +nsfunc(sym_t *decl, sym_t *args) { sym_t *arg, *sym; scl_t sc; @@ -1371,9 +1323,9 @@ nsfunc(decl, args) * Called for old style function declarations. */ static void -osfunc(decl, args) - sym_t *decl, *args; +osfunc(sym_t *decl, sym_t *args) { + /* * Remember list of params only if this is really seams to be * a function definition. @@ -1382,7 +1334,7 @@ osfunc(decl, args) decl->s_type == dcs->d_nxt->d_type) { /* * We assume that this becomes a function definition. If - * we are wrong, its corrected in chkfdef(). + * we are wrong, its corrected in chkfdef(). */ if (args != NULL) { decl->s_osdef = 1; @@ -1401,10 +1353,9 @@ osfunc(decl, args) * error message. */ void -chkfdef(sym, msg) - sym_t *sym; - int msg; +chkfdef(sym_t *sym, int msg) { + if (sym->s_osdef) { if (msg) { /* incomplete or misplaced function definition */ @@ -1423,10 +1374,9 @@ chkfdef(sym, msg) * s_def and s_reg are valid after dname(). */ sym_t * -dname(sym) - sym_t *sym; +dname(sym_t *sym) { - scl_t sc; + scl_t sc = NOSCL; if (sym->s_scl == NOSCL) { dcs->d_rdcsym = NULL; @@ -1489,7 +1439,7 @@ dname(sym) * XXX somewhat ugly because we dont know whether * this is AUTO or EXTERN (functions). If we are * wrong it must be corrected in decl1loc(), where - * we have the neccessary type information. + * we have the necessary type information. */ sc = AUTO; sym->s_def = DEF; @@ -1522,9 +1472,9 @@ dname(sym) * definition. */ sym_t * -iname(sym) - sym_t *sym; +iname(sym_t *sym) { + if (sym->s_scl != NOSCL) { if (blklev == sym->s_blklev) { /* redeclaration of formal parameter %s */ @@ -1551,12 +1501,9 @@ iname(sym) * semi is 1 if the following token is T_SEMI */ type_t * -mktag(tag, kind, decl, semi) - sym_t *tag; - tspec_t kind; - int decl, semi; +mktag(sym_t *tag, tspec_t kind, int decl, int semi) { - scl_t scl; + scl_t scl = NOSCL; type_t *tp; if (kind == STRUCT) { @@ -1590,7 +1537,7 @@ mktag(tag, kind, decl, semi) } else { tag = getblk(sizeof (sym_t)); tag->s_name = unnamed; - STRUCT_ASSIGN(tag->s_dpos, curr_pos); + UNIQUE_CURR_POS(tag->s_dpos); tag->s_kind = FTAG; tag->s_scl = scl; tag->s_blklev = -1; @@ -1622,11 +1569,9 @@ mktag(tag, kind, decl, semi) * semi is 1 if T_SEMI follows */ static sym_t * -newtag(tag, scl, decl, semi) - sym_t *tag; - scl_t scl; - int decl, semi; +newtag(sym_t *tag, scl_t scl, int decl, int semi) { + if (tag->s_blklev < blklev) { if (semi) { /* "struct a;" */ @@ -1641,7 +1586,7 @@ newtag(tag, scl, decl, semi) } dcs->d_nxt->d_nedecl = 1; } else if (decl) { - /* "struct a { ..." */ + /* "struct a { ... } " */ if (hflag) /* redefinition hides earlier one: %s */ warning(43, tag->s_name); @@ -1677,8 +1622,7 @@ newtag(tag, scl, decl, semi) } const char * -scltoa(sc) - scl_t sc; +scltoa(scl_t sc) { const char *s; @@ -1701,9 +1645,7 @@ scltoa(sc) * tp points to the type of the, tag, fmem to the list of members/enums. */ type_t * -compltag(tp, fmem) - type_t *tp; - sym_t *fmem; +compltag(type_t *tp, sym_t *fmem) { tspec_t t; str_t *sp; @@ -1745,13 +1687,12 @@ compltag(tp, fmem) * * sym points to the enumerator * val is the value of the enumerator - * impl is 1 if the the value of the enumerator was not explicit specified. + * impl is 1 if the value of the enumerator was not explicit specified. */ sym_t * -ename(sym, val, impl) - sym_t *sym; - int val, impl; +ename(sym_t *sym, int val, int impl) { + if (sym->s_scl) { if (sym->s_blklev == blklev) { /* no hflag, because this is illegal!!! */ @@ -1792,9 +1733,7 @@ ename(sym, val, impl) * Process a single external declarator. */ void -decl1ext(dsym, initflg) - sym_t *dsym; - int initflg; +decl1ext(sym_t *dsym, int initflg) { int warn, rval, redec; sym_t *rdsym; @@ -1850,7 +1789,7 @@ decl1ext(dsym, initflg) } if (!redec && !isredec(dsym, (warn = 0, &warn))) { - + if (warn) { /* redeclaration of %s */ (*(sflag ? error : warning))(27, dsym->s_name); @@ -1896,7 +1835,7 @@ decl1ext(dsym, initflg) compltyp(dsym, rdsym); } - + rmsym(rdsym); } @@ -1913,9 +1852,9 @@ decl1ext(dsym, initflg) * the same symbol. */ void -cpuinfo(sym, rdsym) - sym_t *sym, *rdsym; +cpuinfo(sym_t *sym, sym_t *rdsym) { + sym->s_spos = rdsym->s_spos; sym->s_upos = rdsym->s_upos; sym->s_set = rdsym->s_set; @@ -1928,9 +1867,7 @@ cpuinfo(sym, rdsym) * a warning. */ int -isredec(dsym, warn) - sym_t *dsym; - int *warn; +isredec(sym_t *dsym, int *warn) { sym_t *rsym; @@ -2003,15 +1940,13 @@ isredec(dsym, warn) * Checks if two types are compatible. Returns 0 if not, otherwise 1. * * ignqual ignore qualifiers of type; used for function params - * promot promote left type; used for comparision of params of + * promot promote left type; used for comparison of params of * old style function definitions with params of prototypes. * *warn set to 1 if an old style function declaration is not * compatible with a prototype */ int -eqtype(tp1, tp2, ignqual, promot, warn) - type_t *tp1, *tp2; - int ignqual, promot, *warn; +eqtype(type_t *tp1, type_t *tp2, int ignqual, int promot, int *warn) { tspec_t t; @@ -2077,9 +2012,7 @@ eqtype(tp1, tp2, ignqual, promot, warn) * Compares the parameter types of two prototypes. */ static int -eqargs(tp1, tp2, warn) - type_t *tp1, *tp2; - int *warn; +eqargs(type_t *tp1, type_t *tp2, int *warn) { sym_t *a1, *a2; @@ -2113,9 +2046,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) { sym_t *arg; tspec_t t; @@ -2140,8 +2071,7 @@ mnoarg(tp, warn) * a previous old style function definition. */ static int -chkosdef(rdsym, dsym) - sym_t *rdsym, *dsym; +chkosdef(sym_t *rdsym, sym_t *dsym) { sym_t *args, *pargs, *arg, *parg; int narg, nparg, n; @@ -2202,8 +2132,7 @@ chkosdef(rdsym, dsym) * be duplicated. */ void -compltyp(dsym, ssym) - sym_t *dsym, *ssym; +compltyp(sym_t *dsym, sym_t *ssym) { type_t **dstp, *src; type_t *dst; @@ -2237,9 +2166,7 @@ compltyp(dsym, ssym) * Completes the declaration of a single argument. */ sym_t * -decl1arg(sym, initflg) - sym_t *sym; - int initflg; +decl1arg(sym_t *sym, int initflg) { tspec_t t; @@ -2303,7 +2230,7 @@ decl1arg(sym, initflg) * prototype. */ void -cluparg() +cluparg(void) { sym_t *args, *arg, *pargs, *parg; int narg, nparg, n, msg; @@ -2417,7 +2344,7 @@ cluparg() /* from now the prototype is valid */ funcsym->s_osdef = 0; funcsym->s_args = NULL; - + } } @@ -2428,8 +2355,7 @@ cluparg() * Returns 1 if the position of the previous declaration should be reported. */ static int -chkptdecl(arg, parg) - sym_t *arg, *parg; +chkptdecl(sym_t *arg, sym_t *parg) { type_t *tp, *ptp; int warn, msg; @@ -2462,10 +2388,9 @@ chkptdecl(arg, parg) * Completes a single local declaration/definition. */ void -decl1loc(dsym, initflg) - sym_t *dsym; - int initflg; +decl1loc(sym_t *dsym, int initflg) { + /* Correct a mistake done in dname(). */ if (dsym->s_type->t_tspec == FUNC) { dsym->s_def = DECL; @@ -2570,7 +2495,7 @@ decl1loc(dsym, initflg) if (hflag) /* declaration hides earlier one: %s */ warning(95, dsym->s_name); - + } if (dcs->d_rdcsym->s_blklev == blklev) { @@ -2604,8 +2529,7 @@ decl1loc(dsym, initflg) * Processes (re)declarations of external Symbols inside blocks. */ static void -ledecl(dsym) - sym_t *dsym; +ledecl(sym_t *dsym) { int eqt, warn; sym_t *esym; @@ -2660,8 +2584,7 @@ ledecl(dsym) * detected. */ static int -chkinit(sym) - sym_t *sym; +chkinit(sym_t *sym) { int err; @@ -2692,7 +2615,7 @@ chkinit(sym) * Create a symbole for an abstract declaration. */ sym_t * -aname() +aname(void) { sym_t *sym; @@ -2720,8 +2643,9 @@ aname() * Removes anything which has nothing to do on global level. */ void -globclup() +globclup(void) { + while (dcs->d_nxt != NULL) popdecl(); @@ -2740,9 +2664,9 @@ globclup() * Process an abstract type declaration */ sym_t * -decl1abs(sym) - sym_t *sym; +decl1abs(sym_t *sym) { + chkfdef(sym, 1); chktyp(sym); return (sym); @@ -2752,9 +2676,9 @@ decl1abs(sym) * Checks size after declarations of variables and their initialisation. */ void -chksz(dsym) - sym_t *dsym; +chksz(sym_t *dsym) { + /* * check size only for symbols which are defined and no function and * not typedef name @@ -2781,12 +2705,12 @@ chksz(dsym) * Mark an object as set if it is not already */ void -setsflg(sym) - sym_t *sym; +setsflg(sym_t *sym) { + if (!sym->s_set) { sym->s_set = 1; - STRUCT_ASSIGN(sym->s_spos, curr_pos); + UNIQUE_CURR_POS(sym->s_spos); } } @@ -2794,13 +2718,12 @@ setsflg(sym) * Mark an object as used if it is not already */ void -setuflg(sym, fcall, szof) - sym_t *sym; - int fcall, szof; +setuflg(sym_t *sym, int fcall, int szof) { + if (!sym->s_used) { sym->s_used = 1; - STRUCT_ASSIGN(sym->s_upos, curr_pos); + UNIQUE_CURR_POS(sym->s_upos); } /* * for function calls another record is written @@ -2818,8 +2741,7 @@ setuflg(sym, fcall, szof) * with s_dlnxt) if these are not used or only set. */ void -chkusage(di) - dinfo_t *di; +chkusage(dinfo_t *di) { sym_t *sym; int mknowarn; @@ -2839,9 +2761,7 @@ chkusage(di) * only set. */ void -chkusg1(novar, sym) - int novar; - sym_t *sym; +chkusg1(int novar, sym_t *sym) { pos_t cpos; @@ -2866,10 +2786,9 @@ chkusg1(novar, sym) } static void -chkausg(novar, arg) - int novar; - sym_t *arg; +chkausg(int novar, sym_t *arg) { + if (!arg->s_set) lerror("chkausg() 1"); @@ -2884,9 +2803,7 @@ chkausg(novar, arg) } static void -chkvusg(novar, sym) - int novar; - sym_t *sym; +chkvusg(int novar, sym_t *sym) { scl_t sc; sym_t *xsym; @@ -2953,9 +2870,9 @@ chkvusg(novar, sym) } static void -chklusg(lab) - sym_t *lab; +chklusg(sym_t *lab) { + if (blklev != 1 || lab->s_blklev != 1) lerror("chklusg() 1"); @@ -2971,9 +2888,9 @@ chklusg(lab) } static void -chktusg(sym) - sym_t *sym; +chktusg(sym_t *sym) { + if (!incompl(sym->s_type)) return; @@ -3009,7 +2926,7 @@ chktusg(sym) * - static symbols which are never used */ void -chkglsyms() +chkglsyms(void) { sym_t *sym; pos_t cpos; @@ -3036,12 +2953,12 @@ chkglsyms() } static void -chkglvar(sym) - sym_t *sym; +chkglvar(sym_t *sym) { + if (sym->s_scl == TYPEDEF || sym->s_scl == ENUMCON) return; - + if (sym->s_scl != EXTERN && sym->s_scl != STATIC) lerror("chkglvar() 1"); @@ -3083,13 +3000,13 @@ chkglvar(sym) } static void -glchksz(sym) - sym_t *sym; +glchksz(sym_t *sym) { + if (sym->s_def == TDEF) { if (sym->s_type->t_tspec == FUNC) /* - * this can happen if an syntax error occured + * this can happen if an syntax error occurred * after a function declaration */ return; @@ -3110,9 +3027,7 @@ glchksz(sym) * Prints information about location of previous definition/declaration. */ void -prevdecl(msg, psym) - int msg; - sym_t *psym; +prevdecl(int msg, sym_t *psym) { pos_t cpos; diff --git a/usr.bin/xlint/lint1/emit1.c b/usr.bin/xlint/lint1/emit1.c index ee2434e..fc47a84 100644 --- a/usr.bin/xlint/lint1/emit1.c +++ b/usr.bin/xlint/lint1/emit1.c @@ -1,6 +1,7 @@ -/* $NetBSD: emit1.c,v 1.4 1995/10/02 17:21:28 jpo Exp $ */ +/* $NetBSD: emit1.c,v 1.11 2002/01/31 19:36:54 tv Exp $ */ /* + * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. * Copyright (c) 1994, 1995 Jochen Pohl * All Rights Reserved. * @@ -31,16 +32,17 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static char rcsid[] = "$NetBSD: emit1.c,v 1.4 1995/10/02 17:21:28 jpo Exp $"; +#include <sys/cdefs.h> +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: emit1.c,v 1.11 2002/01/31 19:36:54 tv Exp $"); #endif #include <ctype.h> #include "lint1.h" -static void outtt __P((sym_t *, sym_t *)); -static void outfstrg __P((strg_t *)); +static void outtt(sym_t *, sym_t *); +static void outfstrg(strg_t *); /* * Write type into the output buffer. @@ -82,8 +84,7 @@ static void outfstrg __P((strg_t *)); * and 'v' (for volatile) */ void -outtype(tp) - type_t *tp; +outtype(type_t *tp) { int t, s, na; sym_t *arg; @@ -153,8 +154,7 @@ outtype(tp) * it uses its own output buffer for conversion */ const char * -ttos(tp) - type_t *tp; +ttos(type_t *tp) { static ob_t tob; ob_t tmp; @@ -184,9 +184,12 @@ ttos(tp) * refers to this tag, this typename is written */ static void -outtt(tag, tdef) - sym_t *tag, *tdef; +outtt(sym_t *tag, sym_t *tdef) { + + /* + * 0 is no longer used. + */ if (tag->s_name != unnamed) { outint(1); outname(tag->s_name); @@ -194,7 +197,12 @@ outtt(tag, tdef) outint(2); outname(tdef->s_name); } else { - outint(0); + outint(3); + outint(tag->s_dpos.p_line); + outchar('.'); + outint(getfnid(tag->s_dpos.p_file)); + outchar('.'); + outint(tag->s_dpos.p_uniq); } } @@ -206,11 +214,9 @@ outtt(tag, tdef) * not here */ void -outsym(sym, sc, def) - sym_t *sym; - scl_t sc; - def_t def; +outsym(sym_t *sym, scl_t sc, def_t def) { + /* * Static function declarations must also be written to the output * file. Compatibility of function declarations (for both static @@ -266,6 +272,12 @@ outsym(sym, sc, def) /* name of the symbol */ outname(sym->s_name); + /* renamed name of symbol, if necessary */ + if (sym->s_rename) { + outchar('r'); + outname(sym->s_rename); + } + /* type of the symbol */ outtype(sym->s_type); } @@ -277,10 +289,7 @@ outsym(sym, sc, def) * they are called with proper argument types */ void -outfdef(fsym, posp, rval, osdef, args) - sym_t *fsym, *args; - pos_t *posp; - int rval, osdef; +outfdef(sym_t *fsym, pos_t *posp, int rval, int osdef, sym_t *args) { int narg; sym_t *arg; @@ -352,6 +361,12 @@ outfdef(fsym, posp, rval, osdef, args) /* name of function */ outname(fsym->s_name); + /* renamed name of function, if necessary */ + if (fsym->s_rename) { + outchar('r'); + outname(fsym->s_rename); + } + /* argument types and return value */ if (osdef) { narg = 0; @@ -376,13 +391,11 @@ outfdef(fsym, posp, rval, osdef, args) * (casted to void) */ void -outcall(tn, rvused, rvdisc) - tnode_t *tn; - int rvused, rvdisc; +outcall(tnode_t *tn, int rvused, int rvdisc) { tnode_t *args, *arg; int narg, n, i; - quad_t q; + int64_t q; tspec_t t; /* reset buffer */ @@ -410,7 +423,8 @@ outcall(tn, rvused, rvdisc) /* informations about arguments */ for (n = 1; n <= narg; n++) { /* the last argument is the top one in the tree */ - for (i = narg, arg = args; i > n; i--, arg = arg->tn_right) ; + for (i = narg, arg = args; i > n; i--, arg = arg->tn_right) + continue; arg = arg->tn_left; if (arg->tn_op == CON) { if (isityp(t = arg->tn_type->t_tspec)) { @@ -451,7 +465,8 @@ outcall(tn, rvused, rvdisc) outint(narg); for (n = 1; n <= narg; n++) { /* the last argument is the top one in the tree */ - for (i = narg, arg = args; i > n; i--, arg = arg->tn_right) ; + for (i = narg, arg = args; i > n; i--, arg = arg->tn_right) + continue; outtype(arg->tn_left->tn_type); } /* expected type of return value */ @@ -463,8 +478,7 @@ outcall(tn, rvused, rvdisc) * writes them, enclosed in "" and qouted if necessary, to the output buffer */ static void -outfstrg(strg) - strg_t *strg; +outfstrg(strg_t *strg) { int c, oc, first; u_char *cp; @@ -563,8 +577,7 @@ outfstrg(strg) * writes a record if sym was used */ void -outusg(sym) - sym_t *sym; +outusg(sym_t *sym) { /* reset buffer */ outclr(); diff --git a/usr.bin/xlint/lint1/err.c b/usr.bin/xlint/lint1/err.c index 32c80c4..ffbc1bc 100644 --- a/usr.bin/xlint/lint1/err.c +++ b/usr.bin/xlint/lint1/err.c @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.8 1995/10/02 17:37:00 jpo Exp $ */ +/* $NetBSD: err.c,v 1.16 2001/12/13 23:56:00 augustss Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -31,28 +31,27 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static char rcsid[] = "$NetBSD: err.c,v 1.8 1995/10/02 17:37:00 jpo Exp $"; +#include <sys/cdefs.h> +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: err.c,v 1.16 2001/12/13 23:56:00 augustss Exp $"); #endif +#include <sys/types.h> +#include <stdlib.h> +#include <stdarg.h> + +#include "lint1.h" + /* number of errors found */ int nerr; /* number of syntax errors */ int sytxerr; -#include <stdlib.h> -#ifdef __STDC__ -#include <stdarg.h> -#else -#include <varargs.h> -#endif - -#include "lint1.h" -static const char *basename __P((const char *)); -static void verror __P((int, va_list)); -static void vwarning __P((int, va_list)); +static const char *basename(const char *); +static void verror(int, va_list); +static void vwarning(int, va_list); const char *msgs[] = { @@ -218,7 +217,7 @@ const char *msgs[] = { "assignment in conditional context", /* 159 */ "operator '==' found where '=' was expected", /* 160 */ "constant in conditional context", /* 161 */ - "comparision of %s with %s, op %s", /* 162 */ + "comparison of %s with %s, op %s", /* 162 */ "a cast does not yield an lvalue", /* 163 */ "assignment of negative constant to unsigned type", /* 164 */ "constant truncated by assignment", /* 165 */ @@ -286,7 +285,7 @@ const char *msgs[] = { "const object %s should have initializer", /* 227 */ "function cannot return const or volatile object", /* 228 */ "questionable conversion of function pointer", /* 229 */ - "nonportable character comparision, op %s", /* 230 */ + "nonportable character comparison, op %s", /* 230 */ "argument %s unused in function %s", /* 231 */ "label %s unused in function %s", /* 232 */ "struct %s never defined", /* 233 */ @@ -299,7 +298,7 @@ const char *msgs[] = { "assignment of different structures", /* 240 */ "dubious operation on enum, op %s", /* 241 */ "combination of '%s' and '%s', op %s", /* 242 */ - "dubious comparision of enums, op %s", /* 243 */ + "dubious comparison of enums, op %s", /* 243 */ "illegal structure pointer combination", /* 244 */ "illegal structure pointer combination, op %s", /* 245 */ "dubious conversion of enum to '%s'", /* 246 */ @@ -330,7 +329,7 @@ const char *msgs[] = { "switch expression must be of type `int' in traditional C", /* 271 */ "empty translation unit", /* 272 */ "bit-field type '%s' invalid in ANSI C", /* 273 */ - "ANSI C forbids comparision of %s with %s", /* 274 */ + "ANSI C forbids comparison of %s with %s", /* 274 */ "cast discards 'const' from pointer target type", /* 275 */ "", /* 276 */ "initialisation of '%s' with '%s'", /* 277 */ @@ -366,15 +365,29 @@ const char *msgs[] = { "static variable %s set but not used", /* 307 */ "", /* 308 */ "extra bits set to 0 in conversion of '%s' to '%s', op %s", /* 309 */ + "symbol renaming can't be used on function arguments", /* 310 */ + "symbol renaming can't be used on automatic variables", /* 311 */ + "%s C does not support // comments", /* 312 */ }; /* + * print a list of the messages with their ids + */ +void +msglist(void) +{ + int i; + + for (i = 0; i < sizeof(msgs) / sizeof(msgs[0]); i++) + printf("%d\t%s\n", i, msgs[i]); +} + +/* * If Fflag is not set basename() returns a pointer to the last * component of the path, otherwise it returns the argument. */ static const char * -basename(path) - const char *path; +basename(const char *path) { const char *cp, *cp1, *cp2; @@ -392,26 +405,28 @@ basename(path) } static void -verror(n, ap) - int n; - va_list ap; +verror( int n, va_list ap) { const char *fn; + if (ERR_ISSET(n, &msgset)) + return; + fn = basename(curr_pos.p_file); (void)printf("%s(%d): ", fn, curr_pos.p_line); (void)vprintf(msgs[n], ap); - (void)printf("\n"); + (void)printf(" [%d]\n", n); nerr++; } static void -vwarning(n, ap) - int n; - va_list ap; +vwarning( int n, va_list ap) { const char *fn; + if (ERR_ISSET(n, &msgset)) + return; + if (nowarn) /* this warning is suppressed by a LINTED comment */ return; @@ -419,46 +434,28 @@ vwarning(n, ap) fn = basename(curr_pos.p_file); (void)printf("%s(%d): warning: ", fn, curr_pos.p_line); (void)vprintf(msgs[n], ap); - (void)printf("\n"); + (void)printf(" [%d]\n", n); + if (wflag) + nerr++; } void -#ifdef __STDC__ error(int n, ...) -#else -error(n, va_alist) - int n; - va_dcl -#endif { va_list ap; -#ifdef __STDC__ va_start(ap, n); -#else - va_start(ap); -#endif verror(n, ap); va_end(ap); } void -#ifdef __STDC__ lerror(const char *msg, ...) -#else -lerror(msg, va_alist) - const char *msg; - va_dcl -#endif { va_list ap; const char *fn; -#ifdef __STDC__ va_start(ap, msg); -#else - va_start(ap); -#endif fn = basename(curr_pos.p_file); (void)fprintf(stderr, "%s(%d): lint error: ", fn, curr_pos.p_line); (void)vfprintf(stderr, msg, ap); @@ -468,66 +465,39 @@ lerror(msg, va_alist) } void -#ifdef __STDC__ warning(int n, ...) -#else -warning(n, va_alist) - int n; - va_dcl -#endif { va_list ap; -#ifdef __STDC__ va_start(ap, n); -#else - va_start(ap); -#endif vwarning(n, ap); va_end(ap); } void -#ifdef __STDC__ message(int n, ...) -#else -message(n, va_alist) - int n; - va_dcl -#endif { va_list ap; const char *fn; -#ifdef __STDC__ + if (ERR_ISSET(n, &msgset)) + return; + va_start(ap, n); -#else - va_start(ap); -#endif fn = basename(curr_pos.p_file); (void)printf("%s(%d): ", fn, curr_pos.p_line); (void)vprintf(msgs[n], ap); - (void)printf("\n"); + (void)printf(" [%d]\n", n); va_end(ap); } int -#ifdef __STDC__ gnuism(int n, ...) -#else -gnuism(n, va_alist) - int n; - va_dcl -#endif { va_list ap; int msg; -#ifdef __STDC__ va_start(ap, n); -#else - va_start(ap); -#endif if (sflag && !gflag) { verror(n, ap); msg = 1; diff --git a/usr.bin/xlint/lint1/externs1.h b/usr.bin/xlint/lint1/externs1.h index e9923c7..765c1ef 100644 --- a/usr.bin/xlint/lint1/externs1.h +++ b/usr.bin/xlint/lint1/externs1.h @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.7 1995/10/02 17:31:39 jpo Exp $ */ +/* $NetBSD: externs1.h,v 1.13 2002/01/18 21:01:39 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -42,16 +42,16 @@ extern int eflag; extern int Fflag; extern int gflag; extern int hflag; -extern int pflag; extern int rflag; extern int sflag; extern int tflag; extern int uflag; extern int vflag; extern int yflag; +extern int wflag; extern int zflag; -extern void norecover __P((void)); +extern void norecover(void); /* * cgram.y @@ -60,8 +60,8 @@ extern int blklev; extern int mblklev; extern int yydebug; -extern int yyerror __P((char *)); -extern int yyparse __P((void)); +extern int yyerror(char *); +extern int yyparse(void); /* * scan.l @@ -70,41 +70,41 @@ extern pos_t curr_pos; extern pos_t csrc_pos; extern symt_t symtyp; extern FILE *yyin; -extern u_quad_t qbmasks[], qlmasks[], qumasks[]; +extern uint64_t qbmasks[], qlmasks[], qumasks[]; -extern void initscan __P((void)); -extern int sign __P((quad_t, tspec_t, int)); -extern int msb __P((quad_t, tspec_t, int)); -extern quad_t xsign __P((quad_t, tspec_t, int)); -extern void clrwflgs __P((void)); -extern sym_t *getsym __P((sbuf_t *)); -extern void cleanup __P((void)); -extern sym_t *pushdown __P((sym_t *)); -extern void rmsym __P((sym_t *)); -extern void rmsyms __P((sym_t *)); -extern void inssym __P((int, sym_t *)); -extern void freeyyv __P((void *, int)); -extern int yylex __P((void)); +extern void initscan(void); +extern int sign(int64_t, tspec_t, int); +extern int msb(int64_t, tspec_t, int); +extern int64_t xsign(int64_t, tspec_t, int); +extern void clrwflgs(void); +extern sym_t *getsym(sbuf_t *); +extern void cleanup(void); +extern sym_t *pushdown(sym_t *); +extern void rmsym(sym_t *); +extern void rmsyms(sym_t *); +extern void inssym(int, sym_t *); +extern void freeyyv(void *, int); +extern int yylex(void); /* * mem1.c */ -extern const char *fnalloc __P((const char *)); -extern const char *fnnalloc __P((const char *, size_t)); -extern int getfnid __P((const char *)); +extern const char *fnalloc(const char *); +extern const char *fnnalloc(const char *, size_t); +extern int getfnid(const char *); -extern void initmem __P((void)); +extern void initmem(void); -extern void *getblk __P((size_t)); -extern void *getlblk __P((int, size_t)); -extern void freeblk __P((void)); -extern void freelblk __P((int)); +extern void *getblk(size_t); +extern void *getlblk(int, size_t); +extern void freeblk(void); +extern void freelblk(int); -extern void *tgetblk __P((size_t)); -extern tnode_t *getnode __P((void)); -extern void tfreeblk __P((void)); -extern struct mbl *tsave __P((void)); -extern void trestor __P((struct mbl *)); +extern void *tgetblk(size_t); +extern tnode_t *getnode(void); +extern void tfreeblk(void); +extern struct mbl *tsave(void); +extern void trestor(struct mbl *); /* * err.c @@ -113,11 +113,13 @@ extern int nerr; extern int sytxerr; extern const char *msgs[]; -extern void error __P((int, ...)); -extern void warning __P((int, ...)); -extern void message __P((int, ...)); -extern int gnuism __P((int, ...)); -extern void lerror __P((const char *, ...)); +extern void msglist(void); +extern void error(int, ...); +extern void warning(int, ...); +extern void message(int, ...); +extern int gnuism(int, ...); +extern void lerror(const char *, ...) + __attribute__((__noreturn__,__format__(__printf__, 1, 2))); /* * decl.c @@ -126,82 +128,82 @@ extern dinfo_t *dcs; extern const char *unnamed; extern int enumval; -extern void initdecl __P((void)); -extern type_t *gettyp __P((tspec_t)); -extern type_t *duptyp __P((const type_t *)); -extern type_t *tduptyp __P((const type_t *)); -extern int incompl __P((type_t *)); -extern void setcompl __P((type_t *, int)); -extern void addscl __P((scl_t)); -extern void addtype __P((type_t *)); -extern void addqual __P((tqual_t)); -extern void pushdecl __P((scl_t)); -extern void popdecl __P((void)); -extern void setasm __P((void)); -extern void clrtyp __P((void)); -extern void deftyp __P((void)); -extern int length __P((type_t *, const char *)); -extern int getbound __P((type_t *)); -extern sym_t *lnklst __P((sym_t *, sym_t *)); -extern void chktyp __P((sym_t *)); -extern sym_t *decl1str __P((sym_t *)); -extern sym_t *bitfield __P((sym_t *, int)); -extern pqinf_t *mergepq __P((pqinf_t *, pqinf_t *)); -extern sym_t *addptr __P((sym_t *, pqinf_t *)); -extern sym_t *addarray __P((sym_t *, int, int)); -extern sym_t *addfunc __P((sym_t *, sym_t *)); -extern void chkfdef __P((sym_t *, int)); -extern sym_t *dname __P((sym_t *)); -extern sym_t *iname __P((sym_t *)); -extern type_t *mktag __P((sym_t *, tspec_t, int, int)); -extern const char *scltoa __P((scl_t)); -extern type_t *compltag __P((type_t *, sym_t *)); -extern sym_t *ename __P((sym_t *, int, int)); -extern void decl1ext __P((sym_t *, int)); -extern void cpuinfo __P((sym_t *, sym_t *)); -extern int isredec __P((sym_t *, int *)); -extern int eqtype __P((type_t *, type_t *, int, int, int *)); -extern void compltyp __P((sym_t *, sym_t *)); -extern sym_t *decl1arg __P((sym_t *, int)); -extern void cluparg __P((void)); -extern void decl1loc __P((sym_t *, int)); -extern sym_t *aname __P((void)); -extern void globclup __P((void)); -extern sym_t *decl1abs __P((sym_t *)); -extern void chksz __P((sym_t *)); -extern void setsflg __P((sym_t *)); -extern void setuflg __P((sym_t *, int, int)); -extern void chkusage __P((dinfo_t *)); -extern void chkusg1 __P((int, sym_t *)); -extern void chkglsyms __P((void)); -extern void prevdecl __P((int, sym_t *)); +extern void initdecl(void); +extern type_t *gettyp(tspec_t); +extern type_t *duptyp(const type_t *); +extern type_t *tduptyp(const type_t *); +extern int incompl(type_t *); +extern void setcompl(type_t *, int); +extern void addscl(scl_t); +extern void addtype(type_t *); +extern void addqual(tqual_t); +extern void pushdecl(scl_t); +extern void popdecl(void); +extern void setasm(void); +extern void clrtyp(void); +extern void deftyp(void); +extern int length(type_t *, const char *); +extern int getbound(type_t *); +extern sym_t *lnklst(sym_t *, sym_t *); +extern void chktyp(sym_t *); +extern sym_t *decl1str(sym_t *); +extern sym_t *bitfield(sym_t *, int); +extern pqinf_t *mergepq(pqinf_t *, pqinf_t *); +extern sym_t *addptr(sym_t *, pqinf_t *); +extern sym_t *addarray(sym_t *, int, int); +extern sym_t *addfunc(sym_t *, sym_t *); +extern void chkfdef(sym_t *, int); +extern sym_t *dname(sym_t *); +extern sym_t *iname(sym_t *); +extern type_t *mktag(sym_t *, tspec_t, int, int); +extern const char *scltoa(scl_t); +extern type_t *compltag(type_t *, sym_t *); +extern sym_t *ename(sym_t *, int, int); +extern void decl1ext(sym_t *, int); +extern void cpuinfo(sym_t *, sym_t *); +extern int isredec(sym_t *, int *); +extern int eqtype(type_t *, type_t *, int, int, int *); +extern void compltyp(sym_t *, sym_t *); +extern sym_t *decl1arg(sym_t *, int); +extern void cluparg(void); +extern void decl1loc(sym_t *, int); +extern sym_t *aname(void); +extern void globclup(void); +extern sym_t *decl1abs(sym_t *); +extern void chksz(sym_t *); +extern void setsflg(sym_t *); +extern void setuflg(sym_t *, int, int); +extern void chkusage(dinfo_t *); +extern void chkusg1(int, sym_t *); +extern void chkglsyms(void); +extern void prevdecl(int, sym_t *); /* * tree.c */ -extern void initmtab __P((void)); -extern type_t *incref __P((type_t *, tspec_t)); -extern type_t *tincref __P((type_t *, tspec_t)); -extern tnode_t *getcnode __P((type_t *, val_t *)); -extern tnode_t *getnnode __P((sym_t *, int)); -extern tnode_t *getsnode __P((strg_t *)); -extern sym_t *strmemb __P((tnode_t *, op_t, sym_t *)); -extern tnode_t *build __P((op_t, tnode_t *, tnode_t *)); -extern tnode_t *cconv __P((tnode_t *)); -extern int typeok __P((op_t, int, tnode_t *, tnode_t *)); -extern tnode_t *promote __P((op_t, int, tnode_t *)); -extern tnode_t *convert __P((op_t, int, type_t *, tnode_t *)); -extern void cvtcon __P((op_t, int, type_t *, val_t *, val_t *)); -extern const char *tyname __P((type_t *)); -extern tnode_t *bldszof __P((type_t *)); -extern tnode_t *cast __P((tnode_t *, type_t *)); -extern tnode_t *funcarg __P((tnode_t *, tnode_t *)); -extern tnode_t *funccall __P((tnode_t *, tnode_t *)); -extern val_t *constant __P((tnode_t *)); -extern void expr __P((tnode_t *, int, int)); -extern void chkmisc __P((tnode_t *, int, int, int, int, int, int)); -extern int conaddr __P((tnode_t *, sym_t **, ptrdiff_t *)); -extern strg_t *catstrg __P((strg_t *, strg_t *)); +extern void initmtab(void); +extern type_t *incref(type_t *, tspec_t); +extern type_t *tincref(type_t *, tspec_t); +extern tnode_t *getcnode(type_t *, val_t *); +extern tnode_t *getnnode(sym_t *, int); +extern tnode_t *getsnode(strg_t *); +extern sym_t *strmemb(tnode_t *, op_t, sym_t *); +extern tnode_t *build(op_t, tnode_t *, tnode_t *); +extern tnode_t *cconv(tnode_t *); +extern int typeok(op_t, int, tnode_t *, tnode_t *); +extern tnode_t *promote(op_t, int, tnode_t *); +extern tnode_t *convert(op_t, int, type_t *, tnode_t *); +extern void cvtcon(op_t, int, type_t *, val_t *, val_t *); +extern const char *tyname(type_t *); +extern tnode_t *bldszof(type_t *); +extern tnode_t *cast(tnode_t *, type_t *); +extern tnode_t *funcarg(tnode_t *, tnode_t *); +extern tnode_t *funccall(tnode_t *, tnode_t *); +extern val_t *constant(tnode_t *); +extern void expr(tnode_t *, int, int); +extern void chkmisc(tnode_t *, int, int, int, int, int, int); +extern int conaddr(tnode_t *, sym_t **, ptrdiff_t *); +extern strg_t *catstrg(strg_t *, strg_t *); /* * func.c @@ -221,42 +223,44 @@ extern pos_t scflpos; extern int ccflg; extern int llibflg; extern int nowarn; +extern int bitfieldtype_ok; extern int plibflg; extern int quadflg; -extern void pushctrl __P((int)); -extern void popctrl __P((int)); -extern void chkreach __P((void)); -extern void funcdef __P((sym_t *)); -extern void funcend __P((void)); -extern void label __P((int, sym_t *, tnode_t *)); -extern void if1 __P((tnode_t *)); -extern void if2 __P((void)); -extern void if3 __P((int)); -extern void switch1 __P((tnode_t *)); -extern void switch2 __P((void)); -extern void while1 __P((tnode_t *)); -extern void while2 __P((void)); -extern void do1 __P((void)); -extern void do2 __P((tnode_t *)); -extern void for1 __P((tnode_t *, tnode_t *, tnode_t *)); -extern void for2 __P((void)); -extern void dogoto __P((sym_t *)); -extern void docont __P((void)); -extern void dobreak __P((void)); -extern void doreturn __P((tnode_t *)); -extern void glclup __P((int)); -extern void argsused __P((int)); -extern void constcond __P((int)); -extern void fallthru __P((int)); -extern void notreach __P((int)); -extern void lintlib __P((int)); -extern void linted __P((int)); -extern void varargs __P((int)); -extern void printflike __P((int)); -extern void scanflike __P((int)); -extern void protolib __P((int)); -extern void longlong __P((int)); +extern void pushctrl(int); +extern void popctrl(int); +extern void chkreach(void); +extern void funcdef(sym_t *); +extern void funcend(void); +extern void label(int, sym_t *, tnode_t *); +extern void if1(tnode_t *); +extern void if2(void); +extern void if3(int); +extern void switch1(tnode_t *); +extern void switch2(void); +extern void while1(tnode_t *); +extern void while2(void); +extern void do1(void); +extern void do2(tnode_t *); +extern void for1(tnode_t *, tnode_t *, tnode_t *); +extern void for2(void); +extern void dogoto(sym_t *); +extern void docont(void); +extern void dobreak(void); +extern void doreturn(tnode_t *); +extern void glclup(int); +extern void argsused(int); +extern void constcond(int); +extern void fallthru(int); +extern void notreach(int); +extern void lintlib(int); +extern void linted(int); +extern void varargs(int); +extern void printflike(int); +extern void scanflike(int); +extern void protolib(int); +extern void longlong(int); +extern void bitfieldtype(int); /* * init.c @@ -265,17 +269,17 @@ extern int initerr; extern sym_t *initsym; extern int startinit; -extern void prepinit __P((void)); -extern void initrbr __P((void)); -extern void initlbr __P((void)); -extern void mkinit __P((tnode_t *)); +extern void prepinit(void); +extern void initrbr(void); +extern void initlbr(void); +extern void mkinit(tnode_t *); /* * emit.c */ -extern void outtype __P((type_t *)); -extern const char *ttos __P((type_t *)); -extern void outsym __P((sym_t *, scl_t, def_t)); -extern void outfdef __P((sym_t *, pos_t *, int, int, sym_t *)); -extern void outcall __P((tnode_t *, int, int)); -extern void outusg __P((sym_t *)); +extern void outtype(type_t *); +extern const char *ttos(type_t *); +extern void outsym(sym_t *, scl_t, def_t); +extern void outfdef(sym_t *, pos_t *, int, int, sym_t *); +extern void outcall(tnode_t *, int, int); +extern void outusg(sym_t *); diff --git a/usr.bin/xlint/lint1/func.c b/usr.bin/xlint/lint1/func.c index 5d3a172..73ade1f 100644 --- a/usr.bin/xlint/lint1/func.c +++ b/usr.bin/xlint/lint1/func.c @@ -1,4 +1,4 @@ -/* $NetBSD: func.c,v 1.7 1995/10/02 17:31:40 jpo Exp $ */ +/* $NetBSD: func.c,v 1.16 2002/01/03 04:25:15 thorpej Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -31,15 +31,16 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static char rcsid[] = "$NetBSD: func.c,v 1.7 1995/10/02 17:31:40 jpo Exp $"; +#include <sys/cdefs.h> +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: func.c,v 1.16 2002/01/03 04:25:15 thorpej Exp $"); #endif #include <stdlib.h> #include <string.h> #include "lint1.h" -#include "y.tab.h" +#include "cgram.h" /* * Contains a pointer to the symbol table entry of the current function @@ -129,6 +130,12 @@ int llibflg; int nowarn; /* + * Nonzero if bitfield type errors are suppressed by a BITFIELDTYPE + * directive. + */ +int bitfieldtype_ok; + +/* * Nonzero if complaints about use of "long long" are suppressed in * the next statement or declaration. */ @@ -138,8 +145,7 @@ int quadflg; * Puts a new element at the top of the stack used for control statements. */ void -pushctrl(env) - int env; +pushctrl(int env) { cstk_t *ci; @@ -153,8 +159,7 @@ pushctrl(env) * Removes the top element of the stack used for control statements. */ void -popctrl(env) - int env; +popctrl(int env) { cstk_t *ci; clst_t *cl; @@ -179,7 +184,7 @@ popctrl(env) * Prints a warning if a statement cannot be reached. */ void -chkreach() +chkreach(void) { if (!reached && !rchflg) { /* statement not reached */ @@ -199,8 +204,7 @@ chkreach() * redeclaration etc.. */ void -funcdef(fsym) - sym_t *fsym; +funcdef(sym_t *fsym) { int n, warn; sym_t *arg, *sym, *rdsym; @@ -322,7 +326,7 @@ funcdef(fsym) } if (dcs->d_notyp) - /* return value is implizitly declared to be int */ + /* return value is implicitly declared to be int */ fsym->s_rimpl = 1; reached = 1; @@ -332,7 +336,7 @@ funcdef(fsym) * Called at the end of a function definition. */ void -funcend() +funcend(void) { sym_t *arg; int n; @@ -368,7 +372,7 @@ funcend() /* * write the information about the function definition to the * output file - * inline functions explicitely declared extern are written as + * inline functions explicitly declared extern are written as * declarations only. */ if (dcs->d_scl == EXTERN && funcsym->s_inline) { @@ -398,14 +402,12 @@ funcend() * tn expression if typ == T_CASE */ void -label(typ, sym, tn) - int typ; - sym_t *sym; - tnode_t *tn; +label(int typ, sym_t *sym, tnode_t *tn) { cstk_t *ci; clst_t *cl; - val_t *v, *nv; + val_t *v; + val_t nv; tspec_t t; switch (typ) { @@ -422,7 +424,8 @@ label(typ, sym, tn) case T_CASE: /* find the stack entry for the innermost switch statement */ - for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt) ; + for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt) + continue; if (ci == NULL) { /* case not in switch */ @@ -462,28 +465,28 @@ label(typ, sym, tn) * to the type of the switch expression */ v = constant(tn); - nv = xcalloc(1, sizeof (val_t)); - cvtcon(CASE, 0, ci->c_swtype, nv, v); + (void) memset(&nv, 0, sizeof nv); + cvtcon(CASE, 0, ci->c_swtype, &nv, v); free(v); /* look if we had this value already */ for (cl = ci->c_clst; cl != NULL; cl = cl->cl_nxt) { - if (cl->cl_val.v_quad == nv->v_quad) + if (cl->cl_val.v_quad == nv.v_quad) break; } - if (cl != NULL && isutyp(nv->v_tspec)) { + if (cl != NULL && isutyp(nv.v_tspec)) { /* duplicate case in switch, %lu */ - error(200, (u_long)nv->v_quad); + error(200, (u_long)nv.v_quad); } else if (cl != NULL) { /* duplicate case in switch, %ld */ - error(199, (long)nv->v_quad); + error(199, (long)nv.v_quad); } else { /* * append the value to the list of * case values */ cl = xcalloc(1, sizeof (clst_t)); - STRUCT_ASSIGN(cl->cl_val, *nv); + STRUCT_ASSIGN(cl->cl_val, nv); cl->cl_nxt = ci->c_clst; ci->c_clst = cl; } @@ -494,7 +497,8 @@ label(typ, sym, tn) case T_DEFAULT: /* find the stack entry for the innermost switch statement */ - for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt) ; + for (ci = cstk; ci != NULL && !ci->c_switch; ci = ci->c_nxt) + continue; if (ci == NULL) { /* default outside switch */ @@ -519,9 +523,9 @@ label(typ, sym, tn) * T_IF T_LPARN expr T_RPARN */ void -if1(tn) - tnode_t *tn; +if1(tnode_t *tn) { + if (tn != NULL) tn = cconv(tn); if (tn != NULL) @@ -535,8 +539,9 @@ if1(tn) * if_without_else T_ELSE */ void -if2() +if2(void) { + cstk->c_rchif = reached ? 1 : 0; reached = 1; } @@ -546,9 +551,9 @@ if2() * if_without_else T_ELSE stmnt */ void -if3(els) - int els; +if3(int els) { + if (els) { reached |= cstk->c_rchif; } else { @@ -561,8 +566,7 @@ if3(els) * T_SWITCH T_LPARN expr T_RPARN */ void -switch1(tn) - tnode_t *tn; +switch1(tnode_t *tn) { tspec_t t; type_t *tp; @@ -613,9 +617,9 @@ switch1(tn) * switch_expr stmnt */ void -switch2() +switch2(void) { - int nenum, nclab; + int nenum = 0, nclab = 0; sym_t *esym; clst_t *cl; @@ -668,9 +672,9 @@ switch2() * T_WHILE T_LPARN expr T_RPARN */ void -while1(tn) - tnode_t *tn; +while1(tnode_t *tn) { + if (!reached) { /* loop not entered at top */ warning(207); @@ -705,8 +709,9 @@ while1(tn) * while_expr error */ void -while2() +while2(void) { + /* * The end of the loop can be reached if it is no endless loop * or there was a break statement which was reached. @@ -721,8 +726,9 @@ while2() * T_DO */ void -do1() +do1(void) { + if (!reached) { /* loop not entered at top */ warning(207); @@ -738,9 +744,9 @@ do1() * do error */ void -do2(tn) - tnode_t *tn; +do2(tnode_t *tn) { + /* * If there was a continue statement the expression controlling the * loop is reached. @@ -782,9 +788,9 @@ do2(tn) * T_FOR T_LPARN opt_expr T_SEMI opt_expr T_SEMI opt_expr T_RPARN */ void -for1(tn1, tn2, tn3) - tnode_t *tn1, *tn2, *tn3; +for1(tnode_t *tn1, tnode_t *tn2, tnode_t *tn3) { + /* * If there is no initialisation expression it is possible that * it is intended not to enter the loop at top. @@ -843,7 +849,7 @@ for1(tn1, tn2, tn3) * for_exprs error */ void -for2() +for2(void) { pos_t cpos, cspos; tnode_t *tn3; @@ -888,9 +894,9 @@ for2() * T_GOTO error T_SEMI */ void -dogoto(lab) - sym_t *lab; +dogoto(sym_t *lab) { + setuflg(lab, 0, 0); chkreach(); @@ -902,7 +908,7 @@ dogoto(lab) * T_BREAK T_SEMI */ void -dobreak() +dobreak(void) { cstk_t *ci; @@ -928,11 +934,12 @@ dobreak() * T_CONTINUE T_SEMI */ void -docont() +docont(void) { cstk_t *ci; - for (ci = cstk; ci != NULL && !ci->c_loop; ci = ci->c_nxt) ; + for (ci = cstk; ci != NULL && !ci->c_loop; ci = ci->c_nxt) + continue; if (ci == NULL) { /* continue outside loop */ @@ -951,14 +958,14 @@ docont() * T_RETURN expr T_SEMI */ void -doreturn(tn) - tnode_t *tn; +doreturn(tnode_t *tn) { tnode_t *ln, *rn; cstk_t *ci; op_t op; - for (ci = cstk; ci->c_nxt != NULL; ci = ci->c_nxt) ; + for (ci = cstk; ci->c_nxt != NULL; ci = ci->c_nxt) + continue; if (tn != NULL) { ci->c_retval = 1; @@ -1020,8 +1027,7 @@ doreturn(tn) * Especially remove informations about unused lint comments. */ void -glclup(silent) - int silent; +glclup(int silent) { pos_t cpos; @@ -1072,9 +1078,9 @@ glclup(silent) * for usage. A missing argument is taken to be 0. */ void -argsused(n) - int n; +argsused(int n) { + if (n == -1) n = 0; @@ -1098,9 +1104,9 @@ argsused(n) * to the function definition. A missing argument is taken to be 0. */ void -varargs(n) - int n; +varargs(int n) { + if (n == -1) n = 0; @@ -1124,9 +1130,9 @@ varargs(n) * used the check the types of remaining arguments. */ void -printflike(n) - int n; +printflike(int n) { + if (n == -1) n = 0; @@ -1150,9 +1156,9 @@ printflike(n) * used the check the types of remaining arguments. */ void -scanflike(n) - int n; +scanflike(int n) { + if (n == -1) n = 0; @@ -1175,9 +1181,9 @@ scanflike(n) */ /* ARGSUSED */ void -constcond(n) - int n; +constcond(int n) { + ccflg = 1; } @@ -1187,9 +1193,9 @@ constcond(n) */ /* ARGSUSED */ void -fallthru(n) - int n; +fallthru(int n) { + ftflg = 1; } @@ -1199,18 +1205,18 @@ fallthru(n) */ /* ARGSUSED */ void -notreach(n) - int n; +notreach(int n) { + reached = 0; rchflg = 1; } /* ARGSUSED */ void -lintlib(n) - int n; +lintlib(int n) { + if (dcs->d_ctx != EXTERN) { /* must be outside function: ** %s ** */ warning(280, "LINTLIBRARY"); @@ -1225,21 +1231,39 @@ lintlib(n) */ /* ARGSUSED */ void -linted(n) - int n; +linted(int n) { + +#ifdef DEBUG + printf("%s, %d: nowarn = 1\n", curr_pos.p_file, curr_pos.p_line); +#endif nowarn = 1; } /* + * Suppress bitfield type errors on the current line. + */ +/* ARGSUSED */ +void +bitfieldtype(int n) +{ + +#ifdef DEBUG + printf("%s, %d: bitfieldtype_ok = 1\n", curr_pos.p_file, + curr_pos.p_line); +#endif + bitfieldtype_ok = 1; +} + +/* * PROTOTLIB in conjunction with LINTLIBRARY can be used to handle * prototypes like function definitions. This is done if the argument * to PROTOLIB is nonzero. Otherwise prototypes are handled normaly. */ void -protolib(n) - int n; +protolib(int n) { + if (dcs->d_ctx != EXTERN) { /* must be outside function: ** %s ** */ warning(280, "PROTOLIB"); @@ -1254,8 +1278,8 @@ protolib(n) */ /* ARGSUSED */ void -longlong(n) - int n; +longlong(int n) { + quadflg = 1; } diff --git a/usr.bin/xlint/lint1/init.c b/usr.bin/xlint/lint1/init.c index dbd216b..0fd0383 100644 --- a/usr.bin/xlint/lint1/init.c +++ b/usr.bin/xlint/lint1/init.c @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.4 1995/10/02 17:21:37 jpo Exp $ */ +/* $NetBSD: init.c,v 1.9 2001/09/18 18:15:54 wiz Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -31,8 +31,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static char rcsid[] = "$NetBSD: init.c,v 1.4 1995/10/02 17:21:37 jpo Exp $"; +#include <sys/cdefs.h> +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: init.c,v 1.9 2001/09/18 18:15:54 wiz Exp $"); #endif #include <stdlib.h> @@ -40,7 +41,7 @@ static char rcsid[] = "$NetBSD: init.c,v 1.4 1995/10/02 17:21:37 jpo Exp $"; #include "lint1.h" /* - * initerr is set as soon as a fatal error occured in an initialisation. + * initerr is set as soon as a fatal error occurred in an initialisation. * The effect is that the rest of the initialisation is ignored (parsed * by yacc, expression trees built, but no initialisation takes place). */ @@ -53,12 +54,12 @@ sym_t *initsym; istk_t *initstk; -static void popi2 __P((void)); -static void popinit __P((int)); -static void pushinit __P((void)); -static void testinit __P((void)); -static void nextinit __P((int)); -static int strginit __P((tnode_t *)); +static void popi2(void); +static void popinit(int); +static void pushinit(void); +static void testinit(void); +static void nextinit(int); +static int strginit(tnode_t *); /* @@ -66,7 +67,7 @@ static int strginit __P((tnode_t *)); * which is to be initialized on it. */ void -prepinit() +prepinit(void) { istk_t *istk; @@ -93,7 +94,7 @@ prepinit() } static void -popi2() +popi2(void) { istk_t *istk; sym_t *m; @@ -124,9 +125,9 @@ popi2() } static void -popinit(brace) - int brace; +popinit(int brace) { + if (brace) { /* * Take all entries, including the first which requires @@ -150,7 +151,7 @@ popinit(brace) } static void -pushinit() +pushinit(void) { istk_t *istk; int cnt; @@ -235,7 +236,7 @@ pushinit() } static void -testinit() +testinit(void) { istk_t *istk; @@ -266,9 +267,9 @@ testinit() } static void -nextinit(brace) - int brace; +nextinit(int brace) { + if (!brace) { if (initstk->i_type == NULL && !issclt(initstk->i_subt->t_tspec)) { @@ -303,8 +304,9 @@ nextinit(brace) } void -initlbr() +initlbr(void) { + if (initerr) return; @@ -325,8 +327,9 @@ initlbr() } void -initrbr() +initrbr(void) { + if (initerr) return; @@ -334,8 +337,7 @@ initrbr() } void -mkinit(tn) - tnode_t *tn; +mkinit(tnode_t *tn) { ptrdiff_t offs; sym_t *sym; @@ -351,7 +353,7 @@ mkinit(tn) /* * Do not test for automatic aggregat initialisation. If the - * initalizer starts with a brace we have the warning already. + * initializer starts with a brace we have the warning already. * If not, an error will be printed that the initializer must * be enclosed by braces. */ @@ -412,7 +414,7 @@ mkinit(tn) tmem = tsave(); expr(tn, 1, 0); trestor(tmem); - + if (isityp(lt) && ln->tn_type->t_isfield && !isityp(rt)) { /* * Bit-fields can be initialized in trad. C only by integer @@ -446,8 +448,7 @@ mkinit(tn) static int -strginit(tn) - tnode_t *tn; +strginit(tnode_t *tn) { tspec_t t; istk_t *istk; diff --git a/usr.bin/xlint/lint1/lint1.h b/usr.bin/xlint/lint1/lint1.h index 019c98d..278019e 100644 --- a/usr.bin/xlint/lint1/lint1.h +++ b/usr.bin/xlint/lint1/lint1.h @@ -1,6 +1,7 @@ -/* $NetBSD: lint1.h,v 1.6 1995/10/02 17:31:41 jpo Exp $ */ +/* $NetBSD: lint1.h,v 1.12 2002/01/31 19:33:27 tv Exp $ */ /* + * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. * Copyright (c) 1994, 1995 Jochen Pohl * All Rights Reserved. * @@ -34,14 +35,29 @@ #include "lint.h" #include "op.h" +/* XXX - works for most systems, but the whole ALIGN thing needs to go away */ +#ifndef ALIGN +#define ALIGN(x) (((x) + 7) & ~7) +#endif + /* * Describes the position of a declaration or anything else. */ typedef struct { int p_line; const char *p_file; + int p_uniq; /* uniquifier */ } pos_t; +/* Copies curr_pos, keeping things unique. */ +#define UNIQUE_CURR_POS(pos) \ + do { \ + STRUCT_ASSIGN((pos), curr_pos); \ + curr_pos.p_uniq++; \ + if (curr_pos.p_file == csrc_pos.p_file) \ + csrc_pos.p_uniq++; \ + } while (0) + /* * Strings cannot be referenced to simply by a pointer to its first * char. This is because strings can contain NUL characters other than the @@ -76,7 +92,7 @@ typedef struct { int v_ansiu; /* set if an integer constant is unsigned in ANSI C */ union { - quad_t _v_quad; /* integers */ + int64_t _v_quad; /* integers */ ldbl_t _v_ldbl; /* floats */ } v_u; } val_t; @@ -132,11 +148,11 @@ typedef struct type { str_t *_t_str; /* struct/union tag */ enum_t *_t_enum; /* enum tag */ struct sym *_t_args; /* arguments (if t_proto) */ - struct { - u_int _t_flen : 8; /* length of bit-field */ - u_int _t_foffs : 24; /* offset of bit-field */ - } _t_u; } t_u; + struct { + u_int _t_flen : 8; /* length of bit-field */ + u_int _t_foffs : 24; /* offset of bit-field */ + } t_b; struct type *t_subt; /* element type (arrays), return value (functions), or type pointer points to */ } type_t; @@ -146,8 +162,8 @@ typedef struct type { #define t_field t_u._t_field #define t_enum t_u._t_enum #define t_args t_u._t_args -#define t_flen t_u._t_u._t_flen -#define t_foffs t_u._t_u._t_foffs +#define t_flen t_b._t_flen +#define t_foffs t_b._t_foffs /* * types of symbols @@ -187,6 +203,7 @@ typedef enum { */ typedef struct sym { const char *s_name; /* name */ + const char *s_rename; /* renamed symbol's given name */ pos_t s_dpos; /* position of last (prototype)definition, prototypedeclaration, no-prototype-def., tentative definition or declaration, @@ -378,3 +395,20 @@ typedef struct cstk { } cstk_t; #include "externs1.h" + +#define ERR_SETSIZE 1024 +#define __NERRBITS (sizeof(unsigned int)) + +typedef struct err_set { + unsigned int errs_bits[(ERR_SETSIZE + __NERRBITS-1) / __NERRBITS]; +} err_set; + +#define ERR_SET(n, p) \ + ((p)->errs_bits[(n)/__NERRBITS] |= (1 << ((n) % __NERRBITS))) +#define ERR_CLR(n, p) \ + ((p)->errs_bits[(n)/__NERRBITS] &= ~(1 << ((n) % __NERRBITS))) +#define ERR_ISSET(n, p) \ + ((p)->errs_bits[(n)/__NERRBITS] & (1 << ((n) % __NERRBITS))) +#define ERR_ZERO(p) (void)memset((p), 0, sizeof(*(p))) + +extern err_set msgset; diff --git a/usr.bin/xlint/lint1/main1.c b/usr.bin/xlint/lint1/main1.c index 0add206..f04d817 100644 --- a/usr.bin/xlint/lint1/main1.c +++ b/usr.bin/xlint/lint1/main1.c @@ -1,4 +1,4 @@ -/* $NetBSD: main1.c,v 1.3 1995/10/02 17:29:56 jpo Exp $ */ +/* $NetBSD: main1.c,v 1.11 2002/01/29 02:43:38 tv Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -31,14 +31,18 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static char rcsid[] = "$NetBSD: main1.c,v 1.3 1995/10/02 17:29:56 jpo Exp $"; +#include <sys/cdefs.h> +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: main1.c,v 1.11 2002/01/29 02:43:38 tv Exp $"); #endif +#include <sys/types.h> #include <stdio.h> +#include <string.h> #include <stdlib.h> #include <unistd.h> -#include <err.h> +#include <errno.h> +#include <limits.h> #include "lint1.h" @@ -49,7 +53,7 @@ int yflag; * Print warnings if an assignment of an integertype to another integertype * causes an implizit narrowing conversion. If aflag is 1, these warnings * are printed only if the source type is at least as wide as long. If aflag - * is greather then 1, they are always printed. + * is greater than 1, they are always printed. */ int aflag; @@ -71,6 +75,9 @@ int Fflag; /* Enable some extensions of gcc */ int gflag; +/* Treat warnings as errors */ +int wflag; + /* * Apply a number of heuristic tests to attempt to intuit bugs, improve * style, and reduce waste. @@ -104,16 +111,22 @@ int vflag = 1; /* Complain about structures which are never defined. */ int zflag = 1; -static void usage __P((void)); +err_set msgset; + +static void usage(void); + +int main(int, char *[]); int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { int c; + char *ptr; - while ((c = getopt(argc, argv, "abcdeghprstuvyzF")) != -1) { + setprogname(argv[0]); + + ERR_ZERO(&msgset); + while ((c = getopt(argc, argv, "abcdeghmprstuvwyzFX:")) != -1) { switch (c) { case 'a': aflag++; break; case 'b': bflag = 1; break; @@ -128,10 +141,35 @@ main(argc, argv) case 's': sflag = 1; break; case 't': tflag = 1; break; case 'u': uflag = 0; break; + case 'w': wflag = 1; break; case 'v': vflag = 0; break; case 'y': yflag = 1; break; case 'z': zflag = 0; break; - case '?': usage(); + + case 'm': + msglist(); + return(0); + + case 'X': + for (ptr = strtok(optarg, ","); ptr; + ptr = strtok(NULL, ",")) { + char *eptr; + long msg = strtol(ptr, &eptr, 0); + if ((msg == LONG_MIN || msg == LONG_MAX) && + errno == ERANGE) + err(1, "invalid error message id '%s'", + ptr); + if (*eptr || ptr == eptr || msg < 0 || + msg >= ERR_SETSIZE) + errx(1, "invalid error message id '%s'", + ptr); + ERR_SET(msg, &msgset); + } + break; + case '?': + default: + usage(); + break; } } argc -= optind; @@ -168,14 +206,16 @@ main(argc, argv) } static void -usage() +usage(void) { - (void)fprintf(stderr, "usage: lint1 [-abcdeghprstuvyzF] src dest\n"); + (void)fprintf(stderr, + "Usage: %s [-abcdeghmprstuvwyzF] [-X <id>[,<id>]... src dest\n", + getprogname()); exit(1); } - + void -norecover() +norecover(void) { /* cannot recover from previous errors */ error(224); diff --git a/usr.bin/xlint/lint1/makeman b/usr.bin/xlint/lint1/makeman new file mode 100644 index 0000000..721e825 --- /dev/null +++ b/usr.bin/xlint/lint1/makeman @@ -0,0 +1,94 @@ +#!/bin/sh +# $NetBSD$ +# +# Copyright (c) 2000 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Christos Zoulas. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. All advertising materials mentioning features or use of this software +# must display the following acknowledgement: +# This product includes software developed by the NetBSD +# Foundation, Inc. and its contributors. +# 4. Neither the name of The NetBSD Foundation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + + +cat << \__EOF +.\" $NetBSD$ +.\" +.\" Copyright (c) 2000 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Christos Zoulas. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the NetBSD +.\" Foundation, Inc. and its contributors. +.\" 4. Neither the name of The NetBSD Foundation nor the names of its +.\" contributors may be used to endorse or promote products derived +.\" from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.Dd July 5, 2000 +.Dt LINT 7 +.Os +.Sh NAME +.Nm lint +.Nd Lint error message list +.Sh DESCRIPTION +The following is a list of message id's and messages produced by +.Xr lint 1 . +It is intended to be used with +.Fl X +flag of +.Xr lint 1 . +.Pp +.Bd -ragged -offset indent -compact +.Bl -column "Id# Message" +__EOF +"$@" | sed -e 's/^/.It /' -e 's/\\/\\e/g' -e "s/'/\\'/" +echo ".El" +echo ".Ed" diff --git a/usr.bin/xlint/lint1/mem1.c b/usr.bin/xlint/lint1/mem1.c index df880b1..4e21f07 100644 --- a/usr.bin/xlint/lint1/mem1.c +++ b/usr.bin/xlint/lint1/mem1.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem1.c,v 1.2 1995/07/03 21:24:25 cgd Exp $ */ +/* $NetBSD: mem1.c,v 1.6 2002/01/29 02:43:39 tv Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -31,8 +31,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static char rcsid[] = "$NetBSD: mem1.c,v 1.2 1995/07/03 21:24:25 cgd Exp $"; +#include <sys/cdefs.h> +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: mem1.c,v 1.6 2002/01/29 02:43:39 tv Exp $"); #endif #include <sys/types.h> @@ -41,7 +42,6 @@ static char rcsid[] = "$NetBSD: mem1.c,v 1.2 1995/07/03 21:24:25 cgd Exp $"; #include <stdlib.h> #include <string.h> #include <unistd.h> -#include <err.h> #include "lint1.h" @@ -57,15 +57,13 @@ typedef struct fn { static fn_t *fnames; -static fn_t *srchfn __P((const char *, size_t)); +static fn_t *srchfn(const char *, size_t); /* * Look for a Filename of length l. */ static fn_t * -srchfn(s, len) - const char *s; - size_t len; +srchfn(const char *s, size_t len) { fn_t *fn; @@ -80,16 +78,14 @@ srchfn(s, len) * Return a shared string for filename s. */ const char * -fnalloc(s) - const char *s; +fnalloc(const char *s) { + return (s != NULL ? fnnalloc(s, strlen(s)) : NULL); } const char * -fnnalloc(s, len) - const char *s; - size_t len; +fnnalloc(const char *s, size_t len) { fn_t *fn; @@ -121,8 +117,7 @@ fnnalloc(s, len) * Get id of a filename. */ int -getfnid(s) - const char *s; +getfnid(const char *s) { fn_t *fn; @@ -163,12 +158,12 @@ static mbl_t *frmblks; /* length of new allocated memory blocks */ static size_t mblklen; -static void *xgetblk __P((mbl_t **, size_t)); -static void xfreeblk __P((mbl_t **)); -static mbl_t *xnewblk __P((void)); +static void *xgetblk(mbl_t **, size_t); +static void xfreeblk(mbl_t **); +static mbl_t *xnewblk(void); static mbl_t * -xnewblk() +xnewblk(void) { mbl_t *mb; int prot, flags; @@ -182,8 +177,6 @@ xnewblk() mb->blk = mmap(NULL, mblklen, prot, flags, -1, (off_t)0); if (mb->blk == (void *)-1) err(1, "can't map memory"); - if (ALIGN((u_long)mb->blk) != (u_long)mb->blk) - errx(1, "mapped address is not aligned"); mb->size = mblklen; @@ -199,9 +192,7 @@ xnewblk() * zero'd in xfreeblk(). */ static void * -xgetblk(mbp, s) - mbl_t **mbp; - size_t s; +xgetblk(mbl_t **mbp, size_t s) { mbl_t *mb; void *p; @@ -230,8 +221,7 @@ xgetblk(mbp, s) * used memory to zero. */ static void -xfreeblk(fmbp) - mbl_t **fmbp; +xfreeblk(mbl_t **fmbp) { mbl_t *mb; @@ -244,7 +234,7 @@ xfreeblk(fmbp) } void -initmem() +initmem(void) { int pgsz; @@ -254,15 +244,14 @@ initmem() mblks = xcalloc(nmblks = ML_INC, sizeof (mbl_t *)); } - + /* * Allocate memory associated with level l. */ void * -getlblk(l, s) - int l; - size_t s; +getlblk(int l, size_t s) { + while (l >= nmblks) { mblks = xrealloc(mblks, (nmblks + ML_INC) * sizeof (mbl_t *)); (void)memset(&mblks[nmblks], 0, ML_INC * sizeof (mbl_t *)); @@ -272,9 +261,9 @@ getlblk(l, s) } void * -getblk(s) - size_t s; +getblk(size_t s) { + return (getlblk(mblklev, s)); } @@ -282,15 +271,16 @@ getblk(s) * Free all memory associated with level l. */ void -freelblk(l) - int l; +freelblk(int l) { + xfreeblk(&mblks[l]); } void -freeblk() +freeblk(void) { + freelblk(mblklev); } @@ -301,9 +291,9 @@ freeblk() static mbl_t *tmblk; void * -tgetblk(s) - size_t s; +tgetblk(size_t s) { + return (xgetblk(&tmblk, s)); } @@ -311,17 +301,19 @@ tgetblk(s) * Get memory for a new tree node. */ tnode_t * -getnode() +getnode(void) { + return (tgetblk(sizeof (tnode_t))); } /* - * Free all memory which is allocated by the the current expression. + * Free all memory which is allocated by the current expression. */ void -tfreeblk() +tfreeblk(void) { + xfreeblk(&tmblk); } @@ -331,7 +323,7 @@ tfreeblk() * used to restore the memory. */ mbl_t * -tsave() +tsave(void) { mbl_t *tmem; @@ -346,9 +338,9 @@ tsave() * tfreeblk() frees the restored memory. */ void -trestor(tmem) - mbl_t *tmem; +trestor(mbl_t *tmem) { + tfreeblk(); if (tmblk != NULL) { free(tmblk->blk); diff --git a/usr.bin/xlint/lint1/op.h b/usr.bin/xlint/lint1/op.h index 11f05a5..042195a 100644 --- a/usr.bin/xlint/lint1/op.h +++ b/usr.bin/xlint/lint1/op.h @@ -48,7 +48,7 @@ typedef struct { u_int m_tlansiu : 1; /* warning if left op. is unsign. in ANSI C */ u_int m_transiu : 1; /* warning if right op. is unsign. in ANSI C */ u_int m_tpconf : 1; /* test possible precedence confusion */ - u_int m_comp : 1; /* op. performs comparision */ + u_int m_comp : 1; /* op. performs comparison */ u_int m_enumop : 1; /* valid operation on enums */ u_int m_badeop : 1; /* dubious operation on enums */ u_int m_eqwarn : 1; /* warning if on operand stems from == */ diff --git a/usr.bin/xlint/lint1/scan.l b/usr.bin/xlint/lint1/scan.l index 5e23c6b..bd18f73 100644 --- a/usr.bin/xlint/lint1/scan.l +++ b/usr.bin/xlint/lint1/scan.l @@ -1,7 +1,8 @@ %{ -/* $NetBSD: scan.l,v 1.8 1995/10/23 13:38:51 jpo Exp $ */ +/* $NetBSD: scan.l,v 1.26 2002/01/31 22:30:21 tv Exp $ */ /* + * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. * Copyright (c) 1994, 1995 Jochen Pohl * All Rights Reserved. * @@ -32,8 +33,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static char rcsid[] = "$NetBSD: scan.l,v 1.8 1995/10/23 13:38:51 jpo Exp $"; +#include <sys/cdefs.h> +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: scan.l,v 1.26 2002/01/31 22:30:21 tv Exp $"); #endif #include <stdlib.h> @@ -43,44 +45,42 @@ static char rcsid[] = "$NetBSD: scan.l,v 1.8 1995/10/23 13:38:51 jpo Exp $"; #include <ctype.h> #include <errno.h> #include <math.h> -#include <err.h> #include "lint1.h" -#include "y.tab.h" +#include "cgram.h" #define CHAR_MASK (~(~0 << CHAR_BIT)) - -/* XXX declaration of strtouq() is missing in stdlib.h ? */ -extern u_quad_t strtouq __P((const char *, char **, int)); +#define YY_NO_UNPUT /* Current position (its also updated when an included file is parsed) */ -pos_t curr_pos = { 1, "" }; +pos_t curr_pos = { 1, "", 0 }; /* * Current position in C source (not updated when an included file is * parsed). */ -pos_t csrc_pos = { 1, "" }; - -static void incline __P((void)); -static void badchar __P((int)); -static sbuf_t *allocsb __P((void)); -static void freesb __P((sbuf_t *)); -static int inpc __P((void)); -static int hash __P((const char *)); -static sym_t *search __P((sbuf_t *)); -static int name __P((void)); -static int keyw __P((sym_t *)); -static int icon __P((int)); -static int fcon __P((void)); -static int operator __P((int, op_t)); -static int ccon __P((void)); -static int wccon __P((void)); -static int getescc __P((int)); -static void directive __P((void)); -static void comment __P((void)); -static int string __P((void)); -static int wcstrg __P((void)); +pos_t csrc_pos = { 1, "", 0 }; + +static void incline(void); +static void badchar(int); +static sbuf_t *allocsb(void); +static void freesb(sbuf_t *); +static int inpc(void); +static int hash(const char *); +static sym_t *search(sbuf_t *); +static int name(void); +static int keyw(sym_t *); +static int icon(int); +static int fcon(void); +static int operator(int, op_t); +static int ccon(void); +static int wccon(void); +static int getescc(int); +static void directive(void); +static void comment(void); +static void slashslashcomment(void); +static int string(void); +static int wcstrg(void); %} @@ -154,22 +154,26 @@ EX ([eE][+-]?[0-9]+) \n incline(); \t|" "|\f|\v ; "/*" comment(); +"//" slashslashcomment(); . badchar(yytext[0]); %% static void -incline() +incline(void) { curr_pos.p_line++; - if (curr_pos.p_file == csrc_pos.p_file) + curr_pos.p_uniq = 0; + if (curr_pos.p_file == csrc_pos.p_file) { csrc_pos.p_line++; + csrc_pos.p_uniq = 0; + } } static void -badchar(c) - int c; +badchar(int c) { + /* unknown character \%o */ error(250, c); } @@ -212,6 +216,7 @@ static struct kwtab { { "__inline__", T_SCLASS, INLINE, 0, 0, 0, 0 }, { "__inline", T_SCLASS, INLINE, 0, 0, 0, 0 }, { "int", T_TYPE, 0, INT, 0, 0, 0 }, + { "__symbolrename", T_SYMBOLRENAME, 0, 0, 0, 0, 0 }, { "long", T_TYPE, 0, LONG, 0, 0, 0 }, { "register", T_SCLASS, REG, 0, 0, 0, 0 }, { "return", T_RETURN, 0, 0, 0, 0, 0 }, @@ -238,13 +243,13 @@ static struct kwtab { static sym_t *symtab[HSHSIZ1]; /* bit i of the entry with index i is set */ -u_quad_t qbmasks[sizeof(u_quad_t) * CHAR_BIT]; +uint64_t qbmasks[sizeof(uint64_t) * CHAR_BIT]; /* least significant i bits are set in the entry with index i */ -u_quad_t qlmasks[sizeof(u_quad_t) * CHAR_BIT + 1]; +uint64_t qlmasks[sizeof(uint64_t) * CHAR_BIT + 1]; /* least significant i bits are not set in the entry with index i */ -u_quad_t qumasks[sizeof(u_quad_t) * CHAR_BIT + 1]; +uint64_t qumasks[sizeof(uint64_t) * CHAR_BIT + 1]; /* free list for sbuf structures */ static sbuf_t *sbfrlst; @@ -258,12 +263,12 @@ symt_t symtyp; * in a extra table for each name we found. */ void -initscan() +initscan(void) { struct kwtab *kw; sym_t *sym; int h, i; - u_quad_t uq; + uint64_t uq; for (kw = kwtab; kw->kw_name != NULL; kw++) { if (kw->kw_stdc && tflag) @@ -288,21 +293,21 @@ initscan() } /* initialize bit-masks for quads */ - for (i = 0; i < sizeof (u_quad_t) * CHAR_BIT; i++) { - qbmasks[i] = (u_quad_t)1 << i; - uq = ~(u_quad_t)0 << i; + for (i = 0; i < sizeof (uint64_t) * CHAR_BIT; i++) { + qbmasks[i] = (uint64_t)1 << i; + uq = ~(uint64_t)0 << i; qumasks[i] = uq; qlmasks[i] = ~uq; } qumasks[i] = 0; - qlmasks[i] = ~(u_quad_t)0; + qlmasks[i] = ~(uint64_t)0; } /* * Get a free sbuf structure, if possible from the free list */ static sbuf_t * -allocsb() +allocsb(void) { sbuf_t *sb; @@ -319,9 +324,9 @@ allocsb() * Put a sbuf structure to the free list */ static void -freesb(sb) - sbuf_t *sb; +freesb(sbuf_t *sb) { + sb->sb_nxt = sbfrlst; sbfrlst = sb; } @@ -331,7 +336,7 @@ freesb(sb) * Increment line count(s) if necessary. */ static int -inpc() +inpc(void) { int c; @@ -341,8 +346,7 @@ inpc() } static int -hash(s) - const char *s; +hash(const char *s) { u_int v; const u_char *us; @@ -371,7 +375,7 @@ hash(s) * to the symbol table entry. */ static int -name() +name(void) { char *s; sbuf_t *sb; @@ -409,8 +413,7 @@ name() } static sym_t * -search(sb) - sbuf_t *sb; +search(sbuf_t *sb) { sym_t *sym; @@ -423,10 +426,9 @@ search(sb) return (NULL); } - + static int -keyw(sym) - sym_t *sym; +keyw(sym_t *sym) { int t; @@ -445,16 +447,15 @@ keyw(sym) * The value is returned in yylval. icon() (and yylex()) returns T_CON. */ static int -icon(base) - int base; +icon(int base) { int l_suffix, u_suffix; int len; const char *cp; char c, *eptr; tspec_t typ; - u_long ul; - u_quad_t uq; + u_long ul = 0; + uint64_t uq = 0; int ansiu; static tspec_t contypes[2][3] = { { INT, LONG, QUAD }, @@ -509,7 +510,7 @@ icon(base) warning(252); /* - * If the value is to big for the current type, we must choose + * If the value is to big for the current type, we must choose * another type. */ ansiu = 0; @@ -555,21 +556,45 @@ icon(base) } break; /* LINTED (enumeration values not handled in switch) */ + case STRUCT: + case VOID: + case LDOUBLE: + case FUNC: + case ARRAY: + case PTR: + case ENUM: + case UNION: + case SIGNED: + case NOTSPEC: + case DOUBLE: + case FLOAT: + case UQUAD: + case ULONG: + case USHORT: + case SHORT: + case UCHAR: + case SCHAR: + case CHAR: + case UNSIGN: + break; + + case NTSPEC: /* this value unused */ + break; } if (typ != QUAD && typ != UQUAD) { if (isutyp(typ)) { uq = ul; } else { - uq = (quad_t)(long)ul; + uq = (int64_t)(long)ul; } } - uq = (u_quad_t)xsign((quad_t)uq, typ, -1); + uq = (uint64_t)xsign((int64_t)uq, typ, -1); (yylval.y_val = xcalloc(1, sizeof (val_t)))->v_tspec = typ; yylval.y_val->v_ansiu = ansiu; - yylval.y_val->v_quad = (quad_t)uq; + yylval.y_val->v_quad = (int64_t)uq; return (T_CON); } @@ -581,22 +606,18 @@ icon(base) * to the width of type t. */ int -sign(q, t, len) - quad_t q; - tspec_t t; - int len; +sign(int64_t q, tspec_t t, int len) { + if (t == PTR || isutyp(t)) return (0); return (msb(q, t, len)); } int -msb(q, t, len) - quad_t q; - tspec_t t; - int len; +msb(int64_t q, tspec_t t, int len) { + if (len <= 0) len = size(t); return ((q & qbmasks[len - 1]) != 0); @@ -605,12 +626,10 @@ msb(q, t, len) /* * Extends the sign of q. */ -quad_t -xsign(q, t, len) - quad_t q; - tspec_t t; - int len; +int64_t +xsign(int64_t q, tspec_t t, int len) { + if (len <= 0) len = size(t); @@ -627,17 +646,17 @@ xsign(q, t, len) * representation. Type and value are returned in yylval. fcon() * (and yylex()) returns T_CON. * XXX Currently it is not possible to convert constants of type - * long double which are greater then DBL_MAX. + * long double which are greater than DBL_MAX. */ static int -fcon() +fcon(void) { const char *cp; int len; tspec_t typ; char c, *eptr; double d; - float f; + float f = 0; cp = yytext; len = yyleng; @@ -667,7 +686,7 @@ fcon() if (typ == FLOAT) { f = (float)d; - if (isinf(f)) { + if (!finite(f)) { /* floating-point constant out of range */ warning(248); f = f > 0 ? FLT_MAX : -FLT_MAX; @@ -685,10 +704,9 @@ fcon() } static int -operator(t, o) - int t; - op_t o; +operator(int t, op_t o) { + yylval.y_op = o; return (t); } @@ -697,7 +715,7 @@ operator(t, o) * Called if lex found a leading \'. */ static int -ccon() +ccon(void) { int n, val, c; char cv; @@ -727,7 +745,7 @@ ccon() cv = (char)val; val = cv; } - + yylval.y_val = xcalloc(1, sizeof (val_t)); yylval.y_val->v_tspec = INT; yylval.y_val->v_quad = val; @@ -739,7 +757,7 @@ ccon() * Called if lex found a leading L\' */ static int -wccon() +wccon(void) { static char buf[MB_LEN_MAX + 1]; int i, c; @@ -789,11 +807,10 @@ wccon() * string. * * Returns -1 if the end of the character constant or string is reached, - * -2 if the EOF is reached, and the charachter otherwise. + * -2 if the EOF is reached, and the character otherwise. */ static int -getescc(d) - int d; +getescc(int d) { static int pbc = -1; int n, c, v; @@ -808,9 +825,12 @@ getescc(d) return (-1); switch (c) { case '\n': - /* newline in string or char constant */ - error(254); - return (-2); + if (tflag) { + /* newline in string or char constant */ + error(254); + return (-2); + } + return (c); case EOF: return (-2); case '\\': @@ -833,11 +853,7 @@ getescc(d) if (tflag) /* \a undefined in traditional C */ warning(81); -#ifdef __STDC__ return ('\a'); -#else - return ('\007'); -#endif case 'b': return ('\b'); case 'f': @@ -852,11 +868,7 @@ getescc(d) if (tflag) /* \v undefined in traditional C */ warning(264); -#ifdef __STDC__ return ('\v'); -#else - return ('\013'); -#endif case '8': case '9': /* bad octal digit %c */ warning(77, c); @@ -930,7 +942,7 @@ getescc(d) * # lineno "filename" */ static void -directive() +directive(void) { const char *cp, *fn; char c, *eptr; @@ -939,9 +951,10 @@ directive() static int first = 1; /* Go to first non-whitespace after # */ - for (cp = yytext + 1; (c = *cp) == ' ' || c == '\t'; cp++) ; + for (cp = yytext + 1; (c = *cp) == ' ' || c == '\t'; cp++) + continue; - if (!isdigit(c)) { + if (!isdigit((unsigned char)c)) { error: /* undefined or invalid # directive */ warning(255); @@ -952,7 +965,8 @@ directive() goto error; if ((c = *(cp = eptr)) != ' ' && c != '\t' && c != '\0') goto error; - while ((c = *cp++) == ' ' || c == '\t') ; + while ((c = *cp++) == ' ' || c == '\t') + continue; if (c != '\0') { if (c != '"') goto error; @@ -963,11 +977,18 @@ directive() goto error; if ((fnl = cp++ - fn) > PATH_MAX) goto error; - while ((c = *cp++) == ' ' || c == '\t') ; + while ((c = *cp++) == ' ' || c == '\t') + continue; #if 0 if (c != '\0') warning("extra character(s) after directive"); #endif + + /* empty string means stdin */ + if (fnl == 0) { + fn = "{standard input}"; + fnl = 16; /* strlen (fn) */ + } curr_pos.p_file = fnnalloc(fn, fnl); /* * If this is the first directive, the name is the name @@ -981,13 +1002,17 @@ directive() } } curr_pos.p_line = (int)ln - 1; - if (curr_pos.p_file == csrc_pos.p_file) + curr_pos.p_uniq = 0; + if (curr_pos.p_file == csrc_pos.p_file) { csrc_pos.p_line = (int)ln - 1; + csrc_pos.p_uniq = 0; + } } /* * Handle lint comments. Following comments are currently understood: * ARGSUSEDn + * BITFIELDTYPE * CONSTCOND CONSTANTCOND CONSTANTCONDITION * FALLTHRU FALLTHROUGH * LINTLIBRARY @@ -1002,15 +1027,16 @@ directive() * parsed and a function which handles this comment is called. */ static void -comment() +comment(void) { int c, lc; static struct { const char *keywd; int arg; - void (*func) __P((int)); + void (*func)(int); } keywtab[] = { { "ARGSUSED", 1, argsused }, + { "BITFIELDTYPE", 0, bitfieldtype }, { "CONSTCOND", 0, constcond }, { "CONSTANTCOND", 0, constcond }, { "CONSTANTCONDITION", 0, constcond }, @@ -1034,7 +1060,8 @@ comment() eoc = 0; /* Skip white spaces after the start of the comment */ - while ((c = inpc()) != EOF && isspace(c)) ; + while ((c = inpc()) != EOF && isspace(c)) + continue; /* Read the potential keyword to keywd */ l = 0; @@ -1100,6 +1127,22 @@ comment() } /* + * Handle // style comments + */ +static void +slashslashcomment(void) +{ + int c; + + if (sflag < 2 && !gflag) + /* // comments only supported in C99 */ + (void)gnuism(312, tflag ? "traditional" : "ANSI"); + + while ((c = inpc()) != EOF && c != '\n') + continue; +} + +/* * Clear flags for lint comments LINTED, LONGLONG and CONSTCOND. * clrwflgs() is called after function definitions and global and * local declarations and definitions. It is also called between @@ -1107,8 +1150,9 @@ comment() * (if, switch, for, while). */ void -clrwflgs() +clrwflgs(void) { + nowarn = 0; quadflg = 0; ccflg = 0; @@ -1120,7 +1164,7 @@ clrwflgs() * by the parser are responsible for freeing this buffer. */ static int -string() +string(void) { u_char *s; int c; @@ -1151,7 +1195,7 @@ string() } static int -wcstrg() +wcstrg(void) { char *s; int c, i, n, wi; @@ -1221,8 +1265,7 @@ wcstrg() * XXX calls to getsym() should be delayed until decl1*() is called */ sym_t * -getsym(sb) - sbuf_t *sb; +getsym(sbuf_t *sb) { dinfo_t *di; char *s; @@ -1270,7 +1313,7 @@ getsym(sb) di = dcs; } - STRUCT_ASSIGN(sym->s_dpos, curr_pos); + UNIQUE_CURR_POS(sym->s_dpos); if ((sym->s_kind = symtyp) != FLAB) sym->s_type = gettyp(INT); @@ -1293,9 +1336,9 @@ getsym(sb) * back to the symbol table. */ void -rmsym(sym) - sym_t *sym; +rmsym(sym_t *sym) { + if ((*sym->s_rlink = sym->s_link) != NULL) sym->s_link->s_rlink = sym->s_rlink; sym->s_blklev = -1; @@ -1307,8 +1350,7 @@ rmsym(sym) * table. */ void -rmsyms(syms) - sym_t *syms; +rmsyms(sym_t *syms) { sym_t *sym; @@ -1326,9 +1368,7 @@ rmsyms(syms) * Put a symbol into the symbol table */ void -inssym(bl, sym) - int bl; - sym_t *sym; +inssym(int bl, sym_t *sym) { int h; @@ -1348,7 +1388,7 @@ inssym(bl, sym) * level 0. */ void -cleanup() +cleanup(void) { sym_t *sym, *nsym; int i; @@ -1371,8 +1411,7 @@ cleanup() * Create a new symbol with the name of an existing symbol. */ sym_t * -pushdown(sym) - sym_t *sym; +pushdown(sym_t *sym) { int h; sym_t *nsym; @@ -1382,7 +1421,7 @@ pushdown(sym) if (sym->s_blklev > blklev) lerror("pushdown()"); nsym->s_name = sym->s_name; - STRUCT_ASSIGN(nsym->s_dpos, curr_pos); + UNIQUE_CURR_POS(nsym->s_dpos); nsym->s_kind = sym->s_kind; nsym->s_blklev = blklev; @@ -1402,9 +1441,7 @@ pushdown(sym) * The type of information in yylval is described by tok. */ void -freeyyv(sp, tok) - void *sp; - int tok; +freeyyv(void *sp, int tok) { if (tok == T_NAME || tok == T_TYPENAME) { sbuf_t *sb = *(sbuf_t **)sp; @@ -1422,5 +1459,5 @@ freeyyv(sp, tok) lerror("fryylv() 1"); } free(strg); - } + } } diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index 525e407..d725de8 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.12 1995/10/02 17:37:57 jpo Exp $ */ +/* $NetBSD: tree.c,v 1.24 2002/01/31 22:30:20 tv Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -31,8 +31,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static char rcsid[] = "$NetBSD: tree.c,v 1.12 1995/10/02 17:37:57 jpo Exp $"; +#include <sys/cdefs.h> +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: tree.c,v 1.24 2002/01/31 22:30:20 tv Exp $"); #endif #include <stdlib.h> @@ -42,51 +43,51 @@ static char rcsid[] = "$NetBSD: tree.c,v 1.12 1995/10/02 17:37:57 jpo Exp $"; #include <math.h> #include "lint1.h" -#include "y.tab.h" +#include "cgram.h" /* Various flags for each operator. */ static mod_t modtab[NOPS]; -static tnode_t *getinode __P((tspec_t, quad_t)); -static void ptrcmpok __P((op_t, tnode_t *, tnode_t *)); -static int asgntypok __P((op_t, int, tnode_t *, tnode_t *)); -static void chkbeop __P((op_t, tnode_t *, tnode_t *)); -static void chkeop2 __P((op_t, int, tnode_t *, tnode_t *)); -static void chkeop1 __P((op_t, int, tnode_t *, tnode_t *)); -static tnode_t *mktnode __P((op_t, type_t *, tnode_t *, tnode_t *)); -static void balance __P((op_t, tnode_t **, tnode_t **)); -static void incompat __P((op_t, tspec_t, tspec_t)); -static void illptrc __P((mod_t *, type_t *, type_t *)); -static void mrgqual __P((type_t **, type_t *, type_t *)); -static int conmemb __P((type_t *)); -static void ptconv __P((int, tspec_t, tspec_t, type_t *, tnode_t *)); -static void iiconv __P((op_t, int, tspec_t, tspec_t, type_t *, tnode_t *)); -static void piconv __P((op_t, tspec_t, type_t *, tnode_t *)); -static void ppconv __P((op_t, tnode_t *, type_t *)); -static tnode_t *bldstr __P((op_t, tnode_t *, tnode_t *)); -static tnode_t *bldincdec __P((op_t, tnode_t *)); -static tnode_t *bldamper __P((tnode_t *, int)); -static tnode_t *bldplmi __P((op_t, tnode_t *, tnode_t *)); -static tnode_t *bldshft __P((op_t, tnode_t *, tnode_t *)); -static tnode_t *bldcol __P((tnode_t *, tnode_t *)); -static tnode_t *bldasgn __P((op_t, tnode_t *, tnode_t *)); -static tnode_t *plength __P((type_t *)); -static tnode_t *fold __P((tnode_t *)); -static tnode_t *foldtst __P((tnode_t *)); -static tnode_t *foldflt __P((tnode_t *)); -static tnode_t *chkfarg __P((type_t *, tnode_t *)); -static tnode_t *parg __P((int, type_t *, tnode_t *)); -static void nulleff __P((tnode_t *)); -static void displexpr __P((tnode_t *, int)); -static void chkaidx __P((tnode_t *, int)); -static void chkcomp __P((op_t, tnode_t *, tnode_t *)); -static void precconf __P((tnode_t *)); +static tnode_t *getinode(tspec_t, int64_t); +static void ptrcmpok(op_t, tnode_t *, tnode_t *); +static int asgntypok(op_t, int, tnode_t *, tnode_t *); +static void chkbeop(op_t, tnode_t *, tnode_t *); +static void chkeop2(op_t, int, tnode_t *, tnode_t *); +static void chkeop1(op_t, int, tnode_t *, tnode_t *); +static tnode_t *mktnode(op_t, type_t *, tnode_t *, tnode_t *); +static void balance(op_t, tnode_t **, tnode_t **); +static void incompat(op_t, tspec_t, tspec_t); +static void illptrc(mod_t *, type_t *, type_t *); +static void mrgqual(type_t **, type_t *, type_t *); +static int conmemb(type_t *); +static void ptconv(int, tspec_t, tspec_t, type_t *, tnode_t *); +static void iiconv(op_t, int, tspec_t, tspec_t, type_t *, tnode_t *); +static void piconv(op_t, tspec_t, type_t *, tnode_t *); +static void ppconv(op_t, tnode_t *, type_t *); +static tnode_t *bldstr(op_t, tnode_t *, tnode_t *); +static tnode_t *bldincdec(op_t, tnode_t *); +static tnode_t *bldamper(tnode_t *, int); +static tnode_t *bldplmi(op_t, tnode_t *, tnode_t *); +static tnode_t *bldshft(op_t, tnode_t *, tnode_t *); +static tnode_t *bldcol(tnode_t *, tnode_t *); +static tnode_t *bldasgn(op_t, tnode_t *, tnode_t *); +static tnode_t *plength(type_t *); +static tnode_t *fold(tnode_t *); +static tnode_t *foldtst(tnode_t *); +static tnode_t *foldflt(tnode_t *); +static tnode_t *chkfarg(type_t *, tnode_t *); +static tnode_t *parg(int, type_t *, tnode_t *); +static void nulleff(tnode_t *); +static void displexpr(tnode_t *, int); +static void chkaidx(tnode_t *, int); +static void chkcomp(op_t, tnode_t *, tnode_t *); +static void precconf(tnode_t *); /* * Initialize mods of operators. */ void -initmtab() +initmtab(void) { static struct { op_t op; @@ -217,9 +218,7 @@ initmtab() * This is most often used to change type "T" in type "pointer to T". */ type_t * -incref(tp, t) - type_t *tp; - tspec_t t; +incref(type_t *tp, tspec_t t) { type_t *tp2; @@ -233,9 +232,7 @@ incref(tp, t) * same for use in expressions */ type_t * -tincref(tp, t) - type_t *tp; - tspec_t t; +tincref(type_t *tp, tspec_t t) { type_t *tp2; @@ -249,9 +246,7 @@ tincref(tp, t) * Create a node for a constant. */ tnode_t * -getcnode(tp, v) - type_t *tp; - val_t *v; +getcnode(type_t *tp, val_t *v) { tnode_t *n; @@ -270,9 +265,7 @@ getcnode(tp, v) * Create a node for a integer constant. */ static tnode_t * -getinode(t, q) - tspec_t t; - quad_t q; +getinode(tspec_t t, int64_t q) { tnode_t *n; @@ -290,9 +283,7 @@ getinode(t, q) * ntok is the token which follows the name. */ tnode_t * -getnnode(sym, ntok) - sym_t *sym; - int ntok; +getnnode(sym_t *sym, int ntok) { tnode_t *n; @@ -338,8 +329,7 @@ getnnode(sym, ntok) * Create a node for a string. */ tnode_t * -getsnode(strg) - strg_t *strg; +getsnode(strg_t *strg) { size_t len; tnode_t *n; @@ -377,10 +367,7 @@ getsnode(strg) * member of the struct or union specified by the tn argument. */ sym_t * -strmemb(tn, op, msym) - tnode_t *tn; - op_t op; - sym_t *msym; +strmemb(tnode_t *tn, op_t op, sym_t *msym) { str_t *str; type_t *tp; @@ -537,9 +524,7 @@ strmemb(tn, op, msym) * rn if not NULL, right operand */ tnode_t * -build(op, ln, rn) - op_t op; - tnode_t *ln, *rn; +build(op_t op, tnode_t *ln, tnode_t *rn) { mod_t *mp; tnode_t *ntn; @@ -565,7 +550,7 @@ build(op, ln, rn) rn = cconv(rn); /* - * Print some warnings for comparisions of unsigned values with + * Print some warnings for comparisons of unsigned values with * constants lower than or equal to null. This must be done * before promote() because otherwise unsigned char and unsigned * short would be promoted to int. Also types are tested to be @@ -670,7 +655,7 @@ build(op, ln, rn) break; } - /* Return if an error occured. */ + /* Return if an error occurred. */ if (ntn == NULL) return (NULL); @@ -717,8 +702,7 @@ build(op, ln, rn) * Lvalues are converted to rvalues. */ tnode_t * -cconv(tn) - tnode_t *tn; +cconv(tnode_t *tn) { type_t *tp; @@ -762,14 +746,12 @@ cconv(tn) * If the types are ok, typeok() returns 1, otherwise 0. */ int -typeok(op, arg, ln, rn) - op_t op; - int arg; - tnode_t *ln, *rn; +typeok(op_t op, int arg, tnode_t *ln, tnode_t *rn) { mod_t *mp; - tspec_t lt, rt, lst, rst, olt, ort; - type_t *ltp, *rtp, *lstp, *rstp; + tspec_t lt, rt = NOTSPEC, lst = NOTSPEC, rst = NOTSPEC, olt = NOTSPEC, + ort = NOTSPEC; + type_t *ltp, *rtp = NULL, *lstp = NULL, *rstp = NULL; tnode_t *tn; mp = &modtab[op]; @@ -806,12 +788,14 @@ typeok(op, arg, ln, rn) * For these operations we need the types before promotion * and balancing. */ - for (tn=ln; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left) ; + for (tn=ln; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left) + continue; olt = tn->tn_type->t_tspec; - for (tn=rn; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left) ; + for (tn=rn; tn->tn_op==CVT && !tn->tn_cast; tn=tn->tn_left) + continue; ort = tn->tn_type->t_tspec; } - + switch (op) { case POINT: /* @@ -978,10 +962,10 @@ typeok(op, arg, ln, rn) if (!isutyp(rt) && rn->tn_val->v_quad < 0) { /* negative shift */ warning(121); - } else if ((u_quad_t)rn->tn_val->v_quad == size(lt)) { + } else if ((uint64_t)rn->tn_val->v_quad == size(lt)) { /* shift equal to size fo object */ warning(267); - } else if ((u_quad_t)rn->tn_val->v_quad > size(lt)) { + } else if ((uint64_t)rn->tn_val->v_quad > size(lt)) { /* shift greater than size of object */ warning(122); } @@ -991,7 +975,7 @@ typeok(op, arg, ln, rn) case NE: /* * Accept some things which are allowed with EQ and NE, - * but not with ordered comparisions. + * but not with ordered comparisons. */ if (lt == PTR && ((rt == PTR && rst == VOID) || isityp(rt))) { if (rn->tn_op == CON && rn->tn_val->v_quad == 0) @@ -1133,6 +1117,32 @@ typeok(op, arg, ln, rn) nulleff(ln); break; /* LINTED (enumeration values not handled in switch) */ + case CON: + case CASE: + case PUSH: + case LOAD: + case ICALL: + case CVT: + case CALL: + case FSEL: + case STRING: + case NAME: + case LOGOR: + case LOGAND: + case OR: + case XOR: + case AND: + case MOD: + case DIV: + case MULT: + case UMINUS: + case UPLUS: + case DEC: + case INC: + case COMPL: + case NOT: + case NOOP: + break; } if (mp->m_badeop && @@ -1148,9 +1158,7 @@ typeok(op, arg, ln, rn) } static void -ptrcmpok(op, ln, rn) - op_t op; - tnode_t *ln, *rn; +ptrcmpok(op_t op, tnode_t *ln, tnode_t *rn) { type_t *ltp, *rtp; tspec_t lt, rt; @@ -1164,7 +1172,7 @@ ptrcmpok(op, ln, rn) /* (void *)0 already handled in typeok() */ *(lt == FUNC ? <s : &rts) = "function pointer"; *(lt == VOID ? <s : &rts) = "'void *'"; - /* ANSI C forbids comparision of %s with %s */ + /* ANSI C forbids comparison of %s with %s */ warning(274, lts, rts); } return; @@ -1188,13 +1196,10 @@ ptrcmpok(op, ln, rn) * If the types are (almost) compatible, 1 is returned, otherwise 0. */ static int -asgntypok(op, arg, ln, rn) - op_t op; - int arg; - tnode_t *ln, *rn; +asgntypok(op_t op, int arg, tnode_t *ln, tnode_t *rn) { - tspec_t lt, rt, lst, rst; - type_t *ltp, *rtp, *lstp, *rstp; + tspec_t lt, rt, lst = NOTSPEC, rst = NOTSPEC; + type_t *ltp, *rtp, *lstp = NULL, *rstp = NULL; mod_t *mp; const char *lts, *rts; @@ -1329,9 +1334,7 @@ asgntypok(op, arg, ln, rn) * enum type, is applied to an enum type. */ static void -chkbeop(op, ln, rn) - op_t op; - tnode_t *ln, *rn; +chkbeop(op_t op, tnode_t *ln, tnode_t *rn) { mod_t *mp; @@ -1364,10 +1367,7 @@ chkbeop(op, ln, rn) * Prints a warning if an operator is applied to two different enum types. */ static void -chkeop2(op, arg, ln, rn) - op_t op; - int arg; - tnode_t *ln, *rn; +chkeop2(op_t op, int arg, tnode_t *ln, tnode_t *rn) { mod_t *mp; @@ -1395,7 +1395,7 @@ chkeop2(op, arg, ln, rn) #if 0 } else if (mp->m_comp && op != EQ && op != NE) { if (eflag) - /* dubious comparisions of enums */ + /* dubious comparisons of enums */ warning(243, mp->m_name); #endif } @@ -1406,11 +1406,9 @@ chkeop2(op, arg, ln, rn) * types. */ static void -chkeop1(op, arg, ln, rn) - op_t op; - int arg; - tnode_t *ln, *rn; +chkeop1(op_t op, int arg, tnode_t *ln, tnode_t *rn) { + if (!eflag) return; @@ -1448,10 +1446,7 @@ chkeop1(op, arg, ln, rn) * Build and initialize a new node. */ static tnode_t * -mktnode(op, type, ln, rn) - op_t op; - type_t *type; - tnode_t *ln, *rn; +mktnode(op_t op, type_t *type, tnode_t *ln, tnode_t *rn) { tnode_t *ntn; tspec_t t; @@ -1484,10 +1479,7 @@ mktnode(op, type, ln, rn) * float to double. */ tnode_t * -promote(op, farg, tn) - op_t op; - int farg; - tnode_t *tn; +promote(op_t op, int farg, tnode_t *tn) { tspec_t t; type_t *ntp; @@ -1562,9 +1554,7 @@ promote(op, farg, tn) * type. This is done in different ways for traditional C and ANIS C. */ static void -balance(op, lnp, rnp) - op_t op; - tnode_t **lnp, **rnp; +balance(op_t op, tnode_t **lnp, tnode_t **rnp) { tspec_t lt, rt, t; int i, u; @@ -1639,14 +1629,10 @@ balance(op, lnp, rnp) * If op is FARG, arg is the number of the argument (used for warnings). */ tnode_t * -convert(op, arg, tp, tn) - op_t op; - int arg; - type_t *tp; - tnode_t *tn; +convert(op_t op, int arg, type_t *tp, tnode_t *tn) { tnode_t *ntn; - tspec_t nt, ot, ost; + tspec_t nt, ot, ost = NOTSPEC; if (tn->tn_lvalue) lerror("convert() 1"); @@ -1692,11 +1678,7 @@ convert(op, arg, tp, tn) * in asgntypok(). */ static void -ptconv(arg, nt, ot, tp, tn) - int arg; - tspec_t nt, ot; - type_t *tp; - tnode_t *tn; +ptconv(int arg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn) { tnode_t *ptn; @@ -1748,12 +1730,7 @@ ptconv(arg, nt, ot, tp, tn) */ /* ARGSUSED */ static void -iiconv(op, arg, nt, ot, tp, tn) - op_t op; - int arg; - tspec_t nt, ot; - type_t *tp; - tnode_t *tn; +iiconv(op_t op, int arg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn) { if (tn->tn_op == CON) return; @@ -1784,7 +1761,7 @@ iiconv(op, arg, nt, ot, tp, tn) } else { warning(132, tyname(tn->tn_type)); } - } + } } } @@ -1792,12 +1769,9 @@ iiconv(op, arg, nt, ot, tp, tn) * Print warnings for dubious conversions of pointer to integer. */ static void -piconv(op, nt, tp, tn) - op_t op; - tspec_t nt; - type_t *tp; - tnode_t *tn; +piconv(op_t op, tspec_t nt, type_t *tp, tnode_t *tn) { + if (tn->tn_op == CON) return; @@ -1821,10 +1795,7 @@ piconv(op, nt, tp, tn) * Print warnings for questionable pointer conversions. */ static void -ppconv(op, tn, tp) - op_t op; - tnode_t *tn; - type_t *tp; +ppconv(op_t op, tnode_t *tn, type_t *tp) { tspec_t nt, ot; const char *nts, *ots; @@ -1855,7 +1826,7 @@ ppconv(op, tn, tp) warning(229); return; } - + if (getbound(tp->t_subt) > getbound(tn->tn_type->t_subt)) { if (hflag) /* possible pointer alignment problem */ @@ -1881,16 +1852,12 @@ ppconv(op, tn, tp) * v old constant */ void -cvtcon(op, arg, tp, nv, v) - op_t op; - int arg; - type_t *tp; - val_t *nv, *v; +cvtcon(op_t op, int arg, type_t *tp, val_t *nv, val_t *v) { tspec_t ot, nt; - ldbl_t max, min; + ldbl_t max = 0.0, min = 0.0; int sz, rchk; - quad_t xmask, xmsk1; + int64_t xmask, xmsk1; int osz, nsz; ot = v->v_tspec; @@ -1921,7 +1888,7 @@ cvtcon(op, arg, tp, nv, v) case QUAD: max = QUAD_MAX; min = QUAD_MIN; break; case UQUAD: - max = (u_quad_t)UQUAD_MAX; min = 0; break; + max = (uint64_t)UQUAD_MAX; min = 0; break; case FLOAT: max = FLT_MAX; min = -FLT_MAX; break; case DOUBLE: @@ -1954,18 +1921,18 @@ cvtcon(op, arg, tp, nv, v) nv->v_ldbl = v->v_ldbl; } else { nv->v_quad = (nt == PTR || isutyp(nt)) ? - (u_quad_t)v->v_ldbl : (quad_t)v->v_ldbl; + (uint64_t)v->v_ldbl : (int64_t)v->v_ldbl; } } else { if (nt == FLOAT) { nv->v_ldbl = (ot == PTR || isutyp(ot)) ? - (float)(u_quad_t)v->v_quad : (float)v->v_quad; + (float)(uint64_t)v->v_quad : (float)v->v_quad; } else if (nt == DOUBLE) { nv->v_ldbl = (ot == PTR || isutyp(ot)) ? - (double)(u_quad_t)v->v_quad : (double)v->v_quad; + (double)(uint64_t)v->v_quad : (double)v->v_quad; } else if (nt == LDOUBLE) { nv->v_ldbl = (ot == PTR || isutyp(ot)) ? - (ldbl_t)(u_quad_t)v->v_quad : (ldbl_t)v->v_quad; + (ldbl_t)(uint64_t)v->v_quad : (ldbl_t)v->v_quad; } else { rchk = 1; /* Check for lost precision. */ nv->v_quad = v->v_quad; @@ -1987,7 +1954,7 @@ cvtcon(op, arg, tp, nv, v) sz = tp->t_isfield ? tp->t_flen : size(nt); nv->v_quad = xsign(nv->v_quad, nt, sz); } - + if (rchk && op != CVT) { osz = size(ot); nsz = tp->t_isfield ? tp->t_flen : size(nt); @@ -2114,9 +2081,7 @@ cvtcon(op, arg, tp, nv, v) * Prints a appropriate warning. */ static void -incompat(op, lt, rt) - op_t op; - tspec_t lt, rt; +incompat(op_t op, tspec_t lt, tspec_t rt) { mod_t *mp; @@ -2148,9 +2113,7 @@ incompat(op, lt, rt) * Print an appropriate warning. */ static void -illptrc(mp, ltp, rtp) - mod_t *mp; - type_t *ltp, *rtp; +illptrc(mod_t *mp, type_t *ltp, type_t *rtp) { tspec_t lt, rt; @@ -2184,9 +2147,9 @@ illptrc(mp, ltp, rtp) * of tp1->t_subt and tp2->t_subt. */ static void -mrgqual(tpp, tp1, tp2) - type_t **tpp, *tp1, *tp2; +mrgqual(type_t **tpp, type_t *tp1, type_t *tp2) { + if ((*tpp)->t_tspec != PTR || tp1->t_tspec != PTR || tp2->t_tspec != PTR) { lerror("mrgqual()"); @@ -2212,8 +2175,7 @@ mrgqual(tpp, tp1, tp2) * (maybe recursively). */ static int -conmemb(tp) - type_t *tp; +conmemb(type_t *tp) { sym_t *m; tspec_t t; @@ -2233,8 +2195,7 @@ conmemb(tp) } const char * -tyname(tp) - type_t *tp; +tyname(type_t *tp) { tspec_t t; const char *s; @@ -2273,9 +2234,7 @@ tyname(tp) * Create a new node for one of the operators POINT and ARROW. */ static tnode_t * -bldstr(op, ln, rn) - op_t op; - tnode_t *ln, *rn; +bldstr(op_t op, tnode_t *ln, tnode_t *rn) { tnode_t *ntn, *ctn; int nolval; @@ -2327,9 +2286,7 @@ bldstr(op, ln, rn) * Create a node for INCAFT, INCBEF, DECAFT and DECBEF. */ static tnode_t * -bldincdec(op, ln) - op_t op; - tnode_t *ln; +bldincdec(op_t op, tnode_t *ln) { tnode_t *cn, *ntn; @@ -2339,7 +2296,7 @@ bldincdec(op, ln) if (ln->tn_type->t_tspec == PTR) { cn = plength(ln->tn_type); } else { - cn = getinode(INT, (quad_t)1); + cn = getinode(INT, (int64_t)1); } ntn = mktnode(op, ln->tn_type, ln, cn); @@ -2350,13 +2307,11 @@ bldincdec(op, ln) * Create a tree node for the & operator */ static tnode_t * -bldamper(tn, noign) - tnode_t *tn; - int noign; +bldamper(tnode_t *tn, int noign) { tnode_t *ntn; tspec_t t; - + if (!noign && ((t = tn->tn_type->t_tspec) == ARRAY || t == FUNC)) { /* & before array or function: ignored */ if (tflag) @@ -2370,7 +2325,7 @@ bldamper(tn, noign) tn->tn_left->tn_type->t_subt == tn->tn_type) { return (tn->tn_left); } - + ntn = mktnode(AMPER, tincref(tn->tn_type, PTR), tn, NULL); return (ntn); @@ -2380,9 +2335,7 @@ bldamper(tn, noign) * Create a node for operators PLUS and MINUS. */ static tnode_t * -bldplmi(op, ln, rn) - op_t op; - tnode_t *ln, *rn; +bldplmi(op_t op, tnode_t *ln, tnode_t *rn) { tnode_t *ntn, *ctn; type_t *tp; @@ -2435,9 +2388,7 @@ bldplmi(op, ln, rn) * Create a node for operators SHL and SHR. */ static tnode_t * -bldshft(op, ln, rn) - op_t op; - tnode_t *ln, *rn; +bldshft(op_t op, tnode_t *ln, tnode_t *rn) { tspec_t t; tnode_t *ntn; @@ -2452,8 +2403,7 @@ bldshft(op, ln, rn) * Create a node for COLON. */ static tnode_t * -bldcol(ln, rn) - tnode_t *ln, *rn; +bldcol(tnode_t *ln, tnode_t *rn) { tspec_t lt, rt, pdt; type_t *rtp; @@ -2531,9 +2481,7 @@ bldcol(ln, rn) * Create a node for an assignment operator (both = and op= ). */ static tnode_t * -bldasgn(op, ln, rn) - op_t op; - tnode_t *ln, *rn; +bldasgn(op_t op, tnode_t *ln, tnode_t *rn) { tspec_t lt, rt; tnode_t *ntn, *ctn; @@ -2594,8 +2542,7 @@ bldasgn(op, ln, rn) * Get length of type tp->t_subt. */ static tnode_t * -plength(tp) - type_t *tp; +plength(type_t *tp) { int elem, elsz; tspec_t st; @@ -2657,39 +2604,28 @@ plength(tp) st = INT; #endif - return (getinode(st, (quad_t)(elem * elsz / CHAR_BIT))); + return (getinode(st, (int64_t)(elem * elsz / CHAR_BIT))); } -#ifdef XXX_BROKEN_GCC -static int -quad_t_eq(x, y) - quad_t x, y; -{ - return (x == y); -} - -static int -u_quad_t_eq(x, y) - u_quad_t x, y; -{ - return (x == y); -} -#endif - +/* + * XXX + * Note: There appear to be a number of bugs in detecting overflow in + * this function. An audit and a set of proper regression tests are needed. + * --Perry Metzger, Nov. 16, 2001 + */ /* * Do only as much as necessary to compute constant expressions. * Called only if the operator allows folding and (both) operands * are constants. */ static tnode_t * -fold(tn) - tnode_t *tn; +fold(tnode_t *tn) { val_t *v; tspec_t t; int utyp, ovfl; - quad_t sl, sr, q, mask; - u_quad_t ul, ur; + int64_t sl, sr = 0, q = 0, mask; + uint64_t ul, ur = 0; tnode_t *cn; v = xcalloc(1, sizeof (val_t)); @@ -2700,6 +2636,7 @@ fold(tn) if (modtab[tn->tn_op].m_binary) ur = sr = tn->tn_right->tn_val->v_quad; + mask = qlmasks[size(t)]; ovfl = 0; switch (tn->tn_op) { @@ -2715,9 +2652,17 @@ fold(tn) q = ~sl; break; case MULT: - q = utyp ? ul * ur : sl * sr; - if (msb(q, t, -1) != (msb(sl, t, -1) ^ msb(sr, t, -1))) - ovfl = 1; + if (utyp) { + q = ul * ur; + if (q != (q & mask)) + ovfl = 1; + else if ((ul != 0) && ((q / ul) != ur)) + ovfl = 1; + } else { + q = sl * sr; + if (msb(q, t, -1) != (msb(sl, t, -1) ^ msb(sr, t, -1))) + ovfl = 1; + } break; case DIV: if (sr == 0) { @@ -2762,7 +2707,7 @@ fold(tn) break; case SHR: /* - * The sign must be explizitly extended because + * The sign must be explicitly extended because * shifts of signed values are implementation dependent. */ q = ul >> sr; @@ -2781,11 +2726,7 @@ fold(tn) q = utyp ? ul > ur : sl > sr; break; case EQ: -#ifdef XXX_BROKEN_GCC - q = utyp ? u_quad_t_eq(ul, ur) : quad_t_eq(sl, sr); -#else q = utyp ? ul == ur : sl == sr; -#endif break; case NE: q = utyp ? ul != ur : sl != sr; @@ -2803,10 +2744,8 @@ fold(tn) lerror("fold() 5"); } - mask = qlmasks[size(t)]; - /* XXX does not work for quads. */ - if (ovfl || ((q | mask) != ~(u_quad_t)0 && (q & ~mask) != 0)) { + if (ovfl || ((q | mask) != ~(uint64_t)0 && (q & ~mask) != 0)) { if (hflag) /* integer overflow detected, op %s */ warning(141, modtab[tn->tn_op].m_name); @@ -2819,23 +2758,13 @@ fold(tn) return (cn); } -#ifdef XXX_BROKEN_GCC -int -ldbl_t_neq(x, y) - ldbl_t x, y; -{ - return (x != y); -} -#endif - /* * Same for operators whose operands are compared with 0 (test context). */ static tnode_t * -foldtst(tn) - tnode_t *tn; +foldtst(tnode_t *tn) { - int l, r; + int l, r = 0; val_t *v; v = xcalloc(1, sizeof (val_t)); @@ -2844,22 +2773,14 @@ foldtst(tn) lerror("foldtst() 1"); if (isftyp(tn->tn_left->tn_type->t_tspec)) { -#ifdef XXX_BROKEN_GCC - l = ldbl_t_neq(tn->tn_left->tn_val->v_ldbl, 0.0); -#else l = tn->tn_left->tn_val->v_ldbl != 0.0; -#endif } else { l = tn->tn_left->tn_val->v_quad != 0; } if (modtab[tn->tn_op].m_binary) { if (isftyp(tn->tn_right->tn_type->t_tspec)) { -#ifdef XXX_BROKEN_GCC - r = ldbl_t_neq(tn->tn_right->tn_val->v_ldbl, 0.0); -#else r = tn->tn_right->tn_val->v_ldbl != 0.0; -#endif } else { r = tn->tn_right->tn_val->v_quad != 0; } @@ -2889,12 +2810,11 @@ foldtst(tn) * Same for operands with floating point type. */ static tnode_t * -foldflt(tn) - tnode_t *tn; +foldflt(tnode_t *tn) { val_t *v; tspec_t t; - ldbl_t l, r; + ldbl_t l, r = 0; v = xcalloc(1, sizeof (val_t)); v->v_tspec = t = tn->tn_type->t_tspec; @@ -2966,7 +2886,7 @@ foldflt(tn) if (isnan((double)v->v_ldbl)) lerror("foldflt() 5"); - if (isinf((double)v->v_ldbl) || + if (!finite((double)v->v_ldbl) || (t == FLOAT && (v->v_ldbl > FLT_MAX || v->v_ldbl < -FLT_MAX)) || (t == DOUBLE && @@ -2989,8 +2909,7 @@ foldflt(tn) * Create a constant node for sizeof. */ tnode_t * -bldszof(tp) - type_t *tp; +bldszof(type_t *tp) { int elem, elsz; tspec_t st; @@ -3050,16 +2969,14 @@ bldszof(tp) st = UINT; #endif - return (getinode(st, (quad_t)(elem * elsz / CHAR_BIT))); + return (getinode(st, (int64_t)(elem * elsz / CHAR_BIT))); } /* * Type casts. */ tnode_t * -cast(tn, tp) - tnode_t *tn; - type_t *tp; +cast(tnode_t *tn, type_t *tp) { tspec_t nt, ot; @@ -3118,8 +3035,7 @@ cast(tn, tp) * in funcarg() we have no information about expected argument types. */ tnode_t * -funcarg(args, arg) - tnode_t *args, *arg; +funcarg(tnode_t *args, tnode_t *arg) { tnode_t *ntn; @@ -3129,7 +3045,7 @@ funcarg(args, arg) * will not change. */ if (arg == NULL) - arg = getinode(INT, (quad_t)0); + arg = getinode(INT, (int64_t)0); ntn = mktnode(PUSH, arg->tn_type, arg, args); @@ -3141,8 +3057,7 @@ funcarg(args, arg) * function arguments and insert conversions, if necessary. */ tnode_t * -funccall(func, args) - tnode_t *func, *args; +funccall(tnode_t *func, tnode_t *args) { tnode_t *ntn; op_t fcop; @@ -3181,9 +3096,7 @@ funccall(func, args) * if necessary. */ static tnode_t * -chkfarg(ftp, args) - type_t *ftp; /* type of called function */ - tnode_t *args; /* arguments */ +chkfarg(type_t *ftp, tnode_t *args) { tnode_t *arg; sym_t *asym; @@ -3206,14 +3119,15 @@ chkfarg(ftp, args) error(150, narg, narg > 1 ? "s" : "", npar); asym = NULL; } - + for (n = 1; n <= narg; n++) { /* * The rightmost argument is at the top of the argument * subtree. */ - for (i = narg, arg = args; i > n; i--, arg = arg->tn_right) ; + for (i = narg, arg = args; i > n; i--, arg = arg->tn_right) + continue; /* some things which are always not allowd */ if ((at = arg->tn_left->tn_type->t_tspec) == VOID) { @@ -3255,10 +3169,9 @@ chkfarg(ftp, args) * the type of the parameter. */ static tnode_t * -parg(n, tp, tn) - int n; /* pos of arg */ - type_t *tp; /* expected type (from prototype) */ - tnode_t *tn; /* argument */ +parg( int n, /* pos of arg */ + type_t *tp, /* expected type (from prototype) */ + tnode_t *tn) /* argument */ { tnode_t *ln; int warn; @@ -3281,8 +3194,7 @@ parg(n, tp, tn) * type, an error message is printed. */ val_t * -constant(tn) - tnode_t *tn; +constant(tnode_t *tn) { val_t *v; @@ -3334,10 +3246,9 @@ constant(tn) * for the expression. */ void -expr(tn, vctx, tctx) - tnode_t *tn; - int vctx, tctx; +expr(tnode_t *tn, int vctx, int tctx) { + if (tn == NULL && nerr == 0) lerror("expr() 1"); @@ -3376,9 +3287,9 @@ expr(tn, vctx, tctx) } static void -nulleff(tn) - tnode_t *tn; +nulleff(tnode_t *tn) { + if (!hflag) return; @@ -3397,7 +3308,7 @@ nulleff(tn) * operands has a side effect */ tn = tn->tn_right; - } else if (tn->tn_op == COLON) { + } else if (tn->tn_op == COLON || tn->tn_op == COMMA) { /* * : has a side effect if at least one of its operands * has a side effect @@ -3423,11 +3334,9 @@ nulleff(tn) * only used for debugging */ static void -displexpr(tn, offs) - tnode_t *tn; - int offs; +displexpr(tnode_t *tn, int offs) { - u_quad_t uq; + uint64_t uq; if (tn == NULL) { (void)printf("%*s%s\n", offs, "", "NULL"); @@ -3481,9 +3390,8 @@ displexpr(tn, offs) */ /* ARGSUSED */ void -chkmisc(tn, vctx, tctx, eqwarn, fcall, rvdisc, szof) - tnode_t *tn; - int vctx, tctx, eqwarn, fcall, rvdisc, szof; +chkmisc(tnode_t *tn, int vctx, int tctx, int eqwarn, int fcall, int rvdisc, + int szof) { tnode_t *ln, *rn; mod_t *mp; @@ -3576,6 +3484,44 @@ chkmisc(tn, vctx, tctx, eqwarn, fcall, rvdisc, szof) case STRING: return; /* LINTED (enumeration values not handled in switch) */ + case OR: + case XOR: + case NE: + case GE: + case GT: + case LE: + case LT: + case SHR: + case SHL: + case MINUS: + case PLUS: + case MOD: + case DIV: + case MULT: + case STAR: + case UMINUS: + case UPLUS: + case DEC: + case INC: + case COMPL: + case NOT: + case POINT: + case ARROW: + case NOOP: + case AND: + case FARG: + case CASE: + case INIT: + case RETURN: + case ICALL: + case CVT: + case COMMA: + case FSEL: + case COLON: + case QUEST: + case LOGOR: + case LOGAND: + break; } cvctx = mp->m_vctx; @@ -3603,6 +3549,9 @@ chkmisc(tn, vctx, tctx, eqwarn, fcall, rvdisc, szof) case COLON: chkmisc(rn, cvctx, ctctx, mp->m_eqwarn, 0, 0, szof); break; + case COMMA: + chkmisc(rn, vctx, tctx, mp->m_eqwarn, 0, 0, szof); + break; default: if (mp->m_binary) chkmisc(rn, 1, 0, mp->m_eqwarn, 0, 0, szof); @@ -3618,14 +3567,12 @@ chkmisc(tn, vctx, tctx, eqwarn, fcall, rvdisc, szof) * after the array. */ static void -chkaidx(tn, amper) - tnode_t *tn; - int amper; +chkaidx(tnode_t *tn, int amper) { int dim; tnode_t *ln, *rn; int elsz; - quad_t con; + int64_t con; ln = tn->tn_left; rn = tn->tn_right; @@ -3641,7 +3588,7 @@ chkaidx(tn, amper) return; if (ln->tn_left->tn_type->t_tspec != ARRAY) return; - + /* * For incomplete array types, we can print a warning only if * the index is negative. @@ -3656,7 +3603,7 @@ chkaidx(tn, amper) /* Change the unit of the index from bytes to element size. */ if (isutyp(rn->tn_type->t_tspec)) { - con = (u_quad_t)rn->tn_val->v_quad / elsz; + con = (uint64_t)rn->tn_val->v_quad / elsz; } else { con = rn->tn_val->v_quad / elsz; } @@ -3666,19 +3613,17 @@ chkaidx(tn, amper) if (!isutyp(rn->tn_type->t_tspec) && con < 0) { /* array subscript cannot be negative: %ld */ warning(167, (long)con); - } else if (dim > 0 && (u_quad_t)con >= dim) { + } else if (dim > 0 && (uint64_t)con >= dim) { /* array subscript cannot be > %d: %ld */ warning(168, dim - 1, (long)con); } } /* - * Check for ordered comparisions of unsigned values with 0. + * Check for ordered comparisons of unsigned values with 0. */ static void -chkcomp(op, ln, rn) - op_t op; - tnode_t *ln, *rn; +chkcomp(op_t op, tnode_t *ln, tnode_t *rn) { tspec_t lt, rt; mod_t *mp; @@ -3696,25 +3641,25 @@ chkcomp(op, ln, rn) if ((hflag || pflag) && lt == CHAR && rn->tn_op == CON && (rn->tn_val->v_quad < 0 || rn->tn_val->v_quad > ~(~0 << (CHAR_BIT - 1)))) { - /* nonportable character comparision, op %s */ + /* nonportable character comparison, op %s */ warning(230, mp->m_name); return; } if ((hflag || pflag) && rt == CHAR && ln->tn_op == CON && (ln->tn_val->v_quad < 0 || ln->tn_val->v_quad > ~(~0 << (CHAR_BIT - 1)))) { - /* nonportable character comparision, op %s */ + /* nonportable character comparison, op %s */ warning(230, mp->m_name); return; } if (isutyp(lt) && !isutyp(rt) && rn->tn_op == CON && rn->tn_val->v_quad <= 0) { if (rn->tn_val->v_quad < 0) { - /* comparision of %s with %s, op %s */ + /* comparison of %s with %s, op %s */ warning(162, tyname(ln->tn_type), "negative constant", mp->m_name); } else if (op == LT || op == GE || (hflag && op == LE)) { - /* comparision of %s with %s, op %s */ + /* comparison of %s with %s, op %s */ warning(162, tyname(ln->tn_type), "0", mp->m_name); } return; @@ -3722,11 +3667,11 @@ chkcomp(op, ln, rn) if (isutyp(rt) && !isutyp(lt) && ln->tn_op == CON && ln->tn_val->v_quad <= 0) { if (ln->tn_val->v_quad < 0) { - /* comparision of %s with %s, op %s */ + /* comparison of %s with %s, op %s */ warning(162, "negative constant", tyname(rn->tn_type), mp->m_name); } else if (op == GT || op == LE || (hflag && op == GE)) { - /* comparision of %s with %s, op %s */ + /* comparison of %s with %s, op %s */ warning(162, "0", tyname(rn->tn_type), mp->m_name); } return; @@ -3747,10 +3692,7 @@ chkcomp(op, ln, rn) * representation (including width). */ int -conaddr(tn, symp, offsp) - tnode_t *tn; - sym_t **symp; - ptrdiff_t *offsp; +conaddr(tnode_t *tn, sym_t **symp, ptrdiff_t *offsp) { sym_t *sym; ptrdiff_t offs1, offs2; @@ -3812,8 +3754,7 @@ conaddr(tn, symp, offsp) * Concatenate two string constants. */ strg_t * -catstrg(strg1, strg2) - strg_t *strg1, *strg2; +catstrg(strg_t *strg1, strg_t *strg2) { size_t len1, len2, len; @@ -3849,12 +3790,11 @@ catstrg(strg1, strg2) * expressions are already folded. */ static void -precconf(tn) - tnode_t *tn; +precconf(tnode_t *tn) { tnode_t *ln, *rn; - op_t lop, rop; - int lparn, rparn; + op_t lop, rop = NOOP; + int lparn, rparn = 0; mod_t *mp; int warn; @@ -3914,6 +3854,61 @@ precconf(tn) } break; /* LINTED (enumeration values not handled in switch) */ + case DECAFT: + case XORASS: + case SHLASS: + case NOOP: + case ARROW: + case ORASS: + case POINT: + case NAME: + case NOT: + case COMPL: + case CON: + case INC: + case STRING: + case DEC: + case INCBEF: + case DECBEF: + case INCAFT: + case FSEL: + case CALL: + case COMMA: + case CVT: + case ICALL: + case LOAD: + case PUSH: + case RETURN: + case INIT: + case CASE: + case FARG: + case SUBASS: + case ADDASS: + case MODASS: + case DIVASS: + case MULASS: + case ASSIGN: + case COLON: + case QUEST: + case LOGAND: + case NE: + case EQ: + case GE: + case GT: + case LE: + case LT: + case MINUS: + case PLUS: + case MOD: + case DIV: + case MULT: + case AMPER: + case STAR: + case UMINUS: + case SHRASS: + case UPLUS: + case ANDASS: + break; } if (warn) { |