From: Dale Weiler Date: Thu, 24 Nov 2016 14:52:57 +0000 (+0000) Subject: Add -Wunused-component like -Wunused-variable but warns about unused components of... X-Git-Tag: xonotic-v0.8.5~50 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=def1a26b12ffdec8f8e09fb9c41459ad30f573d3;p=xonotic%2Fgmqcc.git Add -Wunused-component like -Wunused-variable but warns about unused components of vector --- diff --git a/doc/gmqcc.1 b/doc/gmqcc.1 index 78d767e..510e754 100644 --- a/doc/gmqcc.1 +++ b/doc/gmqcc.1 @@ -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 diff --git a/gmqcc.ini.example b/gmqcc.ini.example index 59a27f9..5c1ad37 100644 --- a/gmqcc.ini.example +++ b/gmqcc.ini.example @@ -348,7 +348,7 @@ [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’. @@ -356,6 +356,11 @@ 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 d6a5493..c71cad8 100644 --- 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; } } diff --git a/opts.def b/opts.def index f5ce0af..2dc4fb7 100644 --- 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)