public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/101062] [10/11/12 Regression] wrong code with "-O2 -fno-toplevel-reorder -frename-registers"
Date: Tue, 15 Jun 2021 08:15:31 +0000	[thread overview]
Message-ID: <bug-101062-4-CfZXyUtvqd@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-101062-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101062

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #7)
> Now, it looks to me this is rather an issue that the access is larger than
> the object and thus a general bug - at least I don't see how it should only
> manifest with bitfields in unions?
> 
> Note we do
> 
>       if (TREE_CODE (to) == COMPONENT_REF
>           && DECL_BIT_FIELD_TYPE (TREE_OPERAND (to, 1)))
>         get_bit_range (&bitregion_start, &bitregion_end, to, &bitpos,
> &offset);
>       /* The C++ memory model naturally applies to byte-aligned fields.
>          However, if we do not have a DECL_BIT_FIELD_TYPE but BITPOS or
>          BITSIZE are not byte-aligned, there is no need to limit the range
>          we can access.  This can occur with packed structures in Ada.  */
>       else if (maybe_gt (bitsize, 0)
>                && multiple_p (bitsize, BITS_PER_UNIT)
>                && multiple_p (bitpos, BITS_PER_UNIT))
>         {
>           bitregion_start = bitpos;
>           bitregion_end = bitpos + bitsize - 1;
>         }
> 
> but if we assume that for DECL_BIT_FIELD_TYPE there's a representative
> then we miss the else if, so - maybe get_bit_range should return whether
> it handled things or the else if part should be done unconditionally
> in case bitregion_start/end is not {0,0}?

This wouldn't help us, bitsize is > 0, but not a multiple of BITS_PER_UNIT in
this case.  Furthermore, even if we add there bitregion_start/end for the base
variable if any as further fallthrough, I think most C/C++ programmers will
expect that with
union U { int a; int b : 5; } u[64];
u[4].b = 1; can be done safely in one thread and
u[5].a = 2; in another one.

My patch fixes that (or another possibility would be to compute the
representative even in UNION_TYPE (no idea about QUAL_UNION_TYPE) - could be as
simple as removing the early out and instead of doing prev = field; in the loop
do if (TREE_CODE (t) != RECORD_TYPE) { finish_bitfield_representative (repr,
field); repr = NULL_TREE; } else prev = field; and in
finish_bitfield_representative override nextf to NULL_TREE).

Improving expand_assignment can be done too, sure, but independently to this.

  parent reply	other threads:[~2021-06-15  8:15 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-14 11:05 [Bug tree-optimization/101062] New: " suochenyao at 163 dot com
2021-06-14 18:04 ` [Bug tree-optimization/101062] [10/11/12 Regression] " jakub at gcc dot gnu.org
2021-06-14 18:08 ` jakub at gcc dot gnu.org
2021-06-14 18:35 ` jakub at gcc dot gnu.org
2021-06-14 18:59 ` jakub at gcc dot gnu.org
2021-06-14 20:20 ` jakub at gcc dot gnu.org
2021-06-14 21:46 ` ebotcazou at gcc dot gnu.org
2021-06-15  7:42 ` rguenth at gcc dot gnu.org
2021-06-15  8:15 ` jakub at gcc dot gnu.org [this message]
2021-06-15  8:56 ` [Bug middle-end/101062] " rguenther at suse dot de
2021-06-15  9:05 ` jakub at gcc dot gnu.org
2021-06-15  9:21 ` rguenth at gcc dot gnu.org
2021-06-16 10:18 ` cvs-commit at gcc dot gnu.org
2021-06-17  8:20 ` jakub at gcc dot gnu.org
2021-06-17  8:22 ` jakub at gcc dot gnu.org
2021-06-17  9:13 ` ebotcazou at gcc dot gnu.org
2021-06-18  9:21 ` cvs-commit at gcc dot gnu.org
2021-06-18  9:23 ` cvs-commit at gcc dot gnu.org
2021-06-18  9:23 ` cvs-commit at gcc dot gnu.org
2021-07-13 13:13 ` [Bug middle-end/101062] [10 " jakub at gcc dot gnu.org
2022-05-10  8:18 ` cvs-commit at gcc dot gnu.org
2022-05-10  8:19 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:20 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:20 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:36 ` jakub at gcc dot gnu.org

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=bug-101062-4-CfZXyUtvqd@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).