diff options
author | markm <markm@FreeBSD.org> | 2002-03-03 15:12:50 +0000 |
---|---|---|
committer | markm <markm@FreeBSD.org> | 2002-03-03 15:12:50 +0000 |
commit | 8207872db749971894f9cbcb5baf92b0defdc929 (patch) | |
tree | fbbab8c077a40ec926aa302ea9349a790feb7896 /usr.bin/xlint | |
parent | 7d6830b3056aeb8b595f7f1d2b8afb86a365778d (diff) | |
download | FreeBSD-src-8207872db749971894f9cbcb5baf92b0defdc929.zip FreeBSD-src-8207872db749971894f9cbcb5baf92b0defdc929.tar.gz |
Merge conflicts, fix Makefiles and remove (re)moved file(s).
Diffstat (limited to 'usr.bin/xlint')
-rw-r--r-- | usr.bin/xlint/Makefile.inc | 19 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/Makefile | 14 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/cgram.y | 228 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/decl.c | 522 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/err.c | 122 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/func.c | 186 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/mem1.c | 82 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/scan.l | 298 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/tree.c | 594 | ||||
-rw-r--r-- | usr.bin/xlint/lint2/Makefile | 2 | ||||
-rw-r--r-- | usr.bin/xlint/lint2/mem2.c | 20 | ||||
-rw-r--r-- | usr.bin/xlint/lint2/read.c | 282 | ||||
-rw-r--r-- | usr.bin/xlint/llib/Makefile | 15 | ||||
-rw-r--r-- | usr.bin/xlint/llib/llib-lstdc | 2 | ||||
-rw-r--r-- | usr.bin/xlint/xlint/lint.1 | 168 | ||||
-rw-r--r-- | usr.bin/xlint/xlint/pathnames.h | 7 | ||||
-rw-r--r-- | usr.bin/xlint/xlint/xlint.c | 365 |
17 files changed, 1598 insertions, 1328 deletions
diff --git a/usr.bin/xlint/Makefile.inc b/usr.bin/xlint/Makefile.inc index 0a31de2..91c252b 100644 --- a/usr.bin/xlint/Makefile.inc +++ b/usr.bin/xlint/Makefile.inc @@ -1,21 +1,12 @@ # $NetBSD: Makefile.inc,v 1.8 2002/02/04 00:18:32 thorpej Exp $ +# $FreeBSD$ +WARNS= 0 .include <bsd.own.mk> .PATH: ${.CURDIR}/../common -# On the m68000, MACHINE_CPU is "m68k", but we have different -# target parameters (namely, long double is a different size -# on the m68000), so we special case the directory name here. -.if ${MACHINE_ARCH} == "m68000" -ARCHSUBDIR= m68000 -.else -ARCHSUBDIR= ${MACHINE_CPU} -.endif +CFLAGS+= -I${.CURDIR}/../arch/${MACHINE_ARCH} +CFLAGS+= -I${.CURDIR}/../common -CPPFLAGS+= -I${.CURDIR}/../arch/${ARCHSUBDIR} -CPPFLAGS+= -I${.CURDIR}/../common - -.if exists(${.CURDIR}/../../Makefile.inc) -.include "${.CURDIR}/../../Makefile.inc" -.endif +OBJECT_FMT= ELF diff --git a/usr.bin/xlint/lint1/Makefile b/usr.bin/xlint/lint1/Makefile index f9656b8..c6d39b9 100644 --- a/usr.bin/xlint/lint1/Makefile +++ b/usr.bin/xlint/lint1/Makefile @@ -3,13 +3,19 @@ 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 y.tab.h -NOMAN= -LDADD+= -ll -DPADD+= ${LIBL} + init.c emit.c emit1.c inittyp.c +MAN= lint.7 + +LDADD+= -ll -lm +DPADD+= ${LIBL} ${LIBM} CFLAGS+= -I. -I${.CURDIR} LINTFLAGS=-aehpz BINDIR= /usr/libexec .include <bsd.prog.mk> + +.PATH: ../common + +lint.7: makeman + sh ${.CURDIR}/makeman ${.OBJDIR}/${PROG} -m >${.TARGET} diff --git a/usr.bin/xlint/lint1/cgram.y b/usr.bin/xlint/lint1/cgram.y index fea9b0c..600eae2 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,14 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static char rcsid[] = "$FreeBSD$"; +#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 +__FBSDID("$FreeBSD$"); #include <stdlib.h> +#include <string.h> #include <limits.h> #include "lint1.h" @@ -55,10 +59,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 +175,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 +252,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 +276,14 @@ translation_unit: ; ext_decl: - func_def { + asm_stmnt + | func_def { glclup(0); - clrwflgs(); + CLRWFLGS(); } | data_def { glclup(0); - clrwflgs(); + CLRWFLGS(); } ; @@ -278,7 +327,7 @@ data_def: } | declspecs deftyp type_init_decls T_SEMI | error T_SEMI { - globclup(); + globclup(); } | error T_RBRACE { globclup(); @@ -712,7 +761,7 @@ enums_with_opt_comma: error(54); } else { /* trailing "," prohibited in enum declaration */ - warning(54); + (void)gnuism(54); } $$ = $1; } @@ -757,24 +806,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); } @@ -920,8 +969,7 @@ pointer: asterisk: T_MULT { - if (($$ = calloc(1, sizeof (pqinf_t))) == NULL) - nomem(); + $$ = xcalloc(1, sizeof (pqinf_t)); $$->p_pcnt = 1; } ; @@ -937,8 +985,7 @@ type_qualifier_list: type_qualifier: T_QUAL { - if (($$ = calloc(1, sizeof (pqinf_t))) == NULL) - nomem(); + $$ = xcalloc(1, sizeof (pqinf_t)); if ($1 == CONST) { $$->p_const = 1; } else { @@ -1017,10 +1064,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); } ; @@ -1053,10 +1100,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; } ; @@ -1214,15 +1267,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: @@ -1237,21 +1286,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(); } ; @@ -1264,35 +1319,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(); } ; @@ -1300,7 +1366,7 @@ iteration_stmnt: while_expr: T_WHILE T_LPARN expr T_RPARN { while1($3); - clrwflgs(); + CLRWFLGS(); } ; @@ -1319,7 +1385,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(); } ; @@ -1377,10 +1443,10 @@ read_until_rparn: declaration_list: declaration { - clrwflgs(); + CLRWFLGS(); } | declaration_list declaration { - clrwflgs(); + CLRWFLGS(); } ; @@ -1443,7 +1509,7 @@ expr: term: T_NAME { - /* XXX realy neccessary? */ + /* XXX really necessary? */ if (yychar < 0) yychar = yylex(); $$ = getnnode(getsym($1), yychar); @@ -1567,15 +1633,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. @@ -1586,8 +1671,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; @@ -1609,26 +1693,17 @@ 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 { -#ifdef XXX_BROKEN_GCC - if (v->v_quad > INT_MAX) { - /* integral constant too large */ - warning(56); - } - else if (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); } -#else - if (v->v_quad > INT_MAX || v->v_quad < INT_MIN) { - /* integral constant too large */ - warning(56); - } -#endif } } free(v); @@ -1636,25 +1711,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) @@ -1665,8 +1761,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 143840b..e59fe67 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,10 +32,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; +#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 +__FBSDID("$FreeBSD$"); #include <sys/param.h> #include <limits.h> @@ -45,9 +47,6 @@ static const char rcsid[] = 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; @@ -60,107 +59,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 */ if ((dcs = calloc(1, sizeof (dinfo_t))) == NULL) @@ -169,13 +94,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 */ if ((typetab = calloc(NTSPEC, sizeof (type_t))) == NULL) nomem(); @@ -211,15 +131,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; @@ -233,8 +152,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; @@ -248,8 +166,7 @@ tduptyp(tp) * struct, union or enum type. */ int -incompl(tp) - type_t *tp; +incompl(type_t *tp) { tspec_t t; @@ -270,9 +187,7 @@ incompl(tp) * types. */ void -setcompl(tp, ic) - type_t *tp; - int ic; +setcompl(type_t *tp, int ic) { tspec_t t; @@ -293,9 +208,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' */ @@ -330,8 +245,7 @@ addscl(sc) * struct/union/enum tag. */ void -addtype(tp) - type_t *tp; +addtype(type_t *tp) { tspec_t t; @@ -397,7 +311,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; @@ -414,7 +328,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() */ @@ -428,9 +342,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; @@ -482,7 +394,30 @@ tdeferr(td, t) } break; /* LINTED (enumeration values not handled in switch) */ - default: + 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. */ @@ -496,14 +431,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; @@ -521,13 +454,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" */ @@ -550,8 +483,7 @@ addqual(q) * argument declaration lists ...) */ void -pushdecl(sc) - scl_t sc; +pushdecl(scl_t sc) { dinfo_t *di; @@ -571,7 +503,7 @@ pushdecl(sc) * Go back to previous declaration level */ void -popdecl() +popdecl(void) { dinfo_t *di; @@ -656,7 +588,7 @@ popdecl() * global declarations/definitions. */ void -setasm() +setasm(void) { dinfo_t *di; @@ -669,8 +601,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; @@ -688,7 +621,7 @@ clrtyp() * context. */ void -deftyp() +deftyp(void) { tspec_t t, s, l; type_t *tp; @@ -804,9 +737,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; @@ -832,17 +765,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 */ @@ -875,15 +809,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) { @@ -907,8 +843,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; @@ -930,8 +865,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; @@ -1023,12 +957,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) @@ -1058,25 +992,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 */ @@ -1132,6 +1079,12 @@ decl1str(dsym) chkfdef(dsym, 0); + /* + * Clear the BITFIELDTYPE indicator after processing each + * structure element. + */ + bitfieldtype_ok = 0; + return (dsym); } @@ -1141,8 +1094,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; @@ -1153,7 +1105,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; @@ -1163,16 +1115,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); @@ -1189,14 +1140,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 { @@ -1228,16 +1179,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)); @@ -1257,15 +1208,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; @@ -1288,8 +1239,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; @@ -1319,8 +1269,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; @@ -1337,8 +1289,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; @@ -1376,9 +1327,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. @@ -1387,7 +1338,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; @@ -1406,10 +1357,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 */ @@ -1428,10 +1378,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; @@ -1494,7 +1443,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; @@ -1527,9 +1476,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 */ @@ -1556,12 +1505,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) { @@ -1595,7 +1541,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; @@ -1627,11 +1573,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;" */ @@ -1646,7 +1590,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); @@ -1682,8 +1626,7 @@ newtag(tag, scl, decl, semi) } const char * -scltoa(sc) - scl_t sc; +scltoa(scl_t sc) { const char *s; @@ -1706,9 +1649,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; @@ -1750,13 +1691,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!!! */ @@ -1797,9 +1737,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; @@ -1855,7 +1793,7 @@ decl1ext(dsym, initflg) } if (!redec && !isredec(dsym, (warn = 0, &warn))) { - + if (warn) { /* redeclaration of %s */ (*(sflag ? error : warning))(27, dsym->s_name); @@ -1901,7 +1839,7 @@ decl1ext(dsym, initflg) compltyp(dsym, rdsym); } - + rmsym(rdsym); } @@ -1918,9 +1856,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; @@ -1933,9 +1871,7 @@ cpuinfo(sym, rdsym) * a warning. */ int -isredec(dsym, warn) - sym_t *dsym; - int *warn; +isredec(sym_t *dsym, int *warn) { sym_t *rsym; @@ -2014,9 +1950,7 @@ isredec(dsym, warn) * 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; @@ -2082,9 +2016,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; @@ -2118,9 +2050,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; @@ -2145,8 +2075,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; @@ -2207,8 +2136,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; @@ -2242,9 +2170,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; @@ -2308,7 +2234,7 @@ decl1arg(sym, initflg) * prototype. */ void -cluparg() +cluparg(void) { sym_t *args, *arg, *pargs, *parg; int narg, nparg, n, msg; @@ -2422,7 +2348,7 @@ cluparg() /* from now the prototype is valid */ funcsym->s_osdef = 0; funcsym->s_args = NULL; - + } } @@ -2433,8 +2359,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; @@ -2467,10 +2392,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; @@ -2575,7 +2499,7 @@ decl1loc(dsym, initflg) if (hflag) /* declaration hides earlier one: %s */ warning(95, dsym->s_name); - + } if (dcs->d_rdcsym->s_blklev == blklev) { @@ -2609,8 +2533,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; @@ -2665,8 +2588,7 @@ ledecl(dsym) * detected. */ static int -chkinit(sym) - sym_t *sym; +chkinit(sym_t *sym) { int err; @@ -2697,7 +2619,7 @@ chkinit(sym) * Create a symbole for an abstract declaration. */ sym_t * -aname() +aname(void) { sym_t *sym; @@ -2725,8 +2647,9 @@ aname() * Removes anything which has nothing to do on global level. */ void -globclup() +globclup(void) { + while (dcs->d_nxt != NULL) popdecl(); @@ -2745,9 +2668,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); @@ -2757,9 +2680,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 @@ -2786,12 +2709,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); } } @@ -2799,13 +2722,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 @@ -2823,8 +2745,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; @@ -2844,9 +2765,7 @@ chkusage(di) * only set. */ void -chkusg1(novar, sym) - int novar; - sym_t *sym; +chkusg1(int novar, sym_t *sym) { pos_t cpos; @@ -2871,10 +2790,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"); @@ -2889,9 +2807,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; @@ -2958,9 +2874,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"); @@ -2976,9 +2892,9 @@ chklusg(lab) } static void -chktusg(sym) - sym_t *sym; +chktusg(sym_t *sym) { + if (!incompl(sym->s_type)) return; @@ -3014,7 +2930,7 @@ chktusg(sym) * - static symbols which are never used */ void -chkglsyms() +chkglsyms(void) { sym_t *sym; pos_t cpos; @@ -3041,12 +2957,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"); @@ -3088,13 +3004,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; @@ -3115,9 +3031,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/err.c b/usr.bin/xlint/lint1/err.c index 212a7d7..9dd804d 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,10 +31,17 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; +#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 +__FBSDID("$FreeBSD$"); + +#include <sys/types.h> +#include <stdlib.h> +#include <stdarg.h> + +#include "lint1.h" /* number of errors found */ int nerr; @@ -42,18 +49,10 @@ 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[] = { @@ -367,15 +366,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; @@ -393,26 +406,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; @@ -420,46 +435,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); @@ -469,66 +466,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/func.c b/usr.bin/xlint/lint1/func.c index 3421e9b..68ade02 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,16 +31,17 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; +#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 +__FBSDID("$FreeBSD$"); #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 @@ -130,6 +131,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. */ @@ -139,8 +146,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; @@ -155,8 +161,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; @@ -181,7 +186,7 @@ popctrl(env) * Prints a warning if a statement cannot be reached. */ void -chkreach() +chkreach(void) { if (!reached && !rchflg) { /* statement not reached */ @@ -201,8 +206,7 @@ chkreach() * redeclaration etc.. */ void -funcdef(fsym) - sym_t *fsym; +funcdef(sym_t *fsym) { int n, warn; sym_t *arg, *sym, *rdsym; @@ -324,7 +328,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; @@ -334,7 +338,7 @@ funcdef(fsym) * Called at the end of a function definition. */ void -funcend() +funcend(void) { sym_t *arg; int n; @@ -370,7 +374,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) { @@ -400,14 +404,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) { @@ -424,7 +426,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 */ @@ -464,30 +467,28 @@ label(typ, sym, tn) * to the type of the switch expression */ v = constant(tn); - if ((nv = calloc(1, sizeof (val_t))) == NULL) - nomem(); - 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 */ - if ((cl = calloc(1, sizeof (clst_t))) == NULL) - nomem(); - STRUCT_ASSIGN(cl->cl_val, *nv); + cl = xcalloc(1, sizeof (clst_t)); + STRUCT_ASSIGN(cl->cl_val, nv); cl->cl_nxt = ci->c_clst; ci->c_clst = cl; } @@ -498,7 +499,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 */ @@ -523,9 +525,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) @@ -539,8 +541,9 @@ if1(tn) * if_without_else T_ELSE */ void -if2() +if2(void) { + cstk->c_rchif = reached ? 1 : 0; reached = 1; } @@ -550,9 +553,9 @@ if2() * if_without_else T_ELSE stmnt */ void -if3(els) - int els; +if3(int els) { + if (els) { reached |= cstk->c_rchif; } else { @@ -565,8 +568,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; @@ -618,9 +620,9 @@ switch1(tn) * switch_expr stmnt */ void -switch2() +switch2(void) { - int nenum, nclab; + int nenum = 0, nclab = 0; sym_t *esym; clst_t *cl; @@ -673,9 +675,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); @@ -710,8 +712,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. @@ -726,8 +729,9 @@ while2() * T_DO */ void -do1() +do1(void) { + if (!reached) { /* loop not entered at top */ warning(207); @@ -743,9 +747,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. @@ -787,9 +791,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. @@ -848,7 +852,7 @@ for1(tn1, tn2, tn3) * for_exprs error */ void -for2() +for2(void) { pos_t cpos, cspos; tnode_t *tn3; @@ -893,9 +897,9 @@ for2() * T_GOTO error T_SEMI */ void -dogoto(lab) - sym_t *lab; +dogoto(sym_t *lab) { + setuflg(lab, 0, 0); chkreach(); @@ -907,7 +911,7 @@ dogoto(lab) * T_BREAK T_SEMI */ void -dobreak() +dobreak(void) { cstk_t *ci; @@ -933,11 +937,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 */ @@ -956,14 +961,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; @@ -1025,8 +1030,7 @@ doreturn(tn) * Especially remove informations about unused lint comments. */ void -glclup(silent) - int silent; +glclup(int silent) { pos_t cpos; @@ -1077,9 +1081,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; @@ -1103,9 +1107,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; @@ -1129,9 +1133,9 @@ varargs(n) * used the check the types of remaining arguments. */ void -printflike(n) - int n; +printflike(int n) { + if (n == -1) n = 0; @@ -1155,9 +1159,9 @@ printflike(n) * used the check the types of remaining arguments. */ void -scanflike(n) - int n; +scanflike(int n) { + if (n == -1) n = 0; @@ -1180,9 +1184,9 @@ scanflike(n) */ /* ARGSUSED */ void -constcond(n) - int n; +constcond(int n) { + ccflg = 1; } @@ -1192,9 +1196,9 @@ constcond(n) */ /* ARGSUSED */ void -fallthru(n) - int n; +fallthru(int n) { + ftflg = 1; } @@ -1204,18 +1208,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"); @@ -1230,21 +1234,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"); @@ -1259,8 +1281,8 @@ protolib(n) */ /* ARGSUSED */ void -longlong(n) - int n; +longlong(int n) { + quadflg = 1; } diff --git a/usr.bin/xlint/lint1/mem1.c b/usr.bin/xlint/lint1/mem1.c index 639e596..0a5a879 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,10 +31,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; +#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 +__FBSDID("$FreeBSD$"); #include <sys/types.h> #include <sys/mman.h> @@ -42,7 +43,6 @@ static const char rcsid[] = #include <stdlib.h> #include <string.h> #include <unistd.h> -#include <err.h> #include "lint1.h" @@ -58,15 +58,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; @@ -81,16 +79,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; @@ -124,8 +120,7 @@ fnnalloc(s, len) * Get id of a filename. */ int -getfnid(s) - const char *s; +getfnid(const char *s) { fn_t *fn; @@ -166,12 +161,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; @@ -186,8 +181,6 @@ xnewblk() mb->blk = mmap(NULL, mblklen, prot, flags, -1, (off_t)0); if (mb->blk == (void *)MAP_FAILED) 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; @@ -203,9 +196,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; @@ -234,8 +225,7 @@ xgetblk(mbp, s) * used memory to zero. */ static void -xfreeblk(fmbp) - mbl_t **fmbp; +xfreeblk(mbl_t **fmbp) { mbl_t *mb; @@ -248,7 +238,7 @@ xfreeblk(fmbp) } void -initmem() +initmem(void) { int pgsz; @@ -259,15 +249,14 @@ initmem() nomem(); } - + /* * Allocate memory associated with level l. */ void * -getlblk(l, s) - int l; - size_t s; +getlblk(int l, size_t s) { + while (l >= nmblks) { if ((mblks = realloc(mblks, (nmblks + ML_INC) * sizeof (mbl_t *))) == NULL) @@ -279,9 +268,9 @@ getlblk(l, s) } void * -getblk(s) - size_t s; +getblk(size_t s) { + return (getlblk(mblklev, s)); } @@ -289,15 +278,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); } @@ -308,9 +298,9 @@ freeblk() static mbl_t *tmblk; void * -tgetblk(s) - size_t s; +tgetblk(size_t s) { + return (xgetblk(&tmblk, s)); } @@ -318,17 +308,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); } @@ -338,7 +330,7 @@ tfreeblk() * used to restore the memory. */ mbl_t * -tsave() +tsave(void) { mbl_t *tmem; @@ -353,9 +345,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/scan.l b/usr.bin/xlint/lint1/scan.l index 5e06aad..9a4617f 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,9 +33,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static char rcsid[] = "$FreeBSD$"; +#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 +__FBSDID("$FreeBSD$"); #include <stdlib.h> #include <string.h> @@ -46,38 +49,40 @@ static char rcsid[] = "$FreeBSD$"; #include <math.h> #include "lint1.h" -#include "y.tab.h" +#include "cgram.h" #define CHAR_MASK (~(~0 << CHAR_BIT)) +#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); %} @@ -151,22 +156,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); } @@ -209,6 +218,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 }, @@ -235,13 +245,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; @@ -255,12 +265,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) @@ -285,21 +295,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; @@ -317,9 +327,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; } @@ -329,7 +339,7 @@ freesb(sb) * Increment line count(s) if necessary. */ static int -inpc() +inpc(void) { int c; @@ -339,8 +349,7 @@ inpc() } static int -hash(s) - const char *s; +hash(const char *s) { u_int v; const u_char *us; @@ -369,7 +378,7 @@ hash(s) * to the symbol table entry. */ static int -name() +name(void) { char *s; sbuf_t *sb; @@ -407,8 +416,7 @@ name() } static sym_t * -search(sb) - sbuf_t *sb; +search(sbuf_t *sb) { sym_t *sym; @@ -421,10 +429,9 @@ search(sb) return (NULL); } - + static int -keyw(sym) - sym_t *sym; +keyw(sym_t *sym) { int t; @@ -443,16 +450,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 }, @@ -507,7 +513,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; @@ -553,24 +559,47 @@ icon(base) } break; /* LINTED (enumeration values not handled in switch) */ - default: + 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); if ((yylval.y_val = calloc(1, sizeof(val_t))) == NULL) nomem(); yylval.y_val->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); } @@ -582,22 +611,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); @@ -606,12 +631,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); @@ -628,17 +651,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; @@ -668,7 +691,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; @@ -688,10 +711,9 @@ fcon() } static int -operator(t, o) - int t; - op_t o; +operator(int t, op_t o) { + yylval.y_op = o; return (t); } @@ -700,7 +722,7 @@ operator(t, o) * Called if lex found a leading \'. */ static int -ccon() +ccon(void) { int n, val, c; char cv; @@ -730,9 +752,8 @@ ccon() cv = (char)val; val = cv; } - - if ((yylval.y_val = calloc(1, sizeof (val_t))) == NULL) - nomem(); + + yylval.y_val = xcalloc(1, sizeof (val_t)); yylval.y_val->v_tspec = INT; yylval.y_val->v_quad = val; @@ -743,7 +764,7 @@ ccon() * Called if lex found a leading L\' */ static int -wccon() +wccon(void) { static char buf[MB_LEN_MAX + 1]; int i, c; @@ -794,11 +815,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; @@ -813,9 +833,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 '\\': @@ -838,11 +861,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': @@ -857,11 +876,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); @@ -935,7 +950,7 @@ getescc(d) * # lineno "filename" */ static void -directive() +directive(void) { const char *cp, *fn; char c, *eptr; @@ -944,9 +959,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); @@ -957,7 +973,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; @@ -968,11 +985,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 @@ -986,13 +1010,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 @@ -1007,15 +1035,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 }, @@ -1039,7 +1068,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; @@ -1105,6 +1135,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 @@ -1112,8 +1158,9 @@ comment() * (if, switch, for, while). */ void -clrwflgs() +clrwflgs(void) { + nowarn = 0; quadflg = 0; ccflg = 0; @@ -1125,7 +1172,7 @@ clrwflgs() * by the parser are responsible for freeing this buffer. */ static int -string() +string(void) { u_char *s; int c; @@ -1159,7 +1206,7 @@ string() } static int -wcstrg() +wcstrg(void) { char *s; int c, i, n, wi; @@ -1233,8 +1280,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; @@ -1282,7 +1328,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); @@ -1305,9 +1351,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; @@ -1319,8 +1365,7 @@ rmsym(sym) * table. */ void -rmsyms(syms) - sym_t *syms; +rmsyms(sym_t *syms) { sym_t *sym; @@ -1338,9 +1383,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; @@ -1360,7 +1403,7 @@ inssym(bl, sym) * level 0. */ void -cleanup() +cleanup(void) { sym_t *sym, *nsym; int i; @@ -1383,8 +1426,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; @@ -1394,7 +1436,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; @@ -1414,9 +1456,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; @@ -1434,5 +1474,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 ab14a99..edd61b0 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,10 +31,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; +#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 +__FBSDID("$FreeBSD$"); #include <stdlib.h> #include <string.h> @@ -43,51 +44,51 @@ static const char rcsid[] = #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; @@ -218,9 +219,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; @@ -234,9 +233,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; @@ -250,9 +247,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; @@ -271,9 +266,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; @@ -291,9 +284,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; @@ -339,8 +330,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; @@ -378,10 +368,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; @@ -538,9 +525,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; @@ -671,7 +656,7 @@ build(op, ln, rn) break; } - /* Return if an error occured. */ + /* Return if an error occurred. */ if (ntn == NULL) return (NULL); @@ -718,8 +703,7 @@ build(op, ln, rn) * Lvalues are converted to rvalues. */ tnode_t * -cconv(tn) - tnode_t *tn; +cconv(tnode_t *tn) { type_t *tp; @@ -763,14 +747,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]; @@ -807,12 +789,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: /* @@ -979,10 +963,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); } @@ -1134,7 +1118,32 @@ typeok(op, arg, ln, rn) nulleff(ln); break; /* LINTED (enumeration values not handled in switch) */ - default: + 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 && @@ -1150,9 +1159,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; @@ -1190,13 +1197,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; @@ -1331,9 +1335,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; @@ -1366,10 +1368,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; @@ -1408,11 +1407,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; @@ -1450,10 +1447,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; @@ -1486,10 +1480,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; @@ -1564,9 +1555,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; @@ -1641,14 +1630,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"); @@ -1694,11 +1679,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; @@ -1750,12 +1731,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; @@ -1786,7 +1762,7 @@ iiconv(op, arg, nt, ot, tp, tn) } else { warning(132, tyname(tn->tn_type)); } - } + } } } @@ -1794,12 +1770,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; @@ -1823,10 +1796,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; @@ -1857,7 +1827,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 */ @@ -1883,16 +1853,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; @@ -1923,7 +1889,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: @@ -1956,18 +1922,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; @@ -1989,7 +1955,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); @@ -2116,9 +2082,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; @@ -2150,9 +2114,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; @@ -2186,9 +2148,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()"); @@ -2214,8 +2176,7 @@ mrgqual(tpp, tp1, tp2) * (maybe recursively). */ static int -conmemb(tp) - type_t *tp; +conmemb(type_t *tp) { sym_t *m; tspec_t t; @@ -2235,8 +2196,7 @@ conmemb(tp) } const char * -tyname(tp) - type_t *tp; +tyname(type_t *tp) { tspec_t t; const char *s; @@ -2275,9 +2235,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; @@ -2329,9 +2287,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; @@ -2341,7 +2297,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); @@ -2352,13 +2308,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) @@ -2372,7 +2326,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); @@ -2382,9 +2336,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; @@ -2437,9 +2389,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; @@ -2454,8 +2404,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; @@ -2533,9 +2482,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; @@ -2596,8 +2543,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; @@ -2659,39 +2605,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; if ((v = calloc(1, sizeof (val_t))) == NULL) @@ -2703,6 +2638,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) { @@ -2718,9 +2654,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) { @@ -2765,7 +2709,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; @@ -2784,11 +2728,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; @@ -2806,10 +2746,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); @@ -2822,23 +2760,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; if ((v = calloc(1, sizeof (val_t))) == NULL) @@ -2848,22 +2776,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; } @@ -2893,12 +2813,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; if ((v = calloc(1, sizeof (val_t))) == NULL) nomem(); @@ -2971,7 +2890,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 && @@ -2994,8 +2913,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; @@ -3055,16 +2973,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; @@ -3123,8 +3039,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; @@ -3134,7 +3049,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); @@ -3146,8 +3061,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; @@ -3186,9 +3100,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; @@ -3211,14 +3123,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) { @@ -3260,10 +3173,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; @@ -3287,8 +3199,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; @@ -3341,10 +3252,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"); @@ -3383,9 +3293,9 @@ expr(tn, vctx, tctx) } static void -nulleff(tn) - tnode_t *tn; +nulleff(tnode_t *tn) { + if (!hflag) return; @@ -3404,7 +3314,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 @@ -3430,11 +3340,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"); @@ -3489,9 +3397,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; @@ -3584,7 +3491,44 @@ chkmisc(tn, vctx, tctx, eqwarn, fcall, rvdisc, szof) case STRING: return; /* LINTED (enumeration values not handled in switch) */ - default: + 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; @@ -3612,6 +3556,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); @@ -3627,14 +3574,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; @@ -3650,7 +3595,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. @@ -3665,7 +3610,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; } @@ -3675,7 +3620,7 @@ 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); } @@ -3685,9 +3630,7 @@ chkaidx(tn, amper) * 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; @@ -3756,10 +3699,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; @@ -3821,8 +3761,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; @@ -3860,12 +3799,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; @@ -3925,7 +3863,61 @@ precconf(tn) } break; /* LINTED (enumeration values not handled in switch) */ - default: + 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) { diff --git a/usr.bin/xlint/lint2/Makefile b/usr.bin/xlint/lint2/Makefile index 404c1fb..63c518f 100644 --- a/usr.bin/xlint/lint2/Makefile +++ b/usr.bin/xlint/lint2/Makefile @@ -4,7 +4,7 @@ .PATH: ${.CURDIR}/../lint1 PROG= lint2 -SRCS= main2.c hash.c read.c mem.c mem2.c chk.c msg.c emit.c emit2.c +SRCS= main2.c hash.c read.c mem.c mem2.c chk.c msg.c emit.c emit2.c inittyp.c NOMAN= CFLAGS+=-I${.CURDIR}/../lint1 LINTFLAGS=-abehrz diff --git a/usr.bin/xlint/lint2/mem2.c b/usr.bin/xlint/lint2/mem2.c index dffeb1c..ebc4d13 100644 --- a/usr.bin/xlint/lint2/mem2.c +++ b/usr.bin/xlint/lint2/mem2.c @@ -1,4 +1,4 @@ -/* $NetBSD: mem2.c,v 1.3 1995/10/02 17:27:11 jpo Exp $ */ +/* $NetBSD: mem2.c,v 1.6 2002/01/21 19:49:52 tv Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -31,17 +31,17 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; +#include <sys/cdefs.h> +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: mem2.c,v 1.6 2002/01/21 19:49:52 tv Exp $"); #endif +__FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/types.h> #include <sys/mman.h> #include <unistd.h> #include <string.h> -#include <err.h> #include "lint2.h" @@ -55,7 +55,7 @@ static size_t nxtfree; static void *mbuf; void -initmem() +initmem(void) { int pgsz; @@ -71,13 +71,13 @@ initmem() * need never to be freed. */ void * -xalloc(sz) - size_t sz; +xalloc(size_t sz) { void *ptr; int prot, flags; - sz = ALIGN(sz); + /* Align to at least 8 bytes. */ + sz = (sz + 7) & ~7L; if (nxtfree + sz > mblklen) { /* use mmap() instead of malloc() to avoid malloc overhead. */ prot = PROT_READ | PROT_WRITE; @@ -85,8 +85,6 @@ xalloc(sz) mbuf = mmap(NULL, mblklen, prot, flags, -1, (off_t)0); if (mbuf == (void *)MAP_FAILED) err(1, "can't map memory"); - if (ALIGN((u_long)mbuf) != (u_long)mbuf) - errx(1, "mapped address is not aligned"); (void)memset(mbuf, 0, mblklen); nxtfree = 0; } diff --git a/usr.bin/xlint/lint2/read.c b/usr.bin/xlint/lint2/read.c index 0f160bc..05c7be8 100644 --- a/usr.bin/xlint/lint2/read.c +++ b/usr.bin/xlint/lint2/read.c @@ -1,6 +1,7 @@ -/* $NetBSD: read.c,v 1.2 1995/07/03 21:24:59 cgd Exp $ */ +/* $NetBSD: read.c,v 1.12 2002/01/21 19:49:52 tv Exp $ */ /* + * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. * Copyright (c) 1994, 1995 Jochen Pohl * All Rights Reserved. * @@ -31,17 +32,17 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; +#include <sys/cdefs.h> +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: read.c,v 1.12 2002/01/21 19:49:52 tv Exp $"); #endif +__FBSDID("$FreeBSD$"); +#include <ctype.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <ctype.h> -#include <limits.h> -#include <err.h> #include "lint2.h" @@ -79,33 +80,34 @@ static thtab_t **thtab; /* hash table */ type_t **tlst; /* array for indexed access */ static size_t tlstlen; /* length of tlst */ +static hte_t **renametab; + /* index of current C source file (as spezified at the command line) */ static int csrcfile; -static void inperr __P((void)); -static void setsrc __P((const char *)); -static void setfnid __P((int, const char *)); -static void funccall __P((pos_t *, const char *)); -static void decldef __P((pos_t *, const char *)); -static void usedsym __P((pos_t *, const char *)); -static u_short inptype __P((const char *, const char **)); -static int gettlen __P((const char *, const char **)); -static u_short findtype __P((const char *, size_t, int)); -static u_short storetyp __P((type_t *, const char *, size_t, int)); -static int thash __P((const char *, size_t)); -static char *inpqstrg __P((const char *, const char **)); -static const char *inpname __P((const char *, const char **)); -static int getfnidx __P((const char *)); +static void inperr(void); +static void setsrc(const char *); +static void setfnid(int, const char *); +static void funccall(pos_t *, const char *); +static void decldef(pos_t *, const char *); +static void usedsym(pos_t *, const char *); +static u_short inptype(const char *, const char **); +static int gettlen(const char *, const char **); +static u_short findtype(const char *, size_t, int); +static u_short storetyp(type_t *, const char *, size_t, int); +static int thash(const char *, size_t); +static char *inpqstrg(const char *, const char **); +static const char *inpname(const char *, const char **); +static int getfnidx(const char *); void -readfile(name) - const char *name; +readfile(const char *name) { FILE *inp; size_t len; const char *cp; - char *line, *eptr, rt; + char *line, *eptr, rt = '\0'; int cline, isrc, iline; pos_t pos; @@ -122,6 +124,8 @@ readfile(name) if ((thtab = calloc(THSHSIZ2, sizeof (thtab_t))) == NULL) nomem(); + _inithash(&renametab); + srcfile = getfnidx(name); if ((inp = fopen(name, "r")) == NULL) @@ -198,6 +202,8 @@ readfile(name) } + _destroyhash(renametab); + if (ferror(inp)) err(1, "read error on %s", name); @@ -206,8 +212,9 @@ readfile(name) static void -inperr() +inperr(void) { + errx(1, "input file error: %s", fnames[srcfile]); } @@ -216,23 +223,22 @@ inperr() * currently read. */ static void -setsrc(cp) - const char *cp; +setsrc(const char *cp) { + csrcfile = getfnidx(cp); } /* * setfnid() gets as input an index as used in an input file and the - * associated file name. If neccessary, it creates a new lint2 file + * associated file name. If necessary, it creates a new lint2 file * name index for this file name and creates the mapping of the index * as used in the input file to the index used in lint2. */ static void -setfnid(fid, cp) - int fid; - const char *cp; +setfnid(int fid, const char *cp) { + if (fid == -1) inperr(); @@ -256,15 +262,14 @@ setfnid(fid, cp) * Process a function call record (c-record). */ static void -funccall(posp, cp) - pos_t *posp; - const char *cp; +funccall(pos_t *posp, const char *cp) { arginf_t *ai, **lai; char c, *eptr; int rused, rdisc; hte_t *hte; fcall_t *fcall; + const char *name; fcall = xalloc(sizeof (fcall_t)); STRUCT_ASSIGN(fcall->f_pos, *posp); @@ -318,7 +323,14 @@ funccall(posp, cp) fcall->f_rdisc = rdisc; /* read name of function */ - hte = hsearch(inpname(cp, &cp), 1); + name = inpname(cp, &cp); + + /* first look it up in the renaming table, then in the normal table */ + hte = _hsearch(renametab, name, 0); + if (hte != NULL) + hte = hte->h_hte; + else + hte = hsearch(name, 1); hte->h_used = 1; fcall->f_type = inptype(cp, &cp); @@ -334,14 +346,13 @@ funccall(posp, cp) * Process a declaration or definition (d-record). */ static void -decldef(posp, cp) - pos_t *posp; - const char *cp; +decldef(pos_t *posp, const char *cp) { sym_t *symp, sym; - char c, *ep; - int used; - hte_t *hte; + char c, *ep, *pos1; + int used, renamed; + hte_t *hte, *renamehte = NULL; + const char *name, *rename; (void)memset(&sym, 0, sizeof (sym)); STRUCT_ASSIGN(sym.s_pos, *posp); @@ -419,8 +430,35 @@ decldef(posp, cp) } } - /* read symbol name */ - hte = hsearch(inpname(cp, &cp), 1); + /* read symbol name, doing renaming if necessary */ + name = inpname(cp, &cp); + renamed = 0; + if (*cp == 'r') { + cp++; + name = xstrdup(name); + rename = inpname(cp, &cp); + + /* enter it and see if it's already been renamed */ + renamehte = _hsearch(renametab, name, 1); + if (renamehte->h_hte == NULL) { + hte = hsearch(rename, 1); + renamehte->h_hte = hte; + renamed = 1; + } else if (strcmp((hte = renamehte->h_hte)->h_name, rename)) { + pos1 = xstrdup(mkpos(&renamehte->h_syms->s_pos)); + /* %s renamed multiple times\t%s :: %s */ + msg(18, name, pos1, mkpos(&sym.s_pos)); + free(pos1); + } + free((char *)name); + } else { + /* it might be a previously-done rename */ + hte = _hsearch(renametab, name, 0); + if (hte != NULL) + hte = hte->h_hte; + else + hte = hsearch(name, 1); + } hte->h_used |= used; if (sym.s_def == DEF || sym.s_def == TDEF) hte->h_def = 1; @@ -456,6 +494,10 @@ decldef(posp, cp) } *hte->h_lsym = symp; hte->h_lsym = &symp->s_nxt; + + /* XXX hack so we can remember where a symbol was renamed */ + if (renamed) + renamehte->h_syms = symp; } if (*cp != '\0') @@ -466,12 +508,11 @@ decldef(posp, cp) * Read an u-record (emited by lint1 if a symbol was used). */ static void -usedsym(posp, cp) - pos_t *posp; - const char *cp; +usedsym(pos_t *posp, const char *cp) { usym_t *usym; hte_t *hte; + const char *name; usym = xalloc(sizeof (usym_t)); STRUCT_ASSIGN(usym->u_pos, *posp); @@ -480,7 +521,12 @@ usedsym(posp, cp) if (*cp++ != 'x') inperr(); - hte = hsearch(inpname(cp, &cp), 1); + name = inpname(cp, &cp); + hte = _hsearch(renametab, name, 0); + if (hte != NULL) + hte = hte->h_hte; + else + hte = hsearch(name, 1); hte->h_used = 1; *hte->h_lusym = usym; @@ -491,13 +537,12 @@ usedsym(posp, cp) * Read a type and return the index of this type. */ static u_short -inptype(cp, epp) - const char *cp, **epp; +inptype(const char *cp, const char **epp) { char c, s, *eptr; const char *ep; type_t *tp; - int narg, i, osdef; + int narg, i, osdef = 0; size_t tlen; u_short tidx; int h; @@ -608,8 +653,6 @@ inptype(cp, epp) case STRUCT: case UNION: switch (*cp++) { - case '0': - break; case '1': tp->t_istag = 1; tp->t_tag = hsearch(inpname(cp, &cp), 1); @@ -618,10 +661,42 @@ inptype(cp, epp) tp->t_istynam = 1; tp->t_tynam = hsearch(inpname(cp, &cp), 1); break; + case '3': + tp->t_isuniqpos = 1; + tp->t_uniqpos.p_line = strtol(cp, &eptr, 10); + cp = eptr; + cp++; + /* xlate to 'global' file name. */ + tp->t_uniqpos.p_file = + addoutfile(inpfns[strtol(cp, &eptr, 10)]); + cp = eptr; + cp++; + tp->t_uniqpos.p_uniq = strtol(cp, &eptr, 10); + cp = eptr; + break; } break; - /* LINTED (enumeration value(s) not handled in switch) */ - default: + case LONG: + case VOID: + case LDOUBLE: + case DOUBLE: + case FLOAT: + case UQUAD: + case QUAD: + case ULONG: + case UINT: + case INT: + case USHORT: + case SHORT: + case UCHAR: + case SCHAR: + case CHAR: + case UNSIGN: + case SIGNED: + case NOTSPEC: + break; + case NTSPEC: + abort(); } *epp = cp; @@ -632,8 +707,7 @@ inptype(cp, epp) * Get the length of a type string. */ static int -gettlen(cp, epp) - const char *cp, **epp; +gettlen(const char *cp, const char **epp) { const char *cp1; char c, s, *eptr; @@ -778,20 +852,56 @@ gettlen(cp, epp) case STRUCT: case UNION: switch (*cp++) { - case '0': - break; case '1': (void)inpname(cp, &cp); break; case '2': (void)inpname(cp, &cp); break; + case '3': + /* unique position: line.file.uniquifier */ + (void)strtol(cp, &eptr, 10); + if (cp == eptr) + inperr(); + cp = eptr; + if (*cp++ != '.') + inperr(); + (void)strtol(cp, &eptr, 10); + if (cp == eptr) + inperr(); + cp = eptr; + if (*cp++ != '.') + inperr(); + (void)strtol(cp, &eptr, 10); + if (cp == eptr) + inperr(); + cp = eptr; + break; default: inperr(); } break; - /* LINTED (enumeration value(s) not handled in switch) */ - default: + case FLOAT: + case USHORT: + case SHORT: + case UCHAR: + case SCHAR: + case CHAR: + case UNSIGN: + case SIGNED: + case NOTSPEC: + case INT: + case UINT: + case DOUBLE: + case LDOUBLE: + case VOID: + case ULONG: + case QUAD: + case UQUAD: + case LONG: + break; + case NTSPEC: + abort(); } *epp = cp; @@ -802,10 +912,7 @@ gettlen(cp, epp) * Search a type by it's type string. */ static u_short -findtype(cp, len, h) - const char *cp; - size_t len; - int h; +findtype(const char *cp, size_t len, int h) { thtab_t *thte; @@ -824,14 +931,9 @@ findtype(cp, len, h) * if we read the same type string from the input file. */ static u_short -storetyp(tp, cp, len, h) - type_t *tp; - const char *cp; - size_t len; - int h; +storetyp(type_t *tp, const char *cp, size_t len, int h) { - /* 0 ist reserved */ - static u_int tidx = 1; + static u_int tidx = 1; /* 0 is reserved */ thtab_t *thte; char *name; @@ -866,9 +968,7 @@ storetyp(tp, cp, len, h) * Hash function for types */ static int -thash(s, len) - const char *s; - size_t len; +thash(const char *s, size_t len) { u_int v; @@ -884,8 +984,7 @@ thash(s, len) * Read a string enclosed by "". This string may contain quoted chars. */ static char * -inpqstrg(src, epp) - const char *src, **epp; +inpqstrg(const char *src, const char **epp) { char *strg, *dst; size_t slen; @@ -912,11 +1011,7 @@ inpqstrg(src, epp) c = '\t'; break; case 'v': -#ifdef __STDC__ c = '\v'; -#else - c = '\013'; -#endif break; case 'b': c = '\b'; @@ -928,11 +1023,7 @@ inpqstrg(src, epp) c = '\f'; break; case 'a': -#ifdef __STDC__ c = '\a'; -#else - c = '\007'; -#endif break; case '\\': c = '\\'; @@ -978,8 +1069,7 @@ inpqstrg(src, epp) * Read the name of a symbol in static memory. */ static const char * -inpname(cp, epp) - const char *cp, **epp; +inpname(const char *cp, const char **epp) { static char *buf; static size_t blen = 0; @@ -995,7 +1085,7 @@ inpname(cp, epp) nomem(); for (i = 0; i < len; i++) { c = *cp++; - if (!isalnum(c) && c != '_') + if (!isalnum((unsigned char)c) && c != '_') inperr(); buf[i] = c; } @@ -1010,8 +1100,7 @@ inpname(cp, epp) * a new entry and return the index of the newly created entry. */ static int -getfnidx(fn) - const char *fn; +getfnidx(const char *fn) { int i; @@ -1040,8 +1129,7 @@ getfnidx(fn) * Separate symbols with static and external linkage. */ void -mkstatic(hte) - hte_t *hte; +mkstatic(hte_t *hte) { sym_t *sym1, **symp, *sym; fcall_t **callp, *call; @@ -1085,16 +1173,22 @@ mkstatic(hte) * XXX this entry should be put at the beginning of the list to * avoid to process the same symbol twice. */ - for (nhte = hte; nhte->h_link != NULL; nhte = nhte->h_link) ; - nhte->h_link = xalloc(sizeof (hte_t)); + for (nhte = hte; nhte->h_link != NULL; nhte = nhte->h_link) + continue; + nhte->h_link = xmalloc(sizeof (hte_t)); nhte = nhte->h_link; nhte->h_name = hte->h_name; - nhte->h_static = 1; nhte->h_used = 1; nhte->h_def = 1; /* error in lint1 */ + nhte->h_static = 1; + nhte->h_syms = NULL; nhte->h_lsym = &nhte->h_syms; + nhte->h_calls = NULL; nhte->h_lcall = &nhte->h_calls; + nhte->h_usyms = NULL; nhte->h_lusym = &nhte->h_usyms; + nhte->h_link = NULL; + nhte->h_hte = NULL; /* * move all symbols used in this translation unit into the new diff --git a/usr.bin/xlint/llib/Makefile b/usr.bin/xlint/llib/Makefile index 2c569f5..7a8c3b9 100644 --- a/usr.bin/xlint/llib/Makefile +++ b/usr.bin/xlint/llib/Makefile @@ -1,22 +1,25 @@ -# $NetBSD: Makefile,v 1.2 1995/07/03 21:25:05 cgd Exp $ +# $NetBSD: Makefile,v 1.7 2000/06/14 20:22:19 matt Exp $ # $FreeBSD$ +.include <bsd.own.mk> + LIBS= llib-lposix.ln llib-lstdc.ln LINT= ${.OBJDIR}/../xlint/xlint -all: ${LIBS} +.if ${MKLINT} != "no" +FILES= ${LIBS} +FILESDIR= ${LINTLIBDIR} install: ${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${LIBMODE} \ ${LIBS} ${DESTDIR}${LINTLIBDIR} -clean cleanall: - rm -f ${LIBS} +CLEANFILES+= ${LIBS} llib-lposix.ln: llib-lposix - ${LINT} -Cposix ${.ALLSRC} + ${LINT} ${LINTFLAGS} -Cposix ${.ALLSRC} llib-lstdc.ln: llib-lstdc - ${LINT} -Cstdc ${.ALLSRC} + ${LINT} ${LINTFLAGS} -Cstdc ${.ALLSRC} .include <bsd.prog.mk> diff --git a/usr.bin/xlint/llib/llib-lstdc b/usr.bin/xlint/llib/llib-lstdc index 5ad0ec3..83b44f2 100644 --- a/usr.bin/xlint/llib/llib-lstdc +++ b/usr.bin/xlint/llib/llib-lstdc @@ -1,4 +1,4 @@ -/* $NetBSD: llib-lstdc,v 1.3 1995/07/03 21:39:28 cgd Exp $ */ +/* $NetBSD: llib-lstdc,v 1.2 1995/07/03 21:25:11 cgd Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl diff --git a/usr.bin/xlint/xlint/lint.1 b/usr.bin/xlint/xlint/lint.1 index dfa6143..5c86f9d 100644 --- a/usr.bin/xlint/xlint/lint.1 +++ b/usr.bin/xlint/xlint/lint.1 @@ -1,5 +1,6 @@ -.\" $NetBSD: lint.1,v 1.3 1995/10/23 13:45:31 jpo Exp $ +.\" $NetBSD: lint.1,v 1.20 2001/12/08 19:27:56 wiz Exp $ .\" +.\" Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. .\" Copyright (c) 1994, 1995 Jochen Pohl .\" All Rights Reserved. .\" @@ -31,40 +32,82 @@ .\" .\" $FreeBSD$ .\" -.Dd August 28, 1994 +.Dd May 24, 2001 .Dt LINT 1 .Os .Sh NAME .Nm lint .Nd a C program verifier .Sh SYNOPSIS -.Bk -words .Nm -.Op Fl abceghprvxzHFV -.Op Fl s | t -.Op Fl i | nu -.Op Fl D Ar name Ns Op = Ns Ar def +.Op Fl abceghprvwxzHFV +.Bk -words +.Op Fl s | Fl t +.Ek +.Bk -words +.Op Fl i | Fl nu +.Ek +.Bk -words +.Op Fl D Ar name Ns Op =def +.Ek +.Bk -words .Op Fl U Ar name +.Ek +.Bk -words .Op Fl I Ar directory +.Ek +.Bk -words +.Op Fl d Ar directory +.Ek +.Bk -words .Op Fl L Ar directory +.Ek +.Bk -words .Op Fl l Ar library +.Ek +.Bk -words .Op Fl o Ar outputfile +.Ek +.Bk -words +.Op Fl B Ar directory +.Ek +.Bk -words +.Op Fl X Ar id Ns Op ,id ... +.Ek .Ar -.Nm -.Op Fl abceghprvzHFV -.Op Fl s | t +.Nm lint +.Op Fl abceghprvwzHFV +.Bk -words +.Op Fl s | Fl t +.Ek +.Bk -words .Fl C Ar library -.Op Fl D Ar name Ns Op = Ns Ar def -.Op Fl I Ar directory +.Ek +.Bk -words +.Op Fl D Ar name Ns Op =def +.Ek +.Bk -words .Op Fl U Ar name +.Ek +.Bk -words +.Op Fl I Ar directory +.Ek +.Bk -words +.Op Fl d Ar directory +.Ek +.Bk -words +.Op Fl B Ar directory +.Ek +.Bk -words +.Op Fl X Ar id Ns Op ,id ... +.Ek .Ar .Ek .Sh DESCRIPTION .Nm attempts to detect features of the named C program files that are likely to be bugs, to be non-portable, or to be -wasteful. -It also performs stricter type checking than +wasteful. It also performs stricter type checking than does the C compiler. .Nm runs the C preprocessor as its first phase, with the @@ -75,7 +118,7 @@ or skipped by .Nm . Therefore, this symbol should be thought of as a reserved word for all code that is to be checked by -.Nm . +.Nm "" . .Pp Among the possible problems that are currently noted are unreachable statements, loops not entered at the top, @@ -97,7 +140,7 @@ Filename arguments with names ending with .Pa .ln are taken to be the result of an earlier invocation of -.Nm , +.Nm "" , with either the .Fl i , o , or @@ -153,8 +196,24 @@ if a complaint stems not from a given source file, but from one of its included files, the source filename will be printed followed by a question mark. .Pp -The options are as follows: -.Bl -tag -width indent +The special input file name +.Dq Pa - +causes +.Nm +to take input from standard input (until end of file) and process +it as if it were a +.Pa \&.c +file. +If the +.Fl i +flag is given and +.Dq Pa - +is named as one of the input files, the +.Fl o +flag must also be specified to provide an output file name. +.Pp +.Sy Options +.Bl -tag -width Fl .It Fl a Report assignments of .Vt long @@ -185,13 +244,16 @@ Complain about unusual operations on and combinations of .Vt enum Ns - and -.Vt int Ns eger-Types . +.Sy integer Ns -Types . .It Fl g Don't print warnings for some extensions of .Xr gcc 1 to the C language. Currently these are nonconstant initializers in automatic aggregate initializations, arithmetic on pointer to void, +trailing commas in enum declarations, C++ -style +.Dq // +comments, zero sized structures, subscripting of non-lvalue arrays, prototypes overriding old style function declarations and long long integer types. @@ -200,9 +262,9 @@ The flag also turns on the keywords .Ic asm and -.Ic inline -(alternate keywords with leading underscores for both -.Ic asm +.Sy inline +(alternative keywords with leading underscores for both +.Sy asm and .Ic inline are always available). @@ -218,7 +280,7 @@ file on the command line. These .Pa .ln files are the product of -.Nm Ns 's +.Nm "" Ns 's first pass only, and are not checked for compatibility between functions. .It Fl n @@ -255,8 +317,8 @@ are defined without leading and trailing underscores. The keywords .Ic const , volatile and -.Ic signed -are not available in traditional C mode (although the alternate +.Sy signed +are not available in traditional C mode (although the alternative keywords with leading underscores still are). .It Fl u Do not complain about functions and external variables used @@ -268,13 +330,16 @@ on a subset of files comprising part of a larger program). Suppress complaints about unused arguments in functions. .It Fl x Report variables referred to by -.Ic extern +.Sy extern declarations, but never used. .It Fl z Do not complain about structures that are never defined (for example, using a structure pointer without knowing its contents). -.It Fl C Ar library +.It Fl B Ns Ar path +Path to use when looking for the lint1 and lint2 binaries. Defualts to +.Pa /usr/libexec . +.It Fl C Ns Ar library Create a .Nm library with the name @@ -305,7 +370,11 @@ is defined as 1. Add .Ar directory to the list of directories in which to search for include files. -.It Fl l Ar library +.It Fl d Ns Ar directory +Use +.Ar directory +instead of /usr/include as the default place to find include files. +.It Fl l Ns Ar library Include the lint library .Pa llib-l Ns Ar library Ns Pa .ln . .It Fl L Ar directory @@ -327,9 +396,8 @@ followed by a question mark. Name the output file .Ar outputfile . The output file produced is the input that is given to -.Nm Ns 's -second pass. -The +.Nm "" Ns 's +second pass. The .Fl o option simply saves this file in the named output file. If the @@ -351,11 +419,19 @@ for the preprocessor. .It Fl V Print the command lines constructed by the controller program to run the C preprocessor and -.Nm Ns 's +.Nm "" Ns 's first and second pass. +.It Fl w +Treat warnings as errors. +.It Fl X Ar id Ns Op ,id ... +Suppress error messages identified by the list of ids. A list of messages +and ids can be found in +.Xr lint 7 . .El -.Ss Input Grammar -.Nm Ns 's +.Pp +.Sy Input Grammar +.Pp +.Nm "" Ns 's first pass reads standard C source files. .Nm recognizes the following C comments as commands. @@ -370,11 +446,11 @@ arguments for usage; a missing is taken to be 0 (this option acts like the .Fl v option for the next function). -.It Xo -.Li /* CONSTCOND */ -or -.Li /* CONSTANTCOND */ -or +.It Li /* BITFIELDTYPE */ +Suppress error messages about illegal bitfield types if the type +is an integer type, and suppress non-portable bitfield type warnings. +.It Li /* CONSTCOND */ No or Xo +.Li /* CONSTANTCOND */ No or .Li /* CONSTANTCONDITION */ .Xc suppress complaints about constant operands for the next expression. @@ -401,11 +477,8 @@ or .Li /* NOSTRICT Oo Ar comment Oc Li */ .Xc Suppresses any intra-file warning except those dealing with -unused variables or functions. -This directive should be placed -on the line immediately preceding where the -.Nm -warning occurred. +unused variables or functions. This directive should be placed +on the line immediately preceding where the lint warning occurred. .It Li /* LONGLONG */ Suppress complaints about use of long long integer types. .It Li /* NOTREACHED */ @@ -479,7 +552,7 @@ file, and prints all messages that are about just that source file. After all the source files have been separately run through -.Nm , +.Nm "" , it is invoked once more (without the .Fl i option), listing all the @@ -497,7 +570,7 @@ to be used to .Nm only the source files that have been modified since the last time the set of source files were -.Nm Ns ed . +.Nm "" Ns No ed . .Sh ENVIRONMENT .Bl -tag -width LIBDIR .It Ev LIBDIR @@ -513,6 +586,9 @@ will be used to search for the libraries. .It Ev TMPDIR usually the path for temporary files can be redefined by setting this environment variable. +.It Ev CC +Location of the C compiler program. Defaults to +.Pa /usr/bin/cc . .El .Sh FILES .Bl -tag -width /usr/libdata/lint/llib-lc.ln -compact diff --git a/usr.bin/xlint/xlint/pathnames.h b/usr.bin/xlint/xlint/pathnames.h index 93a842a..112081c 100644 --- a/usr.bin/xlint/xlint/pathnames.h +++ b/usr.bin/xlint/xlint/pathnames.h @@ -1,4 +1,4 @@ -/* $NetBSD: pathnames.h,v 1.2 1995/07/03 21:25:20 cgd Exp $ */ +/* $NetBSD: pathnames.h,v 1.3 1999/04/22 04:40:58 mrg Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -34,7 +34,12 @@ */ /* directory where lint1 and lint2 reside */ +#ifndef PATH_LIBEXEC #define PATH_LIBEXEC "/usr/libexec" +#endif + +/* directory where cc(1) resides */ +#define PATH_USRBIN "/usr/bin" /* directory where cc(1) resides */ #define PATH_USRBIN "/usr/bin" diff --git a/usr.bin/xlint/xlint/xlint.c b/usr.bin/xlint/xlint/xlint.c index 17c12a9..b42ff19 100644 --- a/usr.bin/xlint/xlint/xlint.c +++ b/usr.bin/xlint/xlint/xlint.c @@ -1,6 +1,7 @@ -/* $NetBSD: xlint.c,v 1.3 1995/10/23 14:29:30 jpo Exp $ */ +/* $NetBSD: xlint.c,v 1.26 2002/01/22 01:14:03 thorpej Exp $ */ /* + * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. * Copyright (c) 1994, 1995 Jochen Pohl * All Rights Reserved. * @@ -31,35 +32,37 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef lint -static const char rcsid[] = - "$FreeBSD$"; +#include <sys/cdefs.h> +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: xlint.c,v 1.26 2002/01/22 01:14:03 thorpej Exp $"); #endif +__FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/wait.h> #include <sys/stat.h> #include <sys/utsname.h> +#include <errno.h> +#include <fcntl.h> +#include <paths.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> -#include <signal.h> #include <string.h> #include <unistd.h> -#include <fcntl.h> -#include <err.h> -#include <errno.h> -#include <paths.h> #include "lint.h" #include "pathnames.h" +int main(int, char *[]); + /* directory for temporary files */ static const char *tmpdir; /* path name for cpp output */ static char *cppout; -/* filedescriptor for cpp output */ +/* file descriptor for cpp output */ static int cppoutfd = -1; /* files created by 1st pass */ @@ -95,8 +98,10 @@ static char **libs; /* search path for libraries */ static char **libsrchpath; +static char *libexec_path; + /* flags */ -static int iflag, oflag, Cflag, sflag, tflag, Fflag; +static int iflag, oflag, Cflag, sflag, tflag, Fflag, dflag, Bflag; /* print the commands executed to run the stages of compilation */ static int Vflag; @@ -113,88 +118,81 @@ static int first = 1; */ static const char *currfn; - -static void appstrg __P((char ***, char *)); -static void appcstrg __P((char ***, const char *)); -static void applst __P((char ***, char *const *)); -static void freelst __P((char ***)); -static char *concat2 __P((const char *, const char *)); -static char *concat3 __P((const char *, const char *, const char *)); -static void terminate __P((int)); -static const char *basename __P((const char *, int)); -static void appdef __P((char ***, const char *)); -static void usage __P((void)); -static void fname __P((const char *, int)); -static void runchild __P((const char *, char *const *, const char *, - int)); -static void findlibs __P((char *const *)); -static int rdok __P((const char *)); -static void lint2 __P((void)); -static void cat __P((char *const *, const char *)); +#if !defined(TARGET_PREFIX) +#define TARGET_PREFIX "" +#endif +static const char target_prefix[] = TARGET_PREFIX; + +static void appstrg(char ***, char *); +static void appcstrg(char ***, const char *); +static void applst(char ***, char *const *); +static void freelst(char ***); +static char *concat2(const char *, const char *); +static char *concat3(const char *, const char *, const char *); +static void terminate(int) __attribute__((__noreturn__)); +static const char *lbasename(const char *, int); +static void appdef(char ***, const char *); +static void usage(void); +static void fname(const char *); +static void runchild(const char *, char *const *, const char *, int); +static void findlibs(char *const *); +static int rdok(const char *); +static void lint2(void); +static void cat(char *const *, const char *); /* * Some functions to deal with lists of strings. * Take care that we get no surprises in case of asyncron signals. */ static void -appstrg(lstp, s) - char ***lstp, *s; +appstrg(char ***lstp, char *s) { char **lst, **olst; int i; olst = *lstp; - for (i = 0; olst[i] != NULL; i++) ; - if ((lst = malloc((i + 2) * sizeof (char *))) == NULL) - nomem(); - (void)memcpy(lst, olst, i * sizeof (char *)); + for (i = 0; olst[i] != NULL; i++) + continue; + lst = xrealloc(olst, (i + 2) * sizeof (char *)); lst[i] = s; lst[i + 1] = NULL; *lstp = lst; -} +} static void -appcstrg(lstp, s) - char ***lstp; - const char *s; +appcstrg(char ***lstp, const char *s) { - char *p; - if ((p = strdup(s)) == NULL) - nomem(); - appstrg(lstp, p); + appstrg(lstp, xstrdup(s)); } static void -applst(destp, src) - char ***destp; - char *const *src; +applst(char ***destp, char *const *src) { int i, k; char **dest, **odest; odest = *destp; - for (i = 0; odest[i] != NULL; i++) ; - for (k = 0; src[k] != NULL; k++) ; - if ((dest = malloc((i + k + 1) * sizeof (char *))) == NULL) - nomem(); - (void)memcpy(dest, odest, i * sizeof (char *)); + for (i = 0; odest[i] != NULL; i++) + continue; + for (k = 0; src[k] != NULL; k++) + continue; + dest = xrealloc(odest, (i + k + 1) * sizeof (char *)); for (k = 0; src[k] != NULL; k++) if ((dest[i + k] = strdup(src[k])) == NULL) nomem(); dest[i + k] = NULL; *destp = dest; - free(odest); } static void -freelst(lstp) - char ***lstp; +freelst(char ***lstp) { char *s; int i; - for (i = 0; (*lstp)[i] != NULL; i++) ; + for (i = 0; (*lstp)[i] != NULL; i++) + continue; while (i-- > 0) { s = (*lstp)[i]; (*lstp)[i] = NULL; @@ -203,8 +201,7 @@ freelst(lstp) } static char * -concat2(s1, s2) - const char *s1, *s2; +concat2(const char *s1, const char *s2) { char *s; @@ -217,8 +214,7 @@ concat2(s1, s2) } static char * -concat3(s1, s2, s3) - const char *s1, *s2, *s3; +concat3(const char *s1, const char *s2, const char *s3) { char *s; @@ -235,8 +231,7 @@ concat3(s1, s2, s3) * Clean up after a signal. */ static void -terminate(signo) - int signo; +terminate(int signo) { int i; @@ -264,9 +259,7 @@ terminate(signo) * Returns strg if the string does not contain delim. */ static const char * -basename(strg, delim) - const char *strg; - int delim; +lbasename(const char *strg, int delim) { const char *cp, *cp1, *cp2; @@ -281,34 +274,41 @@ basename(strg, delim) } static void -appdef(lstp, def) - char ***lstp; - const char *def; +appdef(char ***lstp, const char *def) { + appstrg(lstp, concat2("-D__", def)); appstrg(lstp, concat3("-D__", def, "__")); } static void -usage() +usage(void) { - (void)printf("lint [-abceghprvxzHF] [-s|-t] [-i|-nu] [-Dname[=def]] [-Uname]\n"); - (void)printf(" [-Idirectory] [-Ldirectory] [-llibrary] [-ooutputfile] file ...\n"); - (void)printf("\n"); - (void)printf("lint [-abceghprvzHF] [-s|-t] -Clibrary [-Dname[=def]]\n"); - (void)printf(" [-Idirectory] [-Uname] file ...\n"); + + (void)fprintf(stderr, + "Usage: %s [-abceghprvwxzHF] [-s|-t] [-i|-nu] [-Dname[=def]]" + " [-Uname] [-X <id>[,<id>]...\n", getprogname()); + (void)fprintf(stderr, + "\t[-Idirectory] [-Ldirectory] [-llibrary] [-ooutputfile]" + " file...\n"); + (void)fprintf(stderr, + " %s [-abceghprvwzHF] [-s|-t] -Clibrary [-Dname[=def]]\n" + " [-X <id>[,<id>]...\n", getprogname()); + (void)fprintf(stderr, "\t[-Idirectory] [-Uname] [-Bpath] file" + " ...\n"); terminate(-1); } + int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { int c; char flgbuf[3], *tmp, *s; size_t len; + setprogname(argv[0]); + if ((tmp = getenv("TMPDIR")) == NULL || (len = strlen(tmp)) == 0) { if ((tmpdir = strdup(_PATH_TMP)) == NULL) nomem(); @@ -328,34 +328,30 @@ main(argc, argv) terminate(-1); } - if ((p1out = calloc(1, sizeof (char *))) == NULL) - nomem(); - if ((p2in = calloc(1, sizeof (char *))) == NULL) - nomem(); - if ((cflags = calloc(1, sizeof (char *))) == NULL) - nomem(); - if ((lcflags = calloc(1, sizeof (char *))) == NULL) - nomem(); - if ((l1flags = calloc(1, sizeof (char *))) == NULL) - nomem(); - if ((l2flags = calloc(1, sizeof (char *))) == NULL) - nomem(); - if ((l2libs = calloc(1, sizeof (char *))) == NULL) - nomem(); - if ((deflibs = calloc(1, sizeof (char *))) == NULL) - nomem(); - if ((libs = calloc(1, sizeof (char *))) == NULL) - nomem(); - if ((libsrchpath = calloc(1, sizeof (char *))) == NULL) - nomem(); + p1out = xcalloc(1, sizeof (char *)); + p2in = xcalloc(1, sizeof (char *)); + cflags = xcalloc(1, sizeof (char *)); + lcflags = xcalloc(1, sizeof (char *)); + l1flags = xcalloc(1, sizeof (char *)); + l2flags = xcalloc(1, sizeof (char *)); + l2libs = xcalloc(1, sizeof (char *)); + deflibs = xcalloc(1, sizeof (char *)); + libs = xcalloc(1, sizeof (char *)); + libsrchpath = xcalloc(1, sizeof (char *)); appcstrg(&cflags, "-E"); appcstrg(&cflags, "-x"); appcstrg(&cflags, "c"); +#if 0 appcstrg(&cflags, "-D__attribute__(x)="); + appcstrg(&cflags, "-D__extension__(x)=/*NOSTRICT*/0"); +#else + appcstrg(&cflags, "-U__GNUC__"); +#endif appcstrg(&cflags, "-Wp,-$"); - appcstrg(&cflags, "-Wp,-Cc"); + appcstrg(&cflags, "-Wp,-CC"); appcstrg(&cflags, "-Wcomment"); + appcstrg(&cflags, "-D__LINT__"); appcstrg(&cflags, "-Dlint"); /* XXX don't def. with -s */ appdef(&cflags, "lint"); @@ -370,14 +366,7 @@ main(argc, argv) (void)signal(SIGQUIT, terminate); (void)signal(SIGTERM, terminate); - while (argc > optind) { - - argc -= optind; - argv += optind; - optind = 0; - - c = getopt(argc, argv, "abceghil:no:prstuvxzC:D:FHI:L:U:V"); - + while ((c = getopt(argc, argv, "abcd:eghil:no:prstuvwxzB:C:D:FHI:L:U:VX:")) != -1) { switch (c) { case 'a': @@ -387,6 +376,7 @@ main(argc, argv) case 'g': case 'r': case 'v': + case 'w': case 'z': (void)sprintf(flgbuf, "-%c", c); appcstrg(&l1flags, flgbuf); @@ -402,6 +392,12 @@ main(argc, argv) appcstrg(&l2flags, flgbuf); break; + case 'X': + (void)sprintf(flgbuf, "-%c", c); + appcstrg(&l1flags, flgbuf); + appcstrg(&l1flags, optarg); + break; + case 'i': if (Cflag) usage(); @@ -434,19 +430,19 @@ main(argc, argv) sflag = 1; break; +#if !HAVE_CONFIG_H case 't': if (sflag) usage(); freelst(&lcflags); appcstrg(&lcflags, "-traditional"); appstrg(&lcflags, concat2("-D", MACHINE)); -#ifdef MACHINE_ARCH appstrg(&lcflags, concat2("-D", MACHINE_ARCH)); -#endif appcstrg(&l1flags, "-t"); appcstrg(&l2flags, "-t"); tflag = 1; break; +#endif case 'x': appcstrg(&l2flags, "-x"); @@ -464,6 +460,15 @@ main(argc, argv) freelst(&deflibs); break; + case 'd': + if (dflag) + usage(); + dflag = 1; + appcstrg(&cflags, "-nostdinc"); + appcstrg(&cflags, "-idirafter"); + appcstrg(&cflags, optarg); + break; + case 'D': case 'I': case 'U': @@ -491,21 +496,64 @@ main(argc, argv) appcstrg(&l2flags, "-H"); break; + case 'B': + Bflag = 1; + libexec_path = xstrdup(optarg); + break; + case 'V': Vflag = 1; break; - case '?': + default: usage(); /* NOTREACHED */ + } + } + argc -= optind; + argv += optind; + + /* + * To avoid modifying getopt(3)'s state engine midstream, we + * explicitly accept just a few options after the first source file. + * + * In particular, only -l<lib> and -L<libdir> (and these with a space + * after -l or -L) are allowed. + */ + while (argc > 0) { + const char *arg = argv[0]; + + if (arg[0] == '-') { + char ***list; + + /* option */ + switch (arg[1]) { + case 'l': + list = &libs; + break; - case -1: + case 'L': + list = &libsrchpath; + break; + + default: + usage(); + /* NOTREACHED */ + } + if (arg[2]) + appcstrg(list, arg + 2); + else if (argc > 1) { + argc--; + appcstrg(list, *++argv); + } else + usage(); + } else { /* filename */ - fname(argv[0], argc == 1); + fname(arg); first = 0; - optind = 1; } - + argc--; + argv++; } if (first) @@ -541,17 +589,17 @@ main(argc, argv) * and pass it through lint1 if it is a C source. */ static void -fname(name, last) - const char *name; - int last; +fname(const char *name) { const char *bn, *suff; char **args, *ofn, *path; size_t len; + int is_stdin; int fd; - bn = basename(name, '/'); - suff = basename(bn, '.'); + is_stdin = (strcmp(name, "-") == 0); + bn = lbasename(name, '/'); + suff = lbasename(bn, '.'); if (strcmp(suff, "ln") == 0) { /* only for lint2 */ @@ -560,14 +608,15 @@ fname(name, last) return; } - if (strcmp(suff, "c") != 0 && + if (!is_stdin && strcmp(suff, "c") != 0 && (strncmp(bn, "llib-l", 6) != 0 || bn != suff)) { warnx("unknown file type: %s\n", name); return; } - if (!iflag || !first || !last) - (void)printf("%s:\n", Fflag ? name : bn); + if (!iflag || !first) + (void)printf("%s:\n", + is_stdin ? "{standard input}" : Fflag ? name : bn); /* build the name of the output file of lint1 */ if (oflag) { @@ -575,8 +624,11 @@ fname(name, last) outputfn = NULL; oflag = 0; } else if (iflag) { - if ((ofn = malloc(strlen(bn) + (bn == suff ? 4 : 2))) == NULL) - nomem(); + if (is_stdin) { + warnx("-i not supported without -o for standard input"); + return; + } + ofn = xmalloc(strlen(bn) + (bn == suff ? 4 : 2)); len = bn == suff ? strlen(bn) : (suff - 1) - bn; (void)sprintf(ofn, "%.*s", (int)len, bn); (void)strcat(ofn, ".ln"); @@ -600,9 +652,12 @@ fname(name, last) /* run cc */ - if ((path = malloc(strlen(PATH_USRBIN) + sizeof ("/cc"))) == NULL) - nomem(); - (void)sprintf(path, "%s/cc", PATH_USRBIN); + if (getenv("CC") == NULL) { + path = xmalloc(strlen(PATH_USRBIN) + sizeof ("/cc")); + (void)sprintf(path, "%s/cc", PATH_USRBIN); + } else { + path = strdup(getenv("CC")); + } appcstrg(&args, path); applst(&args, cflags); @@ -625,9 +680,19 @@ fname(name, last) /* run lint1 */ - if ((path = malloc(strlen(PATH_LIBEXEC) + sizeof ("/lint1"))) == NULL) - nomem(); - (void)sprintf(path, "%s/lint1", PATH_LIBEXEC); + if (!Bflag) { + path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint1") + + strlen(target_prefix)); + (void)sprintf(path, "%s/%slint1", PATH_LIBEXEC, + target_prefix); + } else { + /* + * XXX Unclear whether we should be using target_prefix + * XXX here. --thorpej@wasabisystems.com + */ + path = xmalloc(strlen(libexec_path) + sizeof ("/lint1")); + (void)sprintf(path, "%s/lint1", libexec_path); + } appcstrg(&args, path); applst(&args, l1flags); @@ -645,10 +710,7 @@ fname(name, last) } static void -runchild(path, args, crfn, fdout) - const char *path, *crfn; - char *const *args; - int fdout; +runchild(const char *path, char *const *args, const char *crfn, int fdout) { int status, rv, signo, i; @@ -678,7 +740,7 @@ runchild(path, args, crfn, fdout) dup2(fdout, STDOUT_FILENO); close(fdout); } - (void)execv(path, args); + (void)execvp(path, args); warn("cannot exec %s", path); _exit(1); /* NOTREACHED */ @@ -691,7 +753,11 @@ runchild(path, args, crfn, fdout) } if (WIFSIGNALED(status)) { signo = WTERMSIG(status); +#if HAVE_DECL_SYS_SIGNAME warnx("%s got SIG%s", path, sys_signame[signo]); +#else + warnx("%s got signal %d", path, signo); +#endif terminate(-1); } if (WEXITSTATUS(status) != 0) @@ -700,8 +766,7 @@ runchild(path, args, crfn, fdout) } static void -findlibs(liblst) - char *const *liblst; +findlibs(char *const *liblst) { int i, k; const char *lib, *path; @@ -737,14 +802,13 @@ findlibs(liblst) } static int -rdok(path) - const char *path; +rdok(const char *path) { struct stat sbuf; if (stat(path, &sbuf) == -1) return (0); - if ((sbuf.st_mode & S_IFMT) != S_IFREG) + if (!S_ISREG(sbuf.st_mode)) return (0); if (access(path, R_OK) == -1) return (0); @@ -752,17 +816,27 @@ rdok(path) } static void -lint2() +lint2(void) { char *path, **args; if ((args = calloc(1, sizeof (char *))) == NULL) nomem(); - if ((path = malloc(strlen(PATH_LIBEXEC) + sizeof ("/lint2"))) == NULL) - nomem(); - (void)sprintf(path, "%s/lint2", PATH_LIBEXEC); - + if (!Bflag) { + path = xmalloc(strlen(PATH_LIBEXEC) + sizeof ("/lint2") + + strlen(target_prefix)); + (void)sprintf(path, "%s/%slint2", PATH_LIBEXEC, + target_prefix); + } else { + /* + * XXX Unclear whether we should be using target_prefix + * XXX here. --thorpej@wasabisystems.com + */ + path = xmalloc(strlen(libexec_path) + sizeof ("/lint2")); + (void)sprintf(path, "%s/lint2", libexec_path); + } + appcstrg(&args, path); applst(&args, l2flags); applst(&args, l2libs); @@ -775,9 +849,7 @@ lint2() } static void -cat(srcs, dest) - char *const *srcs; - const char *dest; +cat(char *const *srcs, const char *dest) { int ifd, ofd, i; char *src, *buf; @@ -814,4 +886,3 @@ cat(srcs, dest) (void)close(ofd); free(buf); } - |