From: Martin Sebor <msebor@gmail.com>
To: GCC Mailing List <gcc@gcc.gnu.org>
Subject: aliasing between internal zero-length-arrays and other members
Date: Mon, 04 Jun 2018 23:39:00 -0000 [thread overview]
Message-ID: <27a478ad-d2d2-7d4e-2dbc-44feae71d10d@gmail.com> (raw)
GCC silently (without -Wpedantic) accepts declarations of zero
length arrays that are followed by other members in the same
struct, such as in:
struct A { char a, b[0], c; };
Is it intended that accesses to elements of such arrays that
alias other members be well-defined?
In my tests, GCC assumes that neither read nor write accesses
to elements of internal zero-length arrays alias other members,
so assuming those aren't bugs I wonder if the documentation
should be updated to make that clear and a warning added for
such declarations (and perhaps also accesses).
For example, the test in the following function is eliminated,
implying that GCC assumes that the access to p->b does not modify
p->c, even though with i set to 0 it would:
void f (struct A *p, int i)
{
int x = p->c;
p->b[i] = 1;
if (x != p->c)
__builtin_abort ();
}
Martin
next reply other threads:[~2018-06-04 23:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-04 23:39 Martin Sebor [this message]
2018-06-05 11:42 ` Richard Biener
2018-06-05 12:54 ` Jakub Jelinek
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=27a478ad-d2d2-7d4e-2dbc-44feae71d10d@gmail.com \
--to=msebor@gmail.com \
--cc=gcc@gcc.gnu.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).