public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: Segher Boessenkool <segher@kernel.crashing.org>,
	 Joseph Myers <joseph@codesourcery.com>
Cc: Bernd Schmidt <bschmidt@redhat.com>,
	 Gcc Patch List <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] c/67882 - improve -Warray-bounds for invalid offsetof
Date: Mon, 09 Nov 2015 22:46:00 -0000	[thread overview]
Message-ID: <5641223D.6090801@gmail.com> (raw)
In-Reply-To: <20151107233804.GB9982@gate.crashing.org>

On 11/07/2015 04:38 PM, Segher Boessenkool wrote:
> On Tue, Oct 20, 2015 at 10:10:44PM +0000, Joseph Myers wrote:
>>> typedef struct FA5_7 {
>>>    int i;
>>>    char a5_7 [5][7];
>>> } FA5_7;
>>>
>>>      __builtin_offsetof (FA5_7, a5_7 [0][7]),         // { dg-warning "index" }
>>>      __builtin_offsetof (FA5_7, a5_7 [1][7]),         // { dg-warning "index" }
>>>      __builtin_offsetof (FA5_7, a5_7 [5][0]),         // { dg-warning "index" }
>>>      __builtin_offsetof (FA5_7, a5_7 [5][7]),         // { dg-warning "index" }
>>>
>>> Here I think the last one of these is most likely invalid (being 8 bytes past
>>> the end of the object, rather than just one) and the others valid. Can you
>>> confirm this? (If the &a.v[2].a example is considered invalid, then I think
>>> the a5_7[5][0] test would be the equivalent and ought to also be considered
>>> invalid).
>>
>> The last one is certainly invalid.  The one before is arguably invalid as
>> well (in the unary '&' equivalent, &a5_7[5][0] which is equivalent to
>> a5_7[5] + 0, the questionable operation is implicit conversion of a5_7[5]
>> from array to pointer - an array expression gets converted to an
>> expression "that points to the initial element of the array object", but
>> there is no array object a5_7[5] here).
>
> C11, 6.5.2.1/3:
> Successive subscript operators designate an element of a
> multidimensional array object. If E is an n-dimensional array (n >= 2)
> with dimensions i x j x . . . x k, then E (used as other than an lvalue)
> is converted to a pointer to an (n - 1)-dimensional array with
> dimensions j x . . . x k. If the unary * operator is applied to this
> pointer explicitly, or implicitly as a result of subscripting, the
> result is the referenced (n - 1)-dimensional array, which itself is
> converted into a pointer if used as other than an lvalue. It follows
> from this that arrays are stored in row-major order (last subscript
> varies fastest).
>
> As far as I see, a5_7[5] here is never treated as an array, just as a
> pointer, and &a5_7[5][0] is valid.

Segher and I discussed this briefly on IRC over the weekend and
I agreed to try to get a confirmation of the interpretation the
warning is based on from WG14. I'll report back what I learn
(if anything). I defer to Bernd and Joseph as to whether to make
any changes in the meantime.

Martin

  reply	other threads:[~2015-11-09 22:46 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-09  2:55 Martin Sebor
2015-10-15 21:59 ` [PING] " Martin Sebor
2015-10-16 12:28 ` Bernd Schmidt
2015-10-16 17:27   ` Joseph Myers
2015-10-16 19:34   ` Martin Sebor
2015-10-20 13:21     ` Bernd Schmidt
2015-10-20 15:33       ` Martin Sebor
2015-10-20 15:52         ` Bernd Schmidt
2015-10-20 16:57           ` Martin Sebor
2015-10-20 17:11             ` Joseph Myers
2015-10-20 19:10               ` Martin Sebor
2015-10-20 16:54         ` Joseph Myers
2015-10-20 20:36           ` Bernd Schmidt
2015-10-20 22:19             ` Joseph Myers
2015-10-23 11:17               ` Bernd Schmidt
2015-10-23 15:15                 ` Martin Sebor
2015-10-23 16:53                   ` Joseph Myers
2015-10-23 17:45                     ` Bernd Schmidt
2015-10-23 20:54                       ` Martin Sebor
2015-10-26 11:44                         ` Bernd Schmidt
2015-10-26 11:51                           ` Jakub Jelinek
2015-10-26 12:01                             ` Bernd Schmidt
2015-10-26 12:04                               ` Jakub Jelinek
2015-10-26 12:32                                 ` Richard Biener
2015-10-27 11:18                                   ` Bernd Schmidt
2015-11-03 19:15                         ` Martin Sebor
2015-11-07 23:38               ` Segher Boessenkool
2015-11-09 22:46                 ` Martin Sebor [this message]
2015-11-10  0:02                 ` Joseph Myers
  -- strict thread matches above, loose matches on Subject: below --
2015-10-09  2:49 Martin Sebor

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=5641223D.6090801@gmail.com \
    --to=msebor@gmail.com \
    --cc=bschmidt@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    --cc=segher@kernel.crashing.org \
    /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).