public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/105598] New: Flag -O2 causes code to misbehave
@ 2022-05-13 17:49 greenfoo at u92 dot eu
  2022-05-13 18:25 ` [Bug c/105598] [11 Regression] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: greenfoo at u92 dot eu @ 2022-05-13 17:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105598
           Summary: Flag -O2 causes code to misbehave
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: greenfoo at u92 dot eu
  Target Milestone: ---

Created attachment 52974
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52974&action=edit
Small example that triggers the issue when using -O2 in gcc 11.x

I found a situation where the "-O2" flag was causing trouble at least in
x86_64.

The attached file "example.c" code is expected to print "4" when compiled and
executed, but it would print "2" when compiled with "-02".

This happens with gcc 11.1, 11.2 and 11.3, but works correctly with gcc 10.3
and 12.1:

> $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:10.3 gcc -o example example.c && ./example
> 4 
> $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:11.1 gcc -o example example.c && ./example
> 2
> $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:11.2 gcc -o example example.c && ./example
> 2
> $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:11.3 gcc -o example example.c && ./example
> 2
> $ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp gcc:12.1 gcc -o example example.c && ./example
> 4

I don't know if this deserves further investigation. If not, please feel free
to discard this bug report.

Thanks!

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

end of thread, other threads:[~2022-05-16 10:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-13 17:49 [Bug c/105598] New: Flag -O2 causes code to misbehave greenfoo at u92 dot eu
2022-05-13 18:25 ` [Bug c/105598] [11 Regression] " jakub at gcc dot gnu.org
2022-05-16  8:47 ` [Bug tree-optimization/105598] " rguenth at gcc dot gnu.org
2022-05-16  8:59 ` jakub at gcc dot gnu.org
2022-05-16  9:18 ` rguenth at gcc dot gnu.org
2022-05-16 10:06 ` 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).