public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97474] New: Regression: optimization produces wrong code
@ 2020-10-17 20:42 sfranzen85 at hotmail dot com
  2020-10-17 21:21 ` [Bug c++/97474] " pinskia at gcc dot gnu.org
                   ` (21 more replies)
  0 siblings, 22 replies; 23+ messages in thread
From: sfranzen85 at hotmail dot com @ 2020-10-17 20:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97474
           Summary: Regression: optimization produces wrong code
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sfranzen85 at hotmail dot com
  Target Milestone: ---

While searching for something different I found the following example code
demonstrating a possible gcc bug:
---
#include <iostream>
using std::cout;

struct A {
    int a;
    int& b;

    A(int x) : a(x), b(a) {}
    A(const A& other) : a(other.a), b(a) {}
    A() : a(0), b(a) {}
};

int foo(A a) {
    a.a *= a.b;
    return a.b;
}


int main() {
    A a(3);

    cout << foo(a) << '\n';
    return 0;
}
---
(Source:
https://stackoverflow.com/questions/62853805/why-does-modifying-a-field-that-is-referenced-by-another-variable-lead-to-unexpe)

I was unable to find a related bug report, hence this one. Wrong output (3
instead of 9) is produced with -O1 or higher, since gcc version 6.4, as
mentioned in a comment. Indeed gcc trunk on godbolt still generates faulty
code: https://godbolt.org/z/TcedxE.

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

end of thread, other threads:[~2022-05-11 20:13 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-17 20:42 [Bug c++/97474] New: Regression: optimization produces wrong code sfranzen85 at hotmail dot com
2020-10-17 21:21 ` [Bug c++/97474] " pinskia at gcc dot gnu.org
2020-10-17 21:31 ` [Bug tree-optimization/97474] [8/9/10/11 Regression] produces wrong code with references to another field pinskia at gcc dot gnu.org
2020-10-17 21:40 ` jakub at gcc dot gnu.org
2020-10-19  7:33 ` rguenth at gcc dot gnu.org
2020-10-19  7:49 ` rguenth at gcc dot gnu.org
2020-10-19  8:35 ` rguenth at gcc dot gnu.org
2020-10-19  8:36 ` rguenth at gcc dot gnu.org
2020-10-19 21:32 ` joseph at codesourcery dot com
2020-10-20  6:39 ` [Bug c++/97474] " rguenth at gcc dot gnu.org
2020-10-20  6:47 ` jakub at gcc dot gnu.org
2020-10-20  6:50 ` jakub at gcc dot gnu.org
2021-01-25 16:32 ` jason at gcc dot gnu.org
2021-01-26  8:29 ` rguenther at suse dot de
2021-01-26 21:12 ` jason at gcc dot gnu.org
2021-01-26 22:11 ` cvs-commit at gcc dot gnu.org
2021-01-27  9:12 ` rguenther at suse dot de
2021-01-29 16:00 ` cvs-commit at gcc dot gnu.org
2021-02-03 15:56 ` [Bug c++/97474] [8/9 " jakub at gcc dot gnu.org
2021-05-14  9:54 ` [Bug c++/97474] [9 " jakub at gcc dot gnu.org
2021-06-01  8:18 ` rguenth at gcc dot gnu.org
2022-05-11 20:05 ` jason at gcc dot gnu.org
2022-05-11 20:13 ` pinskia 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).