On Fri, 2026-01-30 at 10:30:48 +0100, Jakub Jelinek wrote:
> and then tons of spots which do suppress_warning (decl, OPT_Wunused); but
> except for the above one none that do suppress_warning (decl,
> OPT_Wunused_function);
> The first question is why Martin S. made up OPT_Wudefined-inline, that makes
> no sense, the pedwarn is about any undefined functions, not just inline.
>
> Given the number of OPT_Wunused suppressions:
> it grep suppress_warning.*Wunused[^_] .
> gcc/c/c-decl.cc: suppress_warning (olddecl, OPT_Wunused);
> gcc/c/c-typeck.cc: suppress_warning (last, OPT_Wunused);
> gcc/cp/call.cc: suppress_warning (val, OPT_Wunused);
> gcc/cp/call.cc: suppress_warning (val, OPT_Wunused);
> gcc/cp/decl2.cc: suppress_warning (decl, OPT_Wunused);
> gcc/cp/decl2.cc: suppress_warning (decl, OPT_Wunused);
> gcc/cp/decl2.cc: suppress_warning (decl, OPT_Wunused);
> gcc/cp/pt.cc: suppress_warning (decl, OPT_Wunused);
> gcc/cp/pt.cc: suppress_warning (clone, OPT_Wunused);
> gcc/cp/tree.cc: suppress_warning (TYPE_SIZE (t), OPT_Wunused);
> gcc/objc/objc-act.cc: suppress_warning (compound_expr, OPT_Wunused);
> gcc/objc/objc-act.cc: suppress_warning (compound_expr, OPT_Wunused);
> gcc/rust/backend/rust-tree.cc: suppress_warning (TYPE_SIZE (t),
> OPT_Wunused);
> and because cgraphunit.cc uses it I'd think we probably should honor and use
> that
> suppression, at least to guard the C pedwarn, and probably suppress both
> OPT_Wunused and OPT_Wunused_function in the C/C++ asm handling.
> So
> - /* TODO: Add OPT_Wundefined-inline. */
> - if (pedwarn (input_location, 0, "%q+F used but never defined",
> - decl))
> - suppress_warning (decl /* OPT_Wundefined-inline. */);
> + if (!warning_suppressed_p (decl, OPT_Wunused)
> + && pedwarn (input_location, 0, "%q+F used but never
> defined",
> + decl))
> + suppress_warning (decl, OPT_Wunused);
> and
> + else if (TREE_CODE (TREE_OPERAND (t, 0)) == FUNCTION_DECL)
> + {
> + suppress_warning (TREE_OPERAND (t, 0), OPT_Wunused);
> + suppress_warning (TREE_OPERAND (t, 0), OPT_Wunused_function);
> + }
> Or similarly to cgraphunit.cc use warning_suppressed_p (decl, OPT_Wunused)
> to guard both the pedwarn and warn_unused_function and use it in C++ FE too
> and suppress_warning (decl, OPT_Wunused); instead of OPT_Wunused_function.
>
> Note, -Wunused warning enables -Wunused-function by default, but one can
> use -Wunused -Wno-unused-function or -Wno-unused -Wunused-function and the
> warning suppression code isn't aware of that relationship and just records
> the particular OPT_* value it is called with.
The suppression code disables warning categories in nowarn_spec_t; both
are in the same category NW_LEXICAL, so they are equivalent for now.
So I think we should rather be more specific and use OPT_unused_function
in cgraphunit.cc, same as its warning.
Though this means that suppressing OPT_unused(_function) by asm will
also suppress these:
/* Lexical warnings issued by front ends. */
case OPT_Wabi:
case OPT_Wlogical_op:
case OPT_Wparentheses:
case OPT_Wreturn_type:
case OPT_Wsizeof_array_div:
case OPT_Wstrict_aliasing:
case OPT_Wunused:
case OPT_Wunused_function:
case OPT_Wunused_but_set_variable_:
case OPT_Wunused_variable:
case OPT_Wunused_but_set_parameter_:
m_bits = NW_LEXICAL;
break;
There is not much overlap, but it will suppress this without any warning:
$ cat foo.cc
static int asm_fn();
asm("" :: ":"(asm_fn));
static int asm_fn() {}
$ g++ foo.cc -Wreturn-type
(C frontend again ignores this suppression)
I presume we tolerate suppressing these whole categories only when we emit some
other warning.
So we might have to use the flag instead of suppressing.
Michal
> And, if we want to make the code even better, both in the cgraphunit.cc
> and cp/decl.cc and for the pedwarn in c/c-decl.cc use
> if ({pedwarn,warning,warning_at} (...))
> suppress_warning (decl, OPT_Wunused);
>
> Jakub
>