Add -Wunused-component like -Wunused-variable but warns about unused components of vector

This commit is contained in:
Dale Weiler 2016-11-24 14:52:57 +00:00
parent eab20602b1
commit def1a26b12
4 changed files with 15 additions and 5 deletions

View 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

View file

@ -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

9
ir.cpp
View file

@ -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;
}
}

View file

@ -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)