RFQ: -R remark options

Martin Sebor msebor@gmail.com
Wed Aug 26 14:31:24 GMT 2020


On 8/26/20 7:37 AM, Nathan Sidwell wrote:
> Hi,
> I had a need to add a new type of informative message on the modules 
> branch, with an option to enable it.  The message is not a warning or an 
> error, but just 'hey, you asked if X happens.  It happens just here'. 
> This is emitted as a note.  I chose -fnote-$NAME for the option, but 
> that wasn't a very satisfactory solution.
> 
> I have learnt that clang has -R$NAME options for exactly this kind of 
> informative note.  Presumably with -Rno-$NAME negation.
> 
> Presumably we could also use this for optimization notes -- 'I failed to 
> vectorize this loop because ...'
> 
> thoughts?

I think it would be useful to issue informational messages under
the control of a dedicated option.

At the same time, it would also be helpful to make it easier to
keep notes from issuing unintentionally, when a warning is disabled
but the inform() call neglects to check the result of the prior
warning() call.

Finally, another related problem to solve is the incidental
dependency of code generation on the effect of a warning that's
sometimes introduced if a codegen decision is inadvertently made
in the block controlled by the 'if (warning ())' statement.

One idea to solve all three problems is to add an option argument
to inform() to either associate the note with it and issue the note
only when the option is enabled.  A note-only option would then
control standalone notes.

With that, the usual sequence of warning-then-note would be coded
without any tests of return values, like so:

     warning_at (warnloc, OPT_Wfoo, "this foo is bad");
     /* ... */
     inform (noteloc, OPT_Wfoo, "the last foo is here");

Admittedly, this isn't a foolproof solution as it wouldn't prevent
the note from being issued if the source code parsed in between
the calls changed the -Wfoo's disposition via a #pragma GCC
diagnostic.  To solve that, the paired warning() and inform() calls
would need to be associated more closely than by an option.  An idea
is to either change the functions to return and take a unique token
or handle as an argument.  An implementation of this scheme is to
use the auto_diagnostic_group class as this token:

   auto_diagnostic_group adg (OPT_Wfoo);
   adg.warning (warnloc, "this foo is bad");
   /* ... */
   adg.inform (noteloc, "the last foo is here"");

This approach could also work to issue just the notes (for note-
specific options).

Martin


More information about the Gcc-patches mailing list