public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/106131] New: -fstrict-aliasing breaks normal program that does not use any pointer or reference
@ 2022-06-29  2:05 18307130172 at fudan dot edu.cn
  2022-06-29  2:09 ` [Bug c++/106131] " 18307130172 at fudan dot edu.cn
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: 18307130172 at fudan dot edu.cn @ 2022-06-29  2:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106131
           Summary: -fstrict-aliasing breaks normal program that does not
                    use any pointer or reference
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 18307130172 at fudan dot edu.cn
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

Created attachment 53220
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53220&action=edit
preprocessed source file

My program does not use any pointer or reference but is affected by
-fstrict-aliasing. Here is a minimal example to manifest this issue:

#include <vector>
#include <iostream>

using Pair = std::pair<int, int>;

std::vector<Pair> f = {{0, -11}, {0, -8}, {1, 2}};

int foo(Pair x, Pair y) {
    return std::max(x.second, y.second);
}

int main() {
    for (int J = 0; J < 1; J++) {
        f[J] = f[0];
        if(J == 0)
            f[J] = f[2];
        std::cout << foo(f[J], f[1]) << std::endl;
    }
}

Save it to main.cpp and compile it with:

g++ -O2 main.cpp

The expected output should be "2", but the optimized build output "-8". If
compiled with "-O2 -fno-strict-aliasing", the output is correct.

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

end of thread, other threads:[~2022-10-14 10:48 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-29  2:05 [Bug c++/106131] New: -fstrict-aliasing breaks normal program that does not use any pointer or reference 18307130172 at fudan dot edu.cn
2022-06-29  2:09 ` [Bug c++/106131] " 18307130172 at fudan dot edu.cn
2022-06-29  2:36 ` pinskia at gcc dot gnu.org
2022-06-29  9:26 ` redi at gcc dot gnu.org
2022-06-29 19:20 ` [Bug c++/106131] [10/11/12/13 Regression] " pinskia at gcc dot gnu.org
2022-06-29 19:21 ` pinskia at gcc dot gnu.org
2022-06-29 19:38 ` mpolacek at gcc dot gnu.org
2022-06-29 19:39 ` [Bug tree-optimization/106131] " mpolacek at gcc dot gnu.org
2022-06-29 19:39 ` mpolacek at gcc dot gnu.org
2022-06-30  0:50 ` 18307130172 at fudan dot edu.cn
2022-06-30  6:47 ` rguenther at suse dot de
2022-06-30  7:57 ` rguenth at gcc dot gnu.org
2022-06-30  8:31 ` rguenth at gcc dot gnu.org
2022-07-01  6:53 ` cvs-commit at gcc dot gnu.org
2022-07-01  6:54 ` [Bug tree-optimization/106131] [10/11/12 " rguenth at gcc dot gnu.org
2022-07-19 11:38 ` cvs-commit at gcc dot gnu.org
2022-10-11 13:04 ` [Bug tree-optimization/106131] [10/11 " cvs-commit at gcc dot gnu.org
2022-10-14 10:47 ` [Bug tree-optimization/106131] [10 " cvs-commit at gcc dot gnu.org
2022-10-14 10:48 ` rguenth 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).