]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
-Wuninitialized-const, -Wuninitialized-global
authorWolfgang Bumiller <blub@speed.at>
Fri, 28 Dec 2012 18:07:43 +0000 (19:07 +0100)
committerWolfgang Bumiller <blub@speed.at>
Fri, 28 Dec 2012 18:07:43 +0000 (19:07 +0100)
opts.c
opts.def
parser.c

diff --git a/opts.c b/opts.c
index 0594b37ce5b69f8c41dbda2c3abc627cc4b023f4..390e28413c957aa4568c2da28d882cb6bd5c1c09 100644 (file)
--- a/opts.c
+++ b/opts.c
@@ -55,6 +55,7 @@ static void opts_setdefault() {
     opts_set(opts.warn,  WARN_CPP,                       true);
     opts_set(opts.warn,  WARN_UNKNOWN_ATTRIBUTE,         true);
     opts_set(opts.warn,  WARN_RESERVED_NAMES,            true);
+    opts_set(opts.warn,  WARN_UNINITIALIZED_CONSTANT,    true);
     /* flags */
     opts_set(opts.flags, ADJUST_VECTOR_FIELDS,           true);
     opts_set(opts.flags, FTEPP,                          false);
index 1dc3d5c6c3b0800753e568aa6e13e93dc6ff4453..3c60deb7307f9759ebbdb080a0da3f6e5f86a7f9 100644 (file)
--- a/opts.def
+++ b/opts.def
@@ -80,6 +80,8 @@
     GMQCC_DEFINE_FLAG(CPP)
     GMQCC_DEFINE_FLAG(UNKNOWN_ATTRIBUTE)
     GMQCC_DEFINE_FLAG(RESERVED_NAMES)
+    GMQCC_DEFINE_FLAG(UNINITIALIZED_CONSTANT)
+    GMQCC_DEFINE_FLAG(UNINITIALIZED_GLOBAL)
 #endif
 
 #ifdef GMQCC_TYPE_OPTIMIZATIONS
index a47c6ad3b978d78a0a91b1b598e913f654a94c5f..90dc44cb91613e2db84439d10bb568ea9cf1b336 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -5145,6 +5145,14 @@ bool parser_finish(const char *output)
         if (!ast_istype(parser->globals[i], ast_value))
             continue;
         asvalue = (ast_value*)(parser->globals[i]);
+        if (asvalue->cvq == CV_CONST && !asvalue->hasvalue)
+            (void)!compile_warning(ast_ctx(asvalue), WARN_UNINITIALIZED_CONSTANT,
+                                   "uninitialized constant: `%s`",
+                                   asvalue->name);
+        else if ((asvalue->cvq == CV_NONE || asvalue->cvq == CV_CONST) && !asvalue->hasvalue)
+            (void)!compile_warning(ast_ctx(asvalue), WARN_UNINITIALIZED_GLOBAL,
+                                   "uninitialized global: `%s`",
+                                   asvalue->name);
         if (!ast_generate_accessors(asvalue, ir)) {
             ir_builder_delete(ir);
             return false;