crash() replaced by ASSERT() & NOTREACHED() in lint

This commit is contained in:
dick 1988-09-26 11:37:38 +00:00
parent 3d549e7932
commit acf34e54ec
7 changed files with 62 additions and 62 deletions

View file

@ -790,7 +790,9 @@ dataflow.o: dataflow.h
l_lint.o: LLlex.h l_lint.o: LLlex.h
l_lint.o: Lpars.h l_lint.o: Lpars.h
l_lint.o: arith.h l_lint.o: arith.h
l_lint.o: assert.h
l_lint.o: code.h l_lint.o: code.h
l_lint.o: debug.h
l_lint.o: def.h l_lint.o: def.h
l_lint.o: expr.h l_lint.o: expr.h
l_lint.o: file_info.h l_lint.o: file_info.h
@ -851,7 +853,9 @@ l_misc.o: type.h
l_ev_ord.o: LLlex.h l_ev_ord.o: LLlex.h
l_ev_ord.o: Lpars.h l_ev_ord.o: Lpars.h
l_ev_ord.o: arith.h l_ev_ord.o: arith.h
l_ev_ord.o: assert.h
l_ev_ord.o: code.h l_ev_ord.o: code.h
l_ev_ord.o: debug.h
l_ev_ord.o: def.h l_ev_ord.o: def.h
l_ev_ord.o: expr.h l_ev_ord.o: expr.h
l_ev_ord.o: file_info.h l_ev_ord.o: file_info.h
@ -870,6 +874,8 @@ l_ev_ord.o: type.h
l_outdef.o: LLlex.h l_outdef.o: LLlex.h
l_outdef.o: Lpars.h l_outdef.o: Lpars.h
l_outdef.o: arith.h l_outdef.o: arith.h
l_outdef.o: assert.h
l_outdef.o: debug.h
l_outdef.o: def.h l_outdef.o: def.h
l_outdef.o: expr.h l_outdef.o: expr.h
l_outdef.o: field.h l_outdef.o: field.h

View file

@ -14,8 +14,11 @@
#ifdef DEBUG #ifdef DEBUG
/* Note: this macro uses parameter substitution inside strings */ /* Note: this macro uses parameter substitution inside strings */
#define ASSERT(exp) (exp || crash("in %s, %u: assertion %s failed", \ #define ASSERT(exp) (exp || crash("in %s, %u: assertion %s failed", \
__FILE__, __LINE__, "exp")) __FILE__, __LINE__, "exp"))
#define NOTREACHED() crash("in %s, %u: unreachable statement reached", \
__FILE__, __LINE__)
#else #else
#define ASSERT(exp) #define ASSERT(exp)
#define NOTREACHED()
#endif DEBUG #endif DEBUG

View file

