the beginning of unititialized var detection. first victim: functions.

--undefined-function-warning is now --no-undefined-function-warning and
the default is to detect called but undefined functions.
This commit is contained in:
Bill Currie 2001-10-18 17:41:22 +00:00
parent 952f029e6d
commit 96e4e1a232
4 changed files with 13 additions and 9 deletions

View File

@ -287,6 +287,7 @@ typedef struct def_s {
const char *name;
int num_locals;
gofs_t ofs;
int initialized; // for uninit var detection
int constant; // 1 when a declaration included "= immediate"
statref_t *refs; // for relocations

View File

@ -173,7 +173,7 @@ PR_ReuseConstant (expr_t *expr, def_t *def)
if (def) {
PR_FreeLocation (def);
def->ofs = cn->ofs;
def->constant = 1;
def->initialized = def->constant = 1;
cn = def;
}
return cn;
@ -193,7 +193,7 @@ PR_ReuseConstant (expr_t *expr, def_t *def)
PR_NewDef (&type_float, ".imm", 0);
}
}
cn->constant = 1;
cn->initialized = cn->constant = 1;
// copy the immediate to the global area
if (e.type == ex_string)
e.e.integer_val = CopyString (r);

View File

@ -637,6 +637,7 @@ void
build_function (function_t *f)
{
f->def->constant = 1;
f->def->initialized = 1;
G_FUNCTION (f->def->ofs) = numfunctions;
}

View File

@ -710,10 +710,11 @@ PR_FinishCompilation (void)
if (options.undefined_function_warning)
for (d = pr.def_head.def_next; d; d = d->def_next) {
if (d->type->type == ev_func && !d->scope) { // function args ok
// f = G_FUNCTION(d->ofs);
// if (!f || (!f->code && !f->builtin))
if (!d->constant) {
warning (0, "function %s was not defined\n", d->name);
if (d->used) {
if (!d->initialized) {
warning (0, "function %s was called but not defined\n",
d->name);
}
}
}
}
@ -931,7 +932,7 @@ main (int argc, char **argv)
" --cow allow assignment to initialized globals\n"
" --id only support id (progs version 6) features\n"
" --warn=error treat warnings as errors\n"
" --undefined-function-warning warn when a function isn't defined\n"
" --no-undefined-function-warning don't warn when a function isn't defined\n"
);
return 1;
}
@ -980,8 +981,9 @@ main (int argc, char **argv)
options.warn_error = 1;
}
if (CheckParm ("--undefined-function-warning")) {
options.undefined_function_warning = 1;
options.undefined_function_warning = 1;
if (CheckParm ("--no-undefined-function-warning")) {
options.undefined_function_warning = 0;
}
if (strcmp (sourcedir, ".")) {