From: Wolfgang (Blub) Bumiller Date: Sun, 19 Aug 2012 19:26:14 +0000 (+0200) Subject: added -Wused-uninitialized and warning about variables which may be used without... X-Git-Tag: 0.1-rc1~137 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9420c01538223dc977060087e5026642cb3fbe2f;p=xonotic%2Fgmqcc.git added -Wused-uninitialized and warning about variables which may be used without being initialized --- diff --git a/ir.c b/ir.c index 2079dce..00411a6 100644 --- a/ir.c +++ b/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; } diff --git a/main.c b/main.c index d629373..bccac37 100644 --- a/main.c +++ b/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(); diff --git a/warns.def b/warns.def index 6958a99..bda1370 100644 --- a/warns.def +++ b/warns.def @@ -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)