public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106775] New: [11/12 regression] Subscipt operator with array rvalue inside brackets returns lvalue
@ 2022-08-30  2:49 leduyquang753 at gmail dot com
  2022-08-30  7:11 ` [Bug c++/106775] [11/12/13 " rguenth at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: leduyquang753 at gmail dot com @ 2022-08-30  2:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106775
           Summary: [11/12 regression] Subscipt operator with array rvalue
                    inside brackets returns lvalue
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: leduyquang753 at gmail dot com
  Target Milestone: ---

Created attachment 53519
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53519&action=edit
The command-line invocation of GCC, its verbose output and the preprocessed
source.

Using the built-in subscript operator with an array rvalue to the left (outside
brackets) and an integer to the right (inside brackets) returns an xvalue as
expected:

    test.cpp:10:21: error: using rvalue as lvalue [-fpremissive]
       10 |     getAnA().b[0] = 1;
          |     ~~~~~~~~~~~~^

But reversing the two operands makes GCC give an lvalue:

    0[getAnA().b] = 1;

No diagnostic with -Wall -Wextra -pedantic.

(Full preprocessed code attached.)

Test compiled using GCC 12.2.0 on Arch Linux and additionally on Windows and
Compiler explorer. Previous versions of GCC were tested on Compiler explorer
using x86-64 arch.

Other notes: MSVC in Visual studio 2022 seems to have the same issue while
Clang 14 doesn't.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/106775] [11/12/13 regression] Subscipt operator with array rvalue inside brackets returns lvalue
  2022-08-30  2:49 [Bug c++/106775] New: [11/12 regression] Subscipt operator with array rvalue inside brackets returns lvalue leduyquang753 at gmail dot com
@ 2022-08-30  7:11 ` rguenth at gcc dot gnu.org
  2022-08-30 12:59 ` [Bug c++/106775] [10/11/12/13 " mpolacek at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-08-30  7:11 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.4
            Summary|[11/12 regression] Subscipt |[11/12/13 regression]
                   |operator with array rvalue  |Subscipt operator with
                   |inside brackets returns     |array rvalue inside
                   |lvalue                      |brackets returns lvalue

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/106775] [10/11/12/13 regression] Subscipt operator with array rvalue inside brackets returns lvalue
  2022-08-30  2:49 [Bug c++/106775] New: [11/12 regression] Subscipt operator with array rvalue inside brackets returns lvalue leduyquang753 at gmail dot com
  2022-08-30  7:11 ` [Bug c++/106775] [11/12/13 " rguenth at gcc dot gnu.org
@ 2022-08-30 12:59 ` mpolacek at gcc dot gnu.org
  2022-08-30 13:10 ` mpolacek at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-08-30 12:59 UTC (permalink / raw)
  To: gcc-bugs

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

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |10.4.0
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |mpolacek at gcc dot gnu.org
      Known to work|10.4.0                      |
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
            Summary|[11/12/13 regression]       |[10/11/12/13 regression]
                   |Subscipt operator with      |Subscipt operator with
                   |array rvalue inside         |array rvalue inside
                   |brackets returns lvalue     |brackets returns lvalue
   Last reconfirmed|                            |2022-08-30

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Started with r10-3793-g1a37b6d9a7e57c (C++17 only).

commit 1a37b6d9a7e57c71b1bfe449ebd275eb408117fb
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Oct 11 09:36:07 2019 +0200

    re PR c++/91987 (-fstrict-eval-order issues)

            PR c++/91987

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/106775] [10/11/12/13 regression] Subscipt operator with array rvalue inside brackets returns lvalue
  2022-08-30  2:49 [Bug c++/106775] New: [11/12 regression] Subscipt operator with array rvalue inside brackets returns lvalue leduyquang753 at gmail dot com
  2022-08-30  7:11 ` [Bug c++/106775] [11/12/13 " rguenth at gcc dot gnu.org
  2022-08-30 12:59 ` [Bug c++/106775] [10/11/12/13 " mpolacek at gcc dot gnu.org
@ 2022-08-30 13:10 ` mpolacek at gcc dot gnu.org
  2022-08-30 17:02 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2022-08-30 13:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The difference between -fstrong-eval-order=all and -fstrong-eval-order=some:

 <<cleanup_point <<< Unknown tree: expr_stmt
-  (void) (*(int *) &(TARGET_EXPR <D.2421, getAnA ()>).b = 1) >>>>>;
+  (void) ((TARGET_EXPR <D.2421, getAnA ()>).b[0] = 1) >>>>>;
 return <retval> = 0;

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/106775] [10/11/12/13 regression] Subscipt operator with array rvalue inside brackets returns lvalue
  2022-08-30  2:49 [Bug c++/106775] New: [11/12 regression] Subscipt operator with array rvalue inside brackets returns lvalue leduyquang753 at gmail dot com
                   ` (2 preceding siblings ...)
  2022-08-30 13:10 ` mpolacek at gcc dot gnu.org
@ 2022-08-30 17:02 ` jakub at gcc dot gnu.org
  2022-10-19  7:05 ` rguenth at gcc dot gnu.org
  2023-05-29 10:07 ` [Bug c++/106775] [10/11/12/13/14 " jakub at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-08-30 17:02 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So, perhaps either we need to in the
556           if (swapped
557               && flag_strong_eval_order == 2
558               && (TREE_SIDE_EFFECTS (array_expr) || TREE_SIDE_EFFECTS
(index_exp)))
559             expr = build_array_ref (input_location, index_exp, array_expr);
560           else
561             expr = build_array_ref (input_location, array_expr, index_exp);
spot if array_expr has ARRAY_TYPE and is xvalue rather than lvalue
choose some different representation which will ensure the side-effects are
evaluated in the right order, perhaps by using save_expr around index_exp and
using COMPOUND_EXPR for that save_expr and array_expr, or need to adjust
lvalue_kind so that it is able to recognize even what we lower the array ref to
in the line 559 case as array ref with ARRAY_TYPE xvalue base.  We actually
lower it as *(x + y) instead of x[y] with ensuring the side-effects being
evaluated in the right order.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/106775] [10/11/12/13 regression] Subscipt operator with array rvalue inside brackets returns lvalue
  2022-08-30  2:49 [Bug c++/106775] New: [11/12 regression] Subscipt operator with array rvalue inside brackets returns lvalue leduyquang753 at gmail dot com
                   ` (3 preceding siblings ...)
  2022-08-30 17:02 ` jakub at gcc dot gnu.org
@ 2022-10-19  7:05 ` rguenth at gcc dot gnu.org
  2023-05-29 10:07 ` [Bug c++/106775] [10/11/12/13/14 " jakub at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-10-19  7:05 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug c++/106775] [10/11/12/13/14 regression] Subscipt operator with array rvalue inside brackets returns lvalue
  2022-08-30  2:49 [Bug c++/106775] New: [11/12 regression] Subscipt operator with array rvalue inside brackets returns lvalue leduyquang753 at gmail dot com
                   ` (4 preceding siblings ...)
  2022-10-19  7:05 ` rguenth at gcc dot gnu.org
@ 2023-05-29 10:07 ` jakub at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-05-29 10:07 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|11.4                        |11.5

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 11.4 is being released, retargeting bugs to GCC 11.5.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-05-29 10:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-30  2:49 [Bug c++/106775] New: [11/12 regression] Subscipt operator with array rvalue inside brackets returns lvalue leduyquang753 at gmail dot com
2022-08-30  7:11 ` [Bug c++/106775] [11/12/13 " rguenth at gcc dot gnu.org
2022-08-30 12:59 ` [Bug c++/106775] [10/11/12/13 " mpolacek at gcc dot gnu.org
2022-08-30 13:10 ` mpolacek at gcc dot gnu.org
2022-08-30 17:02 ` jakub at gcc dot gnu.org
2022-10-19  7:05 ` rguenth at gcc dot gnu.org
2023-05-29 10:07 ` [Bug c++/106775] [10/11/12/13/14 " jakub at gcc dot gnu.org

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).