@ -12,46 +12,53 @@
#include "arith.h" #include "arith.h"
#include "l_state.h" #include "l_state.h"
static int NOTREACHED; /* Since the lexical analyser does a one-token look-ahead, pseudo-
static int VARARGSn = -1; comments are read too soon. This is remedied by first storing them
static int ARGSUSED; in static variables and then moving them to the real variables
int LINTLIB; one token later.
*/
int s_NOTREACHED; static int notreached;
int f_VARARGSn; static int varargsN = -1;
int f_ARGSUSED; static int argsused;
static check_pseudo();
int LINTLIB; /* file is lint library */
int s_NOTREACHED; /* statement not reached */
int f_VARARGSn; /* function with variable # of args */
int f_ARGSUSED; /* function does not use all args */
set_not_reached() set_not_reached()
{ {
NOTREACHED = 1; notreached = 1;
} }
move_NOT2s() move_NOT2s()
{ {
s_NOTREACHED = NOTREACHED; s_NOTREACHED = notreached;
NOTREACHED = 0; notreached = 0;
} }
set_varargs(n) set_varargs(n)
{ {
VARARGSn = n; varargsN = n;
} }
move_VAR2f() move_VAR2f()
{ {
f_VARARGSn = VARARGSn; f_VARARGSn = varargsN;
VARARGSn = -1; varargsN = -1;
} }
set_argsused(n) set_argsused(n)
{ {
ARGSUSED = n; argsused = n;
} }
move_ARG2f() move_ARG2f()
{ {
f_ARGSUSED = ARGSUSED; f_ARGSUSED = argsused;
ARGSUSED = 0; argsused = 0;
} }
set_lintlib() set_lintlib()
@ -83,8 +90,10 @@ lint_comment(c)
i = 0; i = 0;
return; return;
} }
if (position == IN_COMMENT) if (position == IN_COMMENT)
return; return;
if (position == IN_SPACE) { if (position == IN_SPACE) {
if (c == ' ' || c == '\t') if (c == ' ' || c == '\t')
return; return;
@ -104,6 +113,7 @@ lint_comment(c)
#include <ctype.h> #include <ctype.h>
static
check_pseudo(buf, i) check_pseudo(buf, i)
char *buf; char *buf;
{ {
@ -112,17 +122,22 @@ check_pseudo(buf, i)
* (the u_nderscores are there to not confuse (UNIX) lint) * (the u_nderscores are there to not confuse (UNIX) lint)
*/ */
buf[i++] = '\0'; buf[i++] = '\0';
if (!strcmp(buf, "NOTREACHED")) if (strcmp(buf, "NOTREACHED") == 0) {
set_not_reached(); set_not_reached();
else if (!strcmp(buf, "ARGSUSED")) }
else if (strcmp(buf, "ARGSUSED") == 0) {
set_argsused(1); set_argsused(1);
else if (!strcmp(buf, "LINTLIBRARY")) }
else if (strcmp(buf, "LINTLIBRARY") == 0) {
set_lintlib(); set_lintlib();
else if (!strncmp(buf, "VARARGS", 7)) { }
if (i == 8) else if (strncmp(buf, "VARARGS", 7) == 0) {
if (i == 8) {
set_varargs(0); set_varargs(0);
else if (i == 9 && isdigit(buf[7])) }
else if (i == 9 && isdigit(buf[7])) {
set_varargs(atoi(&buf[7])); set_varargs(atoi(&buf[7]));
}
} }
} }

View file

@ -10,6 +10,7 @@
#ifdef LINT #ifdef LINT
#include <alloc.h> /* for st_free */ #include <alloc.h> /* for st_free */
#include "assert.h"
#include "arith.h" /* definition arith */ #include "arith.h" /* definition arith */
#include "label.h" /* definition label */ #include "label.h" /* definition label */
#include "expr.h" #include "expr.h"
@ -91,10 +92,7 @@ add_expr_state(value, to_state, espp)
{ {
register struct expr_state *esp = *espp; register struct expr_state *esp = *espp;
if (value.vl_class != Name) { ASSERT(value.vl_class == Name);
crash("(add_expr_state) invalid vl_class");
/*NOTREACHED*/
}
while ( esp while ( esp
&& !( esp->es_idf == value.vl_data.vl_idf && !( esp->es_idf == value.vl_data.vl_idf
&& esp->es_offset == value.vl_value && esp->es_offset == value.vl_value

View file

@ -10,6 +10,7 @@
#ifdef LINT #ifdef LINT
#include <alloc.h> /* for st_free */ #include <alloc.h> /* for st_free */
#include "assert.h"
#include "arith.h" /* definition arith */ #include "arith.h" /* definition arith */
#include "label.h" /* definition label */ #include "label.h" /* definition label */
#include "expr.h" #include "expr.h"
@ -136,7 +137,7 @@ lint_value(expr, val)
} }
default: default:
crash("(lint_expr) bad value class\n"); NOTREACHED();
/* NOTREACHED */ /* NOTREACHED */
} }
} }

View file

@ -11,6 +11,7 @@
#include <alloc.h> #include <alloc.h>
#include "arith.h" #include "arith.h"
#include "assert.h"
#include "type.h" #include "type.h"
#include "LLlex.h" #include "LLlex.h"
#include "Lpars.h" #include "Lpars.h"
@ -252,7 +253,7 @@ output_def(od)
case VU: case VU:
break; break;
default: default:
crash("(output_def) illegal class"); NOTREACHED();
/*NOTREACHED*/ /*NOTREACHED*/
} }
printf(":"); printf(":");
@ -268,10 +269,7 @@ outtypes(te, n)
register struct tp_entry *tmp; register struct tp_entry *tmp;
while (n--) { while (n--) {
if (!te) { ASSERT(te);
crash("(outtypes) not enough tp_entries");
/*NOTREACHED*/
}
printf(":"); printf(":");
if (te->te_class == Const && te->te_value >= 0) { if (te->te_class == Const && te->te_value >= 0) {
/* constant non-negative actual parameter */ /* constant non-negative actual parameter */
@ -338,7 +336,7 @@ outtype(tp)
printf("%s", symbol2str(tp->tp_fund)); printf("%s", symbol2str(tp->tp_fund));
break; break;
default: default:
crash("(outtype) illegal tp_fund"); NOTREACHED();
/*NOTREACHED*/ /*NOTREACHED*/
} }
} }

