[1/2] diagnostics: add error_meta

Message ID 20230906135303.3643659-2-arthur.cohen@embecosm.com
State Accepted
Headers
Series [1/2] diagnostics: add error_meta |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Arthur Cohen Sept. 6, 2023, 1:53 p.m. UTC
  From: David Malcolm <dmalcolm@redhat.com>

---
 gcc/diagnostic-core.h |  3 +++
 gcc/diagnostic.cc     | 15 +++++++++++++++
 2 files changed, 18 insertions(+)
  

Comments

David Malcolm Sept. 6, 2023, 2:12 p.m. UTC | #1
On Wed, 2023-09-06 at 15:53 +0200, Arthur Cohen wrote:
> From: David Malcolm <dmalcolm@redhat.com>

I guess I can review this patch :)

Needs a ChangeLog entry, so here's one:

gcc/ChangeLog
	* diagnostic-core.h (error_meta): New decl.
	* diagnostic.cc (error_meta): New.

Also, needs a signed-off-by, so here's one:

Signed-off-by: David Malcolm <dmalcolm@redhat.com>


OK for trunk with those added.

Thanks
Dave



> 
> ---
>  gcc/diagnostic-core.h |  3 +++
>  gcc/diagnostic.cc     | 15 +++++++++++++++
>  2 files changed, 18 insertions(+)
> 
> diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h
> index 7334c79e8e6..c9e27fd2e6e 100644
> --- a/gcc/diagnostic-core.h
> +++ b/gcc/diagnostic-core.h
> @@ -92,6 +92,9 @@ extern void error_n (location_t, unsigned
> HOST_WIDE_INT, const char *,
>  extern void error_at (location_t, const char *, ...)
> ATTRIBUTE_GCC_DIAG(2,3);
>  extern void error_at (rich_location *, const char *, ...)
>    ATTRIBUTE_GCC_DIAG(2,3);
> +extern void error_meta (rich_location *, const diagnostic_metadata
> &,
> +                       const char *, ...)
> +  ATTRIBUTE_GCC_DIAG(3,4);
>  extern void fatal_error (location_t, const char *, ...)
> ATTRIBUTE_GCC_DIAG(2,3)
>       ATTRIBUTE_NORETURN;
>  /* Pass one of the OPT_W* from options.h as the second parameter. 
> */
> diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
> index c523f215bae..65c0cfbf11a 100644
> --- a/gcc/diagnostic.cc
> +++ b/gcc/diagnostic.cc
> @@ -2108,6 +2108,21 @@ error_at (rich_location *richloc, const char
> *gmsgid, ...)
>    va_end (ap);
>  }
>  
> +/* Same as above, but with metadata.  */
> +
> +void
> +error_meta (rich_location *richloc, const diagnostic_metadata
> &metadata,
> +           const char *gmsgid, ...)
> +{
> +  gcc_assert (richloc);
> +
> +  auto_diagnostic_group d;
> +  va_list ap;
> +  va_start (ap, gmsgid);
> +  diagnostic_impl (richloc, &metadata, -1, gmsgid, &ap, DK_ERROR);
> +  va_end (ap);
> +}
> +
>  /* "Sorry, not implemented."  Use for a language feature which is
>     required by the relevant specification but not implemented by
> GCC.
>     An object file will not be produced.  */
  
Arthur Cohen Sept. 6, 2023, 2:24 p.m. UTC | #2
On 9/6/23 16:12, David Malcolm wrote:
> On Wed, 2023-09-06 at 15:53 +0200, Arthur Cohen wrote:
>> From: David Malcolm <dmalcolm@redhat.com>
> 
> I guess I can review this patch :)
> 
> Needs a ChangeLog entry, so here's one:
> 
> gcc/ChangeLog
> 	* diagnostic-core.h (error_meta): New decl.
> 	* diagnostic.cc (error_meta): New.
> 
> Also, needs a signed-off-by, so here's one:
> 
> Signed-off-by: David Malcolm <dmalcolm@redhat.com>
> 

Right! Now that we enforce Changelogs and SoB lines in our CI, I 
completely forgot to add them back to older commits. I'll fix the second 
commit too. Thanks for the fast review!

> 
> OK for trunk with those added.
> 
> Thanks
> Dave
> 
> 
> 
>>
>> ---
>>   gcc/diagnostic-core.h |  3 +++
>>   gcc/diagnostic.cc     | 15 +++++++++++++++
>>   2 files changed, 18 insertions(+)
>>
>> diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h
>> index 7334c79e8e6..c9e27fd2e6e 100644
>> --- a/gcc/diagnostic-core.h
>> +++ b/gcc/diagnostic-core.h
>> @@ -92,6 +92,9 @@ extern void error_n (location_t, unsigned
>> HOST_WIDE_INT, const char *,
>>   extern void error_at (location_t, const char *, ...)
>> ATTRIBUTE_GCC_DIAG(2,3);
>>   extern void error_at (rich_location *, const char *, ...)
>>     ATTRIBUTE_GCC_DIAG(2,3);
>> +extern void error_meta (rich_location *, const diagnostic_metadata
>> &,
>> +                       const char *, ...)
>> +  ATTRIBUTE_GCC_DIAG(3,4);
>>   extern void fatal_error (location_t, const char *, ...)
>> ATTRIBUTE_GCC_DIAG(2,3)
>>        ATTRIBUTE_NORETURN;
>>   /* Pass one of the OPT_W* from options.h as the second parameter.
>> */
>> diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
>> index c523f215bae..65c0cfbf11a 100644
>> --- a/gcc/diagnostic.cc
>> +++ b/gcc/diagnostic.cc
>> @@ -2108,6 +2108,21 @@ error_at (rich_location *richloc, const char
>> *gmsgid, ...)
>>     va_end (ap);
>>   }
>>   
>> +/* Same as above, but with metadata.  */
>> +
>> +void
>> +error_meta (rich_location *richloc, const diagnostic_metadata
>> &metadata,
>> +           const char *gmsgid, ...)
>> +{
>> +  gcc_assert (richloc);
>> +
>> +  auto_diagnostic_group d;
>> +  va_list ap;
>> +  va_start (ap, gmsgid);
>> +  diagnostic_impl (richloc, &metadata, -1, gmsgid, &ap, DK_ERROR);
>> +  va_end (ap);
>> +}
>> +
>>   /* "Sorry, not implemented."  Use for a language feature which is
>>      required by the relevant specification but not implemented by
>> GCC.
>>      An object file will not be produced.  */
>
  

Patch

diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h
index 7334c79e8e6..c9e27fd2e6e 100644
--- a/gcc/diagnostic-core.h
+++ b/gcc/diagnostic-core.h
@@ -92,6 +92,9 @@  extern void error_n (location_t, unsigned HOST_WIDE_INT, const char *,
 extern void error_at (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3);
 extern void error_at (rich_location *, const char *, ...)
   ATTRIBUTE_GCC_DIAG(2,3);
+extern void error_meta (rich_location *, const diagnostic_metadata &,
+			const char *, ...)
+  ATTRIBUTE_GCC_DIAG(3,4);
 extern void fatal_error (location_t, const char *, ...) ATTRIBUTE_GCC_DIAG(2,3)
      ATTRIBUTE_NORETURN;
 /* Pass one of the OPT_W* from options.h as the second parameter.  */
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index c523f215bae..65c0cfbf11a 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -2108,6 +2108,21 @@  error_at (rich_location *richloc, const char *gmsgid, ...)
   va_end (ap);
 }
 
+/* Same as above, but with metadata.  */
+
+void
+error_meta (rich_location *richloc, const diagnostic_metadata &metadata,
+	    const char *gmsgid, ...)
+{
+  gcc_assert (richloc);
+
+  auto_diagnostic_group d;
+  va_list ap;
+  va_start (ap, gmsgid);
+  diagnostic_impl (richloc, &metadata, -1, gmsgid, &ap, DK_ERROR);
+  va_end (ap);
+}
+
 /* "Sorry, not implemented."  Use for a language feature which is
    required by the relevant specification but not implemented by GCC.
    An object file will not be produced.  */