public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Miika <nykseli@protonmail.com>
To: Jonathan Wakely <jwakely.gcc@gmail.com>
Cc: Ben Boeckel <ben.boeckel@kitware.com>,
	"gcc@gcc.gnu.org" <gcc@gcc.gnu.org>
Subject: [RFC] Support for nonzero attribute
Date: Tue, 07 Jun 2022 19:56:29 +0000	[thread overview]
Message-ID: <YGtH1oTvOT6bR2khmyOVSRBzxSiA8-ZvSu2ob_LlVwtwRB07Zhix9vYBszTluCTyRBOGQTaEXu9Zly1hvYJ0ELzRIKw1BCe08EO4vuSnV4Q=@protonmail.com> (raw)
In-Reply-To: <CAH6eHdSbfYfy73GJ+vNd8VZpqTCXFoXCG9oXun51AEn93ZEyWw@mail.gmail.com>

On Tuesday, June 7th, 2022 at 10:46 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On Tue, 7 Jun 2022 at 20:44, Jonathan Wakely wrote:
>
> > On Tue, 7 Jun 2022 at 20:40, Miika via Gcc gcc@gcc.gnu.org wrote:
> >
> > > On Monday, June 6th, 2022 at 9:42 PM, Ben Boeckel ben.boeckel@kitware.com wrote:
> > >
> > > > > Based on Jakub's and Yair's comments I created a new attribute "inrange".
> > > > > Inrage takes three arguments, pos min and max.
> > > > > Pos being the argument position in the function, and min and max defines the
> > > > > range of valid integer. Both min and max are inclusive and work with enums.
> > > > > Warnings are enabled with the new flag: "-Winrange".
> > > >
> > > > Is this something that could be applied to variables or types (I've not
> > > > much experience with GCC attribute internal mechanisms, so maybe not)?
> > >
> > > I took a closer look at it and looks like it can be applied.
> > >
> > > So trying to compile this:
> > > `typedef int __attribute__((inrange(0, 100))) percentage_t; int main() { int percentage __attribute__((inrange(0, 100))) = -1; percentage_t per __attribute__((inrange(0, 100))) = -1; }`
> > >
> > > Would print out something like this:
> > >
> > > foo.c: In function 'main':
> > > foo.c:3:59: warning: inrange variable 'percentage' requires integer in rage of 0..100 [-Winrange]
> >
> > N.B. "rage" should be "range".
> >
> > From the diagnostic it's not clear to me whether this is an inclusive
> > range. Is 0 allowed? Is 100 allowed?
> >
> > Using [0,100] interval notation would imply both endpoints are valid,
> > which I think matches the semantics of your attribute. Is interval
> > notation sufficiently widely understood to use here?
>
>
> Oh, Wikipedia tells me that 0..100 already means that, as an integer interval:
> https://en.wikipedia.org/wiki/Interval_(mathematics)#Integer_intervals
>
> So maybe it's fine as-is (except for the "rage" typo).

Thanks for noticing the typo. I probably need more sleep.

And I'm open to any suggestions about the diagnostic message since I'm not sure
what's the best way to explain the error to the user.

  reply	other threads:[~2022-06-07 19:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-03 16:34 Miika
2022-06-03 16:45 ` Jakub Jelinek
2022-06-04 11:25   ` Miika
2022-06-05 20:09 ` Miika
2022-06-06 18:42   ` Ben Boeckel
2022-06-07 19:39     ` Miika
2022-06-07 19:44       ` Jonathan Wakely
2022-06-07 19:46         ` Jonathan Wakely
2022-06-07 19:56           ` Miika [this message]
2022-06-08 17:42   ` Eric Gallager
2022-06-08 20:59     ` Miika
2022-06-09  4:36       ` Eric Gallager
2022-06-09 18:06         ` Miika
2022-06-12  4:25   ` Prathamesh Kulkarni
2022-06-13 12:55     ` Miika
2022-06-13 16:02       ` Martin Sebor
     [not found] <mailman.2312.1654300374.1672222.gcc@gcc.gnu.org>
2022-06-04 10:26 ` Yair Lenga
2022-06-04 11:55   ` Miika
2022-06-04 21:29     ` Yair Lenga
2022-06-13  9:49   ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='YGtH1oTvOT6bR2khmyOVSRBzxSiA8-ZvSu2ob_LlVwtwRB07Zhix9vYBszTluCTyRBOGQTaEXu9Zly1hvYJ0ELzRIKw1BCe08EO4vuSnV4Q=@protonmail.com' \
    --to=nykseli@protonmail.com \
    --cc=ben.boeckel@kitware.com \
    --cc=gcc@gcc.gnu.org \
    --cc=jwakely.gcc@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).