]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
added -Wused-uninitialized and warning about variables which may be used without...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 19 Aug 2012 19:26:14 +0000 (21:26 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 19 Aug 2012 19:26:14 +0000 (21:26 +0200)
ir.c
main.c
warns.def

diff --git a/ir.c b/ir.c
index 2079dce891fc28651d4bd3d94c816edbb63a4e6b..00411a6f09a9b6ad2b49c201b4a5b9a36ac864f3 100644 (file)
--- 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 d629373511ced9d31d2e1a29614c1e1a8c7094ae..bccac37e94abc6706dd907e010cbfce08e8f248f 100644 (file)
--- 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();
index 6958a9969b78f6cff558c30e2b81c5e6b306179d..bda137029c8538b316ca5c0258b786e7f4bc22eb 100644 (file)
--- 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)