View file

@ -302,10 +302,7 @@ check_autos()
register struct auto_def *a1 = top_ls->ls_current->st_auto_list; register struct auto_def *a1 = top_ls->ls_current->st_auto_list;
register struct auto_def *a2; register struct auto_def *a2;
if (a1 && a1->ad_def->df_level > level) { ASSERT(!(a1 && a1->ad_def->df_level > level));
crash("(check_autos) corrupt level in st_auto_list");
/*NOTREACHED*/
}
while (a1 && a1->ad_def->df_level == level) { while (a1 && a1->ad_def->df_level == level) {
a2 = a1; a2 = a1;
a1 = a1->next; a1 = a1->next;
@ -331,10 +328,7 @@ check_args_used()
register struct stack_entry *se = local_level->sl_entry; register struct stack_entry *se = local_level->sl_entry;
extern int f_ARGSUSED; extern int f_ARGSUSED;
if (level != L_FORMAL1) { ASSERT(level == L_FORMAL1);
crash("(check_args_used) invalid level %d", level);
/*NOTREACHED*/
}
while (se) { while (se) {
register struct def *def = se->se_idf->id_def; register struct def *def = se->se_idf->id_def;
@ -463,16 +457,8 @@ merge_autos(a1, a2, lvl, mode)
} }
a = a2; /* pointer to the result */ a = a2; /* pointer to the result */
while (a1) { while (a1) {
if (!a2) { ASSERT(a2);
crash("(merge_autos) a1 longer than a2"); ASSERT(a1->ad_idf == a2->ad_idf);
/*NOTREACHED*/
}
if (a1->ad_idf != a2->ad_idf) {
crash("(merge_autos) identifiers should be the same %s %s",
a1->ad_idf->id_text, a2->ad_idf->id_text);
/*NOTREACHED*/
}
if (a1->ad_used) if (a1->ad_used)
a2->ad_used = 1; a2->ad_used = 1;
@ -493,10 +479,7 @@ merge_autos(a1, a2, lvl, mode)
a1 = a1->next; a1 = a1->next;
a2 = a2->next; a2 = a2->next;
} }
if (a2) { ASSERT(!a2);
crash("(merge_autos) a2 longer than a1");
/*NOTREACHED*/
}
return a; return a;
} }
@ -873,8 +856,7 @@ lint_break_stmt()
} }
break; break;
default: default:
/* bad break */ NOTREACHED();
crash("find_wdfc() returned invalid entry");
/*NOTREACHED*/ /*NOTREACHED*/
} }
top_ls->ls_current->st_notreached = 1; top_ls->ls_current->st_notreached = 1;
@ -911,10 +893,7 @@ lint_end_function()
* These auto_defs must be freed and the state must be filled * These auto_defs must be freed and the state must be filled
* with zeros. * with zeros.
*/ */
if (top_ls != &stack_bottom) { ASSERT(top_ls == &stack_bottom);
crash("(lint_end_function) top_ls != &stack_bottom");
/*NOTREACHED*/
}
if (top_ls->ls_current->st_auto_list != 0) if (top_ls->ls_current->st_auto_list != 0)
free_st_auto_list(top_ls->ls_current->st_auto_list); free_st_auto_list(top_ls->ls_current->st_auto_list);
top_ls->ls_current->st_auto_list = 0; top_ls->ls_current->st_auto_list = 0;