diff options
author | Chad Loder <cloder@cvs.openbsd.org> | 2005-12-17 21:08:28 +0000 |
---|---|---|
committer | Chad Loder <cloder@cvs.openbsd.org> | 2005-12-17 21:08:28 +0000 |
commit | 832a24ed5ab2dd786f06b3a0d48e761d8b471832 (patch) | |
tree | b1f1b056d00d93ac27333e6241a853f7e2b2412a | |
parent | a7fd65d5d46c64c757fd60fb55ef5e65322d3150 (diff) |
Handle __dead functions using lint comments.
-rw-r--r-- | usr.bin/xlint/lint1/externs1.h | 3 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/func.c | 26 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/lint1.h | 3 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/scan.l | 5 | ||||
-rw-r--r-- | usr.bin/xlint/lint1/tree.c | 7 |
5 files changed, 36 insertions, 8 deletions
diff --git a/usr.bin/xlint/lint1/externs1.h b/usr.bin/xlint/lint1/externs1.h index 22e9e30a837..4bbabf1a30c 100644 --- a/usr.bin/xlint/lint1/externs1.h +++ b/usr.bin/xlint/lint1/externs1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: externs1.h,v 1.8 2005/12/12 23:35:59 cloder Exp $ */ +/* $OpenBSD: externs1.h,v 1.9 2005/12/17 21:08:27 cloder Exp $ */ /* $NetBSD: externs1.h,v 1.7 1995/10/02 17:31:39 jpo Exp $ */ /* @@ -251,6 +251,7 @@ extern void dobreak(void); extern void doreturn(tnode_t *); extern void glclup(int); extern void argsused(int); +extern void noreturn(int); extern void constcond(int); extern void fallthru(int); extern void notreach(int); diff --git a/usr.bin/xlint/lint1/func.c b/usr.bin/xlint/lint1/func.c index c3ee8e6350b..5d73a4e896b 100644 --- a/usr.bin/xlint/lint1/func.c +++ b/usr.bin/xlint/lint1/func.c @@ -1,4 +1,4 @@ -/* $OpenBSD: func.c,v 1.9 2005/12/17 20:19:46 cloder Exp $ */ +/* $OpenBSD: func.c,v 1.10 2005/12/17 21:08:27 cloder Exp $ */ /* $NetBSD: func.c,v 1.7 1995/10/02 17:31:40 jpo Exp $ */ /* @@ -33,7 +33,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: func.c,v 1.9 2005/12/17 20:19:46 cloder Exp $"; +static char rcsid[] = "$OpenBSD: func.c,v 1.10 2005/12/17 21:08:27 cloder Exp $"; #endif #include <stdlib.h> @@ -84,6 +84,12 @@ int nargusg = -1; pos_t aupos; /* + * If the following function has been declared NORETURN, noretflg is set + * to 1. Otherwise it is set to 0. + */ +int noretflg = 0; + +/* * Number of arguments of the following function definition whose types * shall be checked by lint2. -1 stands for all arguments. * @@ -387,6 +393,10 @@ funcend(void) } nargusg = -1; + if (noretflg) + funcsym->s_noreturn = 1; + noretflg = 0; + /* * write the information about the function definition to the * output file @@ -1101,6 +1111,18 @@ argsused(int n) } /* + * NORETURN comment + * + * The following function will never return, which means any code + * following a call to this function is unreachable. + */ +void +noreturn(int n) +{ + noretflg = 1; +} + +/* * VARARGS comment * * Makes that lint2 checks only the first n arguments for compatibility diff --git a/usr.bin/xlint/lint1/lint1.h b/usr.bin/xlint/lint1/lint1.h index b4b4aed8d0c..758c25cc93a 100644 --- a/usr.bin/xlint/lint1/lint1.h +++ b/usr.bin/xlint/lint1/lint1.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lint1.h,v 1.10 2005/12/10 17:41:03 cloder Exp $ */ +/* $OpenBSD: lint1.h,v 1.11 2005/12/17 21:08:27 cloder Exp $ */ /* $NetBSD: lint1.h,v 1.6 1995/10/02 17:31:41 jpo Exp $ */ /* @@ -208,6 +208,7 @@ typedef struct sym { u_int s_rimpl : 1; /* return value of function implicit decl. */ u_int s_osdef : 1; /* symbol stems from old style function def. */ u_int s_inline : 1; /* true if this is a inline function */ + u_int s_noreturn : 1; /* true if this is a NORETURN function */ struct sym *s_xsym; /* for local declared external symbols pointer to external symbol with same name */ def_t s_def; /* declared, tentative defined, defined */ diff --git a/usr.bin/xlint/lint1/scan.l b/usr.bin/xlint/lint1/scan.l index 5b91da5edef..9784df6f167 100644 --- a/usr.bin/xlint/lint1/scan.l +++ b/usr.bin/xlint/lint1/scan.l @@ -1,5 +1,5 @@ %{ -/* $OpenBSD: scan.l,v 1.25 2005/12/11 20:02:09 deraadt Exp $ */ +/* $OpenBSD: scan.l,v 1.26 2005/12/17 21:08:27 cloder Exp $ */ /* $NetBSD: scan.l,v 1.8 1995/10/23 13:38:51 jpo Exp $ */ /* @@ -34,7 +34,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: scan.l,v 1.25 2005/12/11 20:02:09 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: scan.l,v 1.26 2005/12/17 21:08:27 cloder Exp $"; #endif #include <stdlib.h> @@ -999,6 +999,7 @@ comment(void) { "CONSTCOND", 0, constcond }, { "CONSTANTCOND", 0, constcond }, { "CONSTANTCONDITION", 0, constcond }, + { "NORETURN", 1, noreturn }, { "FALLTHRU", 0, fallthru }, { "FALLTHROUGH", 0, fallthru }, { "LINTLIBRARY", 0, lintlib }, diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index e4d391615a9..e78ef4e3653 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tree.c,v 1.29 2005/12/16 03:01:35 cloder Exp $ */ +/* $OpenBSD: tree.c,v 1.30 2005/12/17 21:08:27 cloder Exp $ */ /* $NetBSD: tree.c,v 1.12 1995/10/02 17:37:57 jpo Exp $ */ /* @@ -33,7 +33,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: tree.c,v 1.29 2005/12/16 03:01:35 cloder Exp $"; +static char rcsid[] = "$OpenBSD: tree.c,v 1.30 2005/12/17 21:08:27 cloder Exp $"; #endif #include <stdlib.h> @@ -3131,6 +3131,9 @@ funccall(tnode_t *func, tnode_t *args) fcop = ICALL; } + if (func->tn_sym->s_noreturn) + notreach(0); + /* * after cconv() func will always be a pointer to a function * if it is a valid function designator. |