]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Add -Wunused-component like -Wunused-variable but warns about unused components of...
authorDale Weiler <weilercdale@gmail.com>
Thu, 24 Nov 2016 14:52:57 +0000 (14:52 +0000)
committerDale Weiler <weilercdale@gmail.com>
Thu, 24 Nov 2016 14:52:57 +0000 (14:52 +0000)
doc/gmqcc.1
gmqcc.ini.example
ir.cpp
opts.def

index 78d767e26f384ae38e8e7394a0a0d607c9f90a50..510e754d31dbe276eb4eab87e365ebe4291a4bba 100644 (file)
@@ -186,6 +186,9 @@ variables can be opened using
 .Ql #pragma noref 1
 and closed via
 .Ql #pragma noref 0 Ns .
+.It Fl W Ns Cm unused-component
+Generate a warning about vector variables which are declared but not all their
+components are used.
 .It Fl W Ns Cm used-uninitialized
 Generate a warning if it is possible that a variable can be used
 without prior initialization. Note that this warning is not
index 59a27f9a2091476bd7882b41e9bb0984774d7d4f..5c1ad3777a8c999ad7815492da0fec9f0ba3d927 100644 (file)
 
 [warnings]
     #Generate a warning about variables which are declared but never
-    #used.  This can be avoided by adding the ‘noref’ keyword in front
+    #used. This can be avoided by adding the ‘noref’ keyword in front
     #of the variable declaration. Additionally a complete section of
     #unreferenced variables can be opened using ‘#pragma noref 1’ and
     #closed via ‘#pragma noref 0’.
     UNUSED_VARIABLE = false
 
 
+    #Generate a warning about vector variables which are declared but
+    #components of it are never used.
+
+    UNUSED_COMPONENT = false
+
     #Generate a warning if it is possible that a variable can be used
     #without prior initialization. Note that this warning is not nec‐
     #essarily reliable if the initialization happens only under cer‐
diff --git a/ir.cpp b/ir.cpp
index d6a54932473b0e5df5f163ed4b8c82d6b457cbcd..c71cad8624e7e055d2a3b7e6203b9061b2656fbb 100644 (file)
--- a/ir.cpp
+++ b/ir.cpp
@@ -651,13 +651,14 @@ bool ir_function_finalize(ir_function *self)
                     // individual components are unused so mention them
                     for (size_t i = 0; i < 3; i++)
                         if ((bits & (1 << i))
-                            && irwarning(v->m_context, WARN_UNUSED_VARIABLE,
-                                "unused variable: `%s.%c`", v->m_name.c_str(), "xyz"[i]))
+                            && irwarning(v->m_context, WARN_UNUSED_COMPONENT,
+                                "unused vector component: `%s.%c`", v->m_name.c_str(), "xyz"[i]))
                             return false;
             }
             // just a standard variable
-            else if (irwarning(v->m_context, WARN_UNUSED_VARIABLE,
-                "unused variable: `%s`", v->m_name.c_str())) return false;
+            else if (v->m_name[0] != '#'
+                && irwarning(v->m_context, WARN_UNUSED_VARIABLE,
+                    "unused variable: `%s`", v->m_name.c_str())) return false;
         }
     }
 
index f5ce0af60c58c0fb00a6866935ebabe3a482b0a5..2dc4fb77cd9d8a38d3fa15422ce74b38bde3e7e2 100644 (file)
--- a/opts.def
+++ b/opts.def
@@ -44,6 +44,7 @@
     GMQCC_DEFINE_FLAG(UNINITIALIZED_GLOBAL)
     GMQCC_DEFINE_FLAG(DEBUG)
     GMQCC_DEFINE_FLAG(UNUSED_VARIABLE)
+    GMQCC_DEFINE_FLAG(UNUSED_COMPONENT)
     GMQCC_DEFINE_FLAG(USED_UNINITIALIZED)
     GMQCC_DEFINE_FLAG(UNKNOWN_CONTROL_SEQUENCE)
     GMQCC_DEFINE_FLAG(EXTENSIONS)