public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96594] New: Compiled code behaves differently with -O1 and -O0 on s390x
@ 2020-08-12 19:03 mitya57 at gmail dot com
  2020-08-12 19:04 ` [Bug c++/96594] " mitya57 at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: mitya57 at gmail dot com @ 2020-08-12 19:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96594
           Summary: Compiled code behaves differently with -O1 and -O0 on
                    s390x
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mitya57 at gmail dot com
  Target Milestone: ---

Created attachment 49050
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49050&action=edit
Test case

Hi,

I was debugging Compiz test failures that started happening on Debian/Ubuntu
s390x in July. They are not directly related to GCC upgrade (old GCC 8 behaves
the same way), however I noticed a strange thing that I want to report here.

The attached file behaves differently when built with -O0 and -O1:

$ g++ test.cpp -g -O1 -lX11
$ xvfb-run ./a.out
setting value = 0x1020304
got value = 0xffffffff

$ g++ test.cpp -g -O0 -lX11
$ xvfb-run ./a.out
setting value = 0x1020304
got value = 0x0

And both these behaviors are wrong! Expected behavior is (as seen on x86_64):

$ xvfb-run ./a.out 
setting value = 0x1020304
got value = 0x1020304

However, this bug is about differing behaviors with -O1 and -O0.

The only dependency of this file is Xlib. So far I was not able to make an
example that does not depend on it.

I wanted to bisect a particular optimization that causes this behavior change,
but even with all options from
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-O1 it behaves
like -O0.

Some more things I noticed:

- Moving GetProperty and SetProperty functions away from the namespace makes it
behave like -O0.

- Adding __attribute__((noinline)) to SetProperty makes it behave like -O0. So
the bug may be related to inlining.

I am also attaching assembly dumps with -O1 and -O0.

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

* [Bug c++/96594] Compiled code behaves differently with -O1 and -O0 on s390x
  2020-08-12 19:03 [Bug c++/96594] New: Compiled code behaves differently with -O1 and -O0 on s390x mitya57 at gmail dot com
@ 2020-08-12 19:04 ` mitya57 at gmail dot com
  2020-08-12 19:04 ` mitya57 at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: mitya57 at gmail dot com @ 2020-08-12 19:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Dmitry Shachnev <mitya57 at gmail dot com> ---
Created attachment 49051
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49051&action=edit
Assembly dump with -O0

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

* [Bug c++/96594] Compiled code behaves differently with -O1 and -O0 on s390x
  2020-08-12 19:03 [Bug c++/96594] New: Compiled code behaves differently with -O1 and -O0 on s390x mitya57 at gmail dot com
  2020-08-12 19:04 ` [Bug c++/96594] " mitya57 at gmail dot com
@ 2020-08-12 19:04 ` mitya57 at gmail dot com
  2020-08-12 19:40 ` jakub at gcc dot gnu.org
  2020-08-12 20:12 ` mitya57 at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: mitya57 at gmail dot com @ 2020-08-12 19:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Dmitry Shachnev <mitya57 at gmail dot com> ---
Created attachment 49052
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49052&action=edit
Assembly dump with -O1

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

* [Bug c++/96594] Compiled code behaves differently with -O1 and -O0 on s390x
  2020-08-12 19:03 [Bug c++/96594] New: Compiled code behaves differently with -O1 and -O0 on s390x mitya57 at gmail dot com
  2020-08-12 19:04 ` [Bug c++/96594] " mitya57 at gmail dot com
  2020-08-12 19:04 ` mitya57 at gmail dot com
@ 2020-08-12 19:40 ` jakub at gcc dot gnu.org
  2020-08-12 20:12 ` mitya57 at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-08-12 19:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
That is just a user error, you didn't read the XChangeProperty man page.
"If the specified format is 16, the property data must be a short
array.  If the specified format is 32, the property data must be a long array."
You are using 32, and I assume you are doing this on 64-bit s390x, i.e. where
long is 64-bit, so while it sounds weird, libX11 requires you to put the
property into a long or unsigned long variable and pass address of that (and
read it through that too).
It kind of "works" on x86_64, because it is little-endian, so you just have
random bits in the upper 32 bits of the long that the library actually reads
and perhaps it casts it to a 32-bit type later on.
But s390x is big endian, so if you call it with address of a 32-bit variable,
the low 32 bits of that are the 32 bits after your variable and can contain
arbitrary random values.

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

* [Bug c++/96594] Compiled code behaves differently with -O1 and -O0 on s390x
  2020-08-12 19:03 [Bug c++/96594] New: Compiled code behaves differently with -O1 and -O0 on s390x mitya57 at gmail dot com
                   ` (2 preceding siblings ...)
  2020-08-12 19:40 ` jakub at gcc dot gnu.org
@ 2020-08-12 20:12 ` mitya57 at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: mitya57 at gmail dot com @ 2020-08-12 20:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Dmitry Shachnev <mitya57 at gmail dot com> ---
Thanks a lot for the fast response!

Indeed, your suggestion works. It is counter-intuitive that you need a 64-bit
variable to store a 32-bit value, but I can see the rationale (long is the only
standard type that is guaranteed to be 32-bits).

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

end of thread, other threads:[~2020-08-12 20:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-12 19:03 [Bug c++/96594] New: Compiled code behaves differently with -O1 and -O0 on s390x mitya57 at gmail dot com
2020-08-12 19:04 ` [Bug c++/96594] " mitya57 at gmail dot com
2020-08-12 19:04 ` mitya57 at gmail dot com
2020-08-12 19:40 ` jakub at gcc dot gnu.org
2020-08-12 20:12 ` mitya57 at gmail dot com

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