On Sun, 2020-05-17 at 18:42 -0400, David Malcolm via Gcc-patches wrote:
> On Sun, 2020-05-17 at 18:39 -0400, David Malcolm via Gcc-patches
> wrote:
> > On Mon, 2020-05-18 at 00:05 +0200, Mark Wielaard wrote:
>
> [...snip...]
>
> > How about something like this (though I even haven't checked if it
> > compiles, and am not 100% sure what the wording should be):
> >
> > bool emit (rich_location *rich_loc) FINAL OVERRIDE
> > {
> > diagnostic_metadata m;
> > /* CWE-479: Signal Handler Use of a Non-reentrant Function. */
> > m.add_cwe (479);
>
> ...and there should be this here:
> auto_diagnostic_group d;
>
> to associate the note with the warning.
>
> > if (warning_meta (rich_loc, m,
> > OPT_Wanalyzer_unsafe_call_within_signal_handler,
> > "call to %qD from within signal handler",
> > m_unsafe_fndecl))
> > {
> > if (m_replacement)
> > {
> > gcc_rich_location note_rich_loc (gimple_location
> > (m_unsafe_call));
> > note_rich_loc.add_fixit_replace (m_replacement);
> > inform (¬e_rich_loc, "%qs is a signal-safe replacement
> > for %qD",
> > m_replacement, unsafe_fndecl);
> > }
> > return true;
> > }
> > return false;
> > }
Also, m_unsafe_fndecl is a field of signal_unsafe_call, so we can delay
calling replacement_fn until inside signal_unsafe_call::emit, after the
warning has been emitted.
It could even become a member function of signal_unsafe_call, giving
something like this for signal_unsafe_call::emit:
bool emit (rich_location *rich_loc) FINAL OVERRIDE
{
auto_diagnostic_group d;
diagnostic_metadata m;
/* CWE-479: Signal Handler Use of a Non-reentrant Function. */
m.add_cwe (479);
if (warning_meta (rich_loc, m,
OPT_Wanalyzer_unsafe_call_within_signal_handler,
"call to %qD from within signal handler",
m_unsafe_fndecl))
{
if (const char *replacement = get_replacement_fn ())
{
gcc_rich_location note_rich_loc (gimple_location (m_unsafe_call));
note_rich_loc.add_fixit_replace (replacement);
inform (¬e_rich_loc, "%qs is a signal-safe replacement for %qD",
replacement, m_unsafe_fndecl);
}
return true;
}
return false;
}