public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] attribs: Improve diagnostics
@ 2022-09-23  6:30 Jakub Jelinek
  2022-09-23  6:49 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2022-09-23  6:30 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

Hi!

When looking at the attribs code, I've noticed weird diagnostics
like
int a __attribute__((section ("foo", "bar")));
a.c:1:1: error: wrong number of arguments specified for ‘section’ attribute
    1 | int a __attribute__((section ("foo", "bar")));
      | ^~~
a.c:1:1: note: expected between 1 and 1, found 2
As roughly 50% of attributes that accept any arguments have
spec->min_length == spec->max_length, I think it is worth it to have
separate wording for such common case and just write simpler
a.c:1:1: note: expected 1, found 2

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2022-09-23  Jakub Jelinek  <jakub@redhat.com>

	* attribs.cc (decl_attributes): Improve diagnostics, instead of
	saying expected between 1 and 1, found 2 just say expected 1, found 2.

--- gcc/attribs.cc.jj	2022-09-22 10:54:44.693705319 +0200
+++ gcc/attribs.cc	2022-09-22 18:18:38.142414100 +0200
@@ -737,6 +737,9 @@ decl_attributes (tree *node, tree attrib
 	      if (spec->max_length < 0)
 		inform (input_location, "expected %i or more, found %i",
 			spec->min_length, nargs);
+	      else if (spec->min_length == spec->max_length)
+		inform (input_location, "expected %i, found %i",
+			spec->min_length, nargs);
 	      else
 		inform (input_location, "expected between %i and %i, found %i",
 			spec->min_length, spec->max_length, nargs);


	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] attribs: Improve diagnostics
  2022-09-23  6:30 [PATCH] attribs: Improve diagnostics Jakub Jelinek
@ 2022-09-23  6:49 ` Richard Biener
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2022-09-23  6:49 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches

On Fri, 23 Sep 2022, Jakub Jelinek wrote:

> Hi!
> 
> When looking at the attribs code, I've noticed weird diagnostics
> like
> int a __attribute__((section ("foo", "bar")));
> a.c:1:1: error: wrong number of arguments specified for ?section? attribute
>     1 | int a __attribute__((section ("foo", "bar")));
>       | ^~~
> a.c:1:1: note: expected between 1 and 1, found 2
> As roughly 50% of attributes that accept any arguments have
> spec->min_length == spec->max_length, I think it is worth it to have
> separate wording for such common case and just write simpler
> a.c:1:1: note: expected 1, found 2
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

Thanks,
Richard.

> 2022-09-23  Jakub Jelinek  <jakub@redhat.com>
> 
> 	* attribs.cc (decl_attributes): Improve diagnostics, instead of
> 	saying expected between 1 and 1, found 2 just say expected 1, found 2.
> 
> --- gcc/attribs.cc.jj	2022-09-22 10:54:44.693705319 +0200
> +++ gcc/attribs.cc	2022-09-22 18:18:38.142414100 +0200
> @@ -737,6 +737,9 @@ decl_attributes (tree *node, tree attrib
>  	      if (spec->max_length < 0)
>  		inform (input_location, "expected %i or more, found %i",
>  			spec->min_length, nargs);
> +	      else if (spec->min_length == spec->max_length)
> +		inform (input_location, "expected %i, found %i",
> +			spec->min_length, nargs);
>  	      else
>  		inform (input_location, "expected between %i and %i, found %i",
>  			spec->min_length, spec->max_length, nargs);
> 
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-23  6:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-23  6:30 [PATCH] attribs: Improve diagnostics Jakub Jelinek
2022-09-23  6:49 ` Richard Biener

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).