mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-18 14:21:36 +00:00
added -Wused-uninitialized and warning about variables which may be used without being initialized
This commit is contained in:
parent
ede98f5521
commit
9420c01538
3 changed files with 33 additions and 0 deletions
31
ir.c
31
ir.c
|
@ -133,6 +133,24 @@ static void irerror(lex_ctx ctx, const char *msg, ...)
|
|||
va_end(ap);
|
||||
}
|
||||
|
||||
static bool irwarning(lex_ctx ctx, int warntype, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int lvl = LVL_WARNING;
|
||||
|
||||
if (!OPTS_WARN(warntype))
|
||||
return false;
|
||||
|
||||
if (opts_werror)
|
||||
lvl = LVL_ERROR;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vprintmsg(lvl, ctx.file, ctx.line, "warning", fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return opts_werror;
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
*IR Builder
|
||||
*/
|
||||
|
@ -1802,6 +1820,19 @@ bool ir_function_calculate_liferanges(ir_function *self)
|
|||
}
|
||||
}
|
||||
} while (changed);
|
||||
if (self->blocks_count) {
|
||||
ir_block *block = self->blocks[0];
|
||||
for (i = 0; i < block->living_count; ++i) {
|
||||
ir_value *v = block->living[i];
|
||||
if (v->name[0] == '#' || v->name[0] == '%')
|
||||
continue;
|
||||
if (irwarning(v->context, WARN_USED_UNINITIALIZED,
|
||||
"variable `%s` may be used uninitialized in this function", v->name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
1
main.c
1
main.c
|
@ -383,6 +383,7 @@ int main(int argc, char **argv) {
|
|||
options_set(opts_warn, WARN_FIELD_REDECLARED, true);
|
||||
options_set(opts_warn, WARN_TOO_FEW_PARAMETERS, true);
|
||||
options_set(opts_warn, WARN_MISSING_RETURN_VALUES, true);
|
||||
options_set(opts_warn, WARN_USED_UNINITIALIZED, true);
|
||||
|
||||
if (!options_parse(argc, argv)) {
|
||||
return usage();
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
GMQCC_DEFINE_FLAG(DEBUG)
|
||||
GMQCC_DEFINE_FLAG(UNUSED_VARIABLE)
|
||||
GMQCC_DEFINE_FLAG(USED_UNINITIALIZED)
|
||||
GMQCC_DEFINE_FLAG(UNKNOWN_CONTROL_SEQUENCE)
|
||||
GMQCC_DEFINE_FLAG(EXTENSIONS)
|
||||
GMQCC_DEFINE_FLAG(FIELD_REDECLARED)
|
||||
|
|
Loading…
Reference in a new issue