public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Per Bothner <bothner@cygnus.com>
To: egcs@cygnus.com, rms@cygnus.com, kenner@cygnus.com
Subject: Re: array bounds check option
Date: Thu, 22 Jan 1998 01:45:00 -0000	[thread overview]
Message-ID: <199801211800.KAA14394@cygnus.com> (raw)
In-Reply-To: <199801211714.MAA15680@melange.gnu.org>

Craig Burley <burley@gnu.org> writes:
> I'd suggest -farray-bounds-check, because "bounds" might be too
> general ("range" certainly is).
>
> E.g. consider whether someone might want an option to check the
> range of values assigned to "enum"s, or types declared with
> explicit ranges (a la Pascal).

In a language with range types, if you check array indexes,
I think you would normally want to "range check" also on values
coerced to ranges.  That catches possible subscript errors earlier.
Also, if we can assume that index expressions whose types are
ranges have values that are actually within the range of its type,
then we can easily optimize away range checks when the range of
the actual index is a sub-set of the array index range.

Thus in normal use, "check array subscript" would imply "check
cast to range type".  That is reasonable for Chill, and (I
believe) Pascal.  Ada I'm not sure about.  A common flag
(both in the sense of one that does it all, and in the sense of
the flag most commonly used!) does not preclude finer control
(such as -fbounds-check -fno-conversion-bounds-check).

> consider whether someone might want an option to check the 
> range of values assigned to "enum"s

That should probably also be implied by -fbounds-check - but
only for enums that have a dense range with values that
always increase by one.

> So I'd say -fsubscript-bounds-check is appropriate only if
> you're putting a check on each ARRAY_REF node (or whatever
> its called), while -farray-bounds-check is appropriate only if
> you're checking the computed offset into the array against
> the overall bounds of the array.

That is reasonable.  But I think -fbounds-check should imply
one of -fsubscript-bounds-check or -farray-bounds-check
depending on the language and strictness mode.  In C or C++,
and traditional Fortran, it might imply -farray-bounds-check.
In Java, Chill, and -pedantic Fortran it might imply
-fsubscript-bounds-check.

	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner

      reply	other threads:[~1998-01-22  1:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-01-20  4:00 Per Bothner
1998-01-21  9:54 ` Craig Burley
1998-01-22  1:45   ` Per Bothner [this message]

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=199801211800.KAA14394@cygnus.com \
    --to=bothner@cygnus.com \
    --cc=egcs@cygnus.com \
    --cc=kenner@cygnus.com \
    --cc=rms@cygnus.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).