gcc 7.3 diagnostic message descriptions

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

gcc 7.3 diagnostic message descriptions

David Gilbert
Hello,

I have been scouring the net and the gcc documentation without success to
try and find a definitive description of the gcc diagnostic messages.

I am working on a project in which I need to parse the gcc compiler
diagnostics in order to automate the correction of the source code being
compiled.

For most of the diagnostics, the semantics are fairly self-evident but I am
left with a few questions:

.         In  some cases, the 'mark' line that follows an 'invalid
conversion' diagnostic description identifies the object that generated the
diagnostic with a '^' and a string of '~'s but in some cases the mark line
only contains a caret that identifies the closing parenthesis of a function
call or declaration and the column value in the diagnostic also points to
this location.  Why are there two behaviors?

.         In the case described in the first question above, I have found
that the error:/warning: diagnostic is followed by a note: diagnostic that
DOES identify the argument that provoked the diagnostic.  Is this entirely
consistent - i.e. will this 'note:' always be present?

.         What I am really trying to find is a comprehensive description of
the gcc diagnostic message syntax.  This is not in the documentation and
does not appear to be on the web either.  Can you point me at a source?

Thanks and regards,

David Gilbert

 

                David Gilbert - NIH Software

                23, chemin du Bois des Arpents

                78860 St Nom la Breteche

                [hidden email]

                Bureau:  +33-(0)9.65.03.17.15

                Mobile:  +33-(0)6-03.85.32.55

 

 

Reply | Threaded
Open this post in threaded view
|

Re: gcc 7.3 diagnostic message descriptions

Jonathan Wakely-4
On Thu, 11 Oct 2018 at 13:20, David Gilbert wrote:
>
> Hello,
>
> I have been scouring the net and the gcc documentation without success to
> try and find a definitive description of the gcc diagnostic messages.
>
> I am working on a project in which I need to parse the gcc compiler
> diagnostics in order to automate the correction of the source code being
> compiled.

I assume you're aware of the -fdiagnostics-parseable-fixits and
-fdiagnostics-generate-patch options?

They don't affect all diagnostics, only those where it makes sense and
the compiler can reliably suggest a fix.

> For most of the diagnostics, the semantics are fairly self-evident but I am
> left with a few questions:
>
> .         In  some cases, the 'mark' line that follows an 'invalid
> conversion' diagnostic description identifies the object that generated the
> diagnostic with a '^' and a string of '~'s but in some cases the mark line
> only contains a caret that identifies the closing parenthesis of a function
> call or declaration and the column value in the diagnostic also points to
> this location.  Why are there two behaviors?

Because in some cases the location info provided to the diagnostic is
just wherever the parser stopped. In some cases there's more
information.

> .         In the case described in the first question above, I have found
> that the error:/warning: diagnostic is followed by a note: diagnostic that
> DOES identify the argument that provoked the diagnostic.  Is this entirely
> consistent - i.e. will this 'note:' always be present?

I doubt it. Those diagnostics are not really designed to be machine readable.

> .         What I am really trying to find is a comprehensive description of
> the gcc diagnostic message syntax.  This is not in the documentation and
> does not appear to be on the web either.  Can you point me at a source?

I don't think there is one. There is no formal "schema" for
diagnostics. Any informal rules they're meant to follow almost
certainly aren't followed universally by all diagnostics.
Reply | Threaded
Open this post in threaded view
|

RE: gcc 7.3 diagnostic message descriptions

David Gilbert
Sigh.  I more-or-less expected your answer(s) but I thought it was worth a try.
At least for the diagnostic produced by the compiles in my project I am seeing consistency in the contents of the 'note:' entries following 'invalid conversion' messages.
Thanks for the quick reply.

-----Original Message-----
From: Jonathan Wakely [mailto:[hidden email]]
Sent: Thursday, 11 October, 2018 15:34
To: [hidden email]
Cc: gcc-help; David Malcolm
Subject: Re: gcc 7.3 diagnostic message descriptions

On Thu, 11 Oct 2018 at 13:20, David Gilbert wrote:
>
> Hello,
>
> I have been scouring the net and the gcc documentation without success
> to try and find a definitive description of the gcc diagnostic messages.
>
> I am working on a project in which I need to parse the gcc compiler
> diagnostics in order to automate the correction of the source code
> being compiled.

I assume you're aware of the -fdiagnostics-parseable-fixits and -fdiagnostics-generate-patch options?

They don't affect all diagnostics, only those where it makes sense and the compiler can reliably suggest a fix.

> For most of the diagnostics, the semantics are fairly self-evident but
> I am left with a few questions:
>
> .         In  some cases, the 'mark' line that follows an 'invalid
> conversion' diagnostic description identifies the object that
> generated the diagnostic with a '^' and a string of '~'s but in some
> cases the mark line only contains a caret that identifies the closing
> parenthesis of a function call or declaration and the column value in
> the diagnostic also points to this location.  Why are there two behaviors?

Because in some cases the location info provided to the diagnostic is just wherever the parser stopped. In some cases there's more information.

> .         In the case described in the first question above, I have found
> that the error:/warning: diagnostic is followed by a note: diagnostic
> that DOES identify the argument that provoked the diagnostic.  Is this
> entirely consistent - i.e. will this 'note:' always be present?

I doubt it. Those diagnostics are not really designed to be machine readable.

> .         What I am really trying to find is a comprehensive description of
> the gcc diagnostic message syntax.  This is not in the documentation
> and does not appear to be on the web either.  Can you point me at a source?

I don't think there is one. There is no formal "schema" for diagnostics. Any informal rules they're meant to follow almost certainly aren't followed universally by all diagnostics.

Reply | Threaded
Open this post in threaded view
|

Re: gcc 7.3 diagnostic message descriptions

Manuel López-Ibáñez
In reply to this post by David Gilbert
On top of what Jonathan already said, I would suggest the following:

On 11/10/18 13:20, David Gilbert wrote:
> I am working on a project in which I need to parse the gcc compiler
> diagnostics in order to automate the correction of the source code being
> compiled.

Any tool that wishes to automate code corrections based on diagnostics should
be built on top of -fdiagnostics-parseable-fixits and
-fdiagnostics-generate-patch options. That is what they are designed for.

If you are building a GUI, you can show humans the human-readable diagnostic
while parsing the output given by those options.

If the above is not enough, you can create a GCC plugin
https://gcc.gnu.org/wiki/plugins to dump diagnostics in some specific format
(JSON?). A good example of a plugin is the GCC Python Plugin:
https://gcc-python-plugin.readthedocs.io/en/latest/working-with-c.html#spell-checking-string-constants-within-source-code

Note that diagnostics have much more internal info (types, declarations, file
locations) than what is shown in a human-readable form, and you could add to
GCC the ability to print diagnostics in a machine-readable format that also
included all that extra info. A first attempt is here:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=19165#c10

but nowadays, using JSON instead of XML is probably best.

Modifying GCC is easier than you may think:
https://gcc.gnu.org/wiki/GettingStarted#Basics:_Contributing_to_GCC_in_10_easy_steps

> .         In  some cases, the 'mark' line that follows an 'invalid
> conversion' diagnostic description identifies the object that generated the
> diagnostic with a '^' and a string of '~'s but in some cases the mark line
> only contains a caret that identifies the closing parenthesis of a function
> call or declaration and the column value in the diagnostic also points to
> this location.  Why are there two behaviors?

In all cases where an automatic fix is possible, GCC should already produce a
correct location and a correct output of -fdiagnostics-parseable-fixits and
-fdiagnostics-generate-patch. Otherwise, it is either a bug or a pending
enhancement. Please report it: https://gcc.gnu.org/bugs/

> .         In the case described in the first question above, I have found
> that the error:/warning: diagnostic is followed by a note: diagnostic that
> DOES identify the argument that provoked the diagnostic.  Is this entirely
> consistent - i.e. will this 'note:' always be present?

If it is useful to have a note and the note is not there, please report a bug.
However, for your purposes, it will be even more useful to dump diagnostics in
a machine-readable format that can contain extra information about types,
declarations, file locations, etc.

> .         What I am really trying to find is a comprehensive description of
> the gcc diagnostic message syntax.  This is not in the documentation and
> does not appear to be on the web either.  Can you point me at a source?

As Jonathan said, the default output is designed for humans, not machines. But
it does strive to be consistent and it does follow some guidelines:
https://gcc.gnu.org/wiki/DiagnosticsGuidelines

If you find inconsistencies, please report them as bugs.

Or maybe even better, go ahead, and fix them :)

https://gcc.gnu.org/wiki/GettingStarted#Basics:_Contributing_to_GCC_in_10_easy_steps

Cheers,

        Manuel.