public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/106355] New: Linux s390x -O2 argument passing miscompile
@ 2022-07-19 14:28 sbergman at redhat dot com
  2022-07-20  8:06 ` [Bug target/106355] " rguenth at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: sbergman at redhat dot com @ 2022-07-19 14:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106355
           Summary: Linux s390x -O2 argument passing miscompile
           Product: gcc
           Version: 12.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sbergman at redhat dot com
  Target Milestone: ---

(I ran into this when trying to build recent LibreOffice 7.5 master on Fedora
36 on s390x causing a crash in one of the executables generated during the
build.  I tracked that down to a member function S::f2(arg1,args2,arg3) calling
S::f1(arg1,arg2,arg3,std::nullopt) but within
S::f1(arg1,arg2,arg3,std::optional<unsigned short> x) then x.has_value()
evaluates to true, or even to some random non-zero value like 163:)

At least with gcc-c++-12.1.1-1.fc36.s390x:

> $ cat test.cc
> #include <cstdlib>
> #include <optional>
> int f1(int, int, int, int, std::optional<unsigned short> x) {
>   if (x) std::abort();
>   return 0;
> }
> int f2(int a, int b, int c, int d) {
>   return f1(a, b, c, d, std::nullopt);
> }

> $ g++ -std=c++17 -O2 -fpic -S test.cc

> $ cat test.s
>         .file   "test.cc"
>         .machinemode zarch
>         .machine "zEC12"
> .text
>         .align  8
>         .align  16
> .globl _Z2f1iiiiSt8optionalItE
>         .type   _Z2f1iiiiSt8optionalItE, @function
> _Z2f1iiiiSt8optionalItE:
> .LFB284:
>         .cfi_startproc
>         tmll    %r6,65280
>         jne     .L7
>         lghi    %r2,0
>         br      %r14
> .L7:
>         stmg    %r14,%r15,112(%r15)
>         .cfi_offset 14, -48
>         .cfi_offset 15, -40
>         lay     %r15,-168(%r15)
>         .cfi_def_cfa_offset 328
>         brasl   %r14,abort@PLT
>         .cfi_endproc
> .LFE284:
>         .size   _Z2f1iiiiSt8optionalItE, .-_Z2f1iiiiSt8optionalItE
>         .align  8
>         .align  16
> .globl _Z2f2iiii
>         .type   _Z2f2iiii, @function
> _Z2f2iiii:
> .LFB287:
>         .cfi_startproc
>         ldgr    %f0,%r15
>         .cfi_register 15, 16
>         lay     %r15,-168(%r15)
>         .cfi_def_cfa_offset 328
>         mvi     166(%r15),0
>         lgdr    %r15,%f0
>         .cfi_restore 15
>         .cfi_def_cfa_offset 160
>         jg      _Z2f1iiiiSt8optionalItE@PLT
>         .cfi_endproc
> .LFE287:
>         .size   _Z2f2iiii, .-_Z2f2iiii
>         .ident  "GCC: (GNU) 12.1.1 20220507 (Red Hat 12.1.1-1)"
>         .section        .note.GNU-stack,"",@progbits

With my limited understanding of s390x assembly, f2 sets the optional's bool
_M_engaged flag byte to 0 on the stack with

        lay     %r15,-168(%r15)
        mvi     166(%r15),0

but then f1 expects to test that byte in %r6 with

        tmll    %r6,65280

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

* [Bug target/106355] Linux s390x -O2 argument passing miscompile
  2022-07-19 14:28 [Bug other/106355] New: Linux s390x -O2 argument passing miscompile sbergman at redhat dot com
@ 2022-07-20  8:06 ` rguenth at gcc dot gnu.org
  2022-07-20  8:14 ` sbergman at redhat dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-07-20  8:06 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |krebbel at gcc dot gnu.org,
                   |                            |rguenth at gcc dot gnu.org

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Did you see whether this is changed behavior from GCC 11?

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

* [Bug target/106355] Linux s390x -O2 argument passing miscompile
  2022-07-19 14:28 [Bug other/106355] New: Linux s390x -O2 argument passing miscompile sbergman at redhat dot com
  2022-07-20  8:06 ` [Bug target/106355] " rguenth at gcc dot gnu.org
@ 2022-07-20  8:14 ` sbergman at redhat dot com
  2022-08-15 13:00 ` dan at danny dot cz
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: sbergman at redhat dot com @ 2022-07-20  8:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Stephan Bergmann <sbergman at redhat dot com> ---
(In reply to Richard Biener from comment #1)
> Did you see whether this is changed behavior from GCC 11?

I didn't check that myself, but the Debian LibreOffice maintainer claims that
he sees the same symptoms when building with some GCC 11 (against some GCC 12
libstdc++, though).  (It appears that this issue only happened to start to hit
builds of LibreOffice after some recent code changes in LibreOffice, so we
don't have any historic data on which versions of GCC would not have had this
issue.)

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

* [Bug target/106355] Linux s390x -O2 argument passing miscompile
  2022-07-19 14:28 [Bug other/106355] New: Linux s390x -O2 argument passing miscompile sbergman at redhat dot com
  2022-07-20  8:06 ` [Bug target/106355] " rguenth at gcc dot gnu.org
  2022-07-20  8:14 ` sbergman at redhat dot com
@ 2022-08-15 13:00 ` dan at danny dot cz
  2022-08-15 13:20 ` stefansf at linux dot ibm.com
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dan at danny dot cz @ 2022-08-15 13:00 UTC (permalink / raw)
  To: gcc-bugs

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

Dan Horák <dan at danny dot cz> changed:

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

--- Comment #3 from Dan Horák <dan at danny dot cz> ---
adding Jakub as this affect Fedora ...

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

* [Bug target/106355] Linux s390x -O2 argument passing miscompile
  2022-07-19 14:28 [Bug other/106355] New: Linux s390x -O2 argument passing miscompile sbergman at redhat dot com
                   ` (2 preceding siblings ...)
  2022-08-15 13:00 ` dan at danny dot cz
@ 2022-08-15 13:20 ` stefansf at linux dot ibm.com
  2022-10-19 12:29 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: stefansf at linux dot ibm.com @ 2022-08-15 13:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Stefan Schulze Frielinghaus <stefansf at linux dot ibm.com> ---
The problem is with sibling call optimization where parameters with BLKmode are
not handled correctly. I will prepare a patch and submit it shortly.

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

* [Bug target/106355] Linux s390x -O2 argument passing miscompile
  2022-07-19 14:28 [Bug other/106355] New: Linux s390x -O2 argument passing miscompile sbergman at redhat dot com
                   ` (3 preceding siblings ...)
  2022-08-15 13:20 ` stefansf at linux dot ibm.com
@ 2022-10-19 12:29 ` cvs-commit at gcc dot gnu.org
  2022-10-25  8:35 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-10-19 12:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Stefan Schulze Frielinghaus
<stefansf@gcc.gnu.org>:

https://gcc.gnu.org/g:cb994acc08b67f26a54e7c5dc1f4995a2ce24d98

commit r13-3377-gcb994acc08b67f26a54e7c5dc1f4995a2ce24d98
Author: Stefan Schulze Frielinghaus <stefansf@linux.ibm.com>
Date:   Wed Oct 19 14:28:22 2022 +0200

    IBM zSystems: Fix function_ok_for_sibcall [PR106355]

    For a parameter with BLKmode we cannot use REG_NREGS in order to
    determine the number of consecutive registers.  Streamlined this with
    the implementation of s390_function_arg.

    Fix some indentation whitespace, too.

    gcc/ChangeLog:

            PR target/106355
            * config/s390/s390.cc (s390_call_saved_register_used): For a
            parameter with BLKmode fix determining number of consecutive
            registers.

    gcc/testsuite/ChangeLog:

            * gcc.target/s390/pr106355.h: Common code for new tests.
            * gcc.target/s390/pr106355-1.c: New test.
            * gcc.target/s390/pr106355-2.c: New test.
            * gcc.target/s390/pr106355-3.c: New test.

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

* [Bug target/106355] Linux s390x -O2 argument passing miscompile
  2022-07-19 14:28 [Bug other/106355] New: Linux s390x -O2 argument passing miscompile sbergman at redhat dot com
                   ` (4 preceding siblings ...)
  2022-10-19 12:29 ` cvs-commit at gcc dot gnu.org
@ 2022-10-25  8:35 ` cvs-commit at gcc dot gnu.org
  2022-10-25  8:37 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-10-25  8:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Stefan Schulze Frielinghaus
<stefansf@gcc.gnu.org>:

https://gcc.gnu.org/g:0737125ec0e9102e139f8f49130b4666be4cc626

commit r12-8865-g0737125ec0e9102e139f8f49130b4666be4cc626
Author: Stefan Schulze Frielinghaus <stefansf@linux.ibm.com>
Date:   Wed Oct 19 14:28:22 2022 +0200

    IBM zSystems: Fix function_ok_for_sibcall [PR106355]

    For a parameter with BLKmode we cannot use REG_NREGS in order to
    determine the number of consecutive registers.  Streamlined this with
    the implementation of s390_function_arg.

    Fix some indentation whitespace, too.

    gcc/ChangeLog:

            PR target/106355
            * config/s390/s390.cc (s390_call_saved_register_used): For a
            parameter with BLKmode fix determining number of consecutive
            registers.

    gcc/testsuite/ChangeLog:

            * gcc.target/s390/pr106355.h: Common code for new tests.
            * gcc.target/s390/pr106355-1.c: New test.
            * gcc.target/s390/pr106355-2.c: New test.
            * gcc.target/s390/pr106355-3.c: New test.

    (cherry picked from commit cb994acc08b67f26a54e7c5dc1f4995a2ce24d98)

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

* [Bug target/106355] Linux s390x -O2 argument passing miscompile
  2022-07-19 14:28 [Bug other/106355] New: Linux s390x -O2 argument passing miscompile sbergman at redhat dot com
                   ` (5 preceding siblings ...)
  2022-10-25  8:35 ` cvs-commit at gcc dot gnu.org
@ 2022-10-25  8:37 ` cvs-commit at gcc dot gnu.org
  2022-10-25  8:39 ` cvs-commit at gcc dot gnu.org
  2024-02-29 20:19 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-10-25  8:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Stefan Schulze Frielinghaus
<stefansf@gcc.gnu.org>:

https://gcc.gnu.org/g:5e41c45fef8262caf20fdcf2a04427f16c295881

commit r11-10336-g5e41c45fef8262caf20fdcf2a04427f16c295881
Author: Stefan Schulze Frielinghaus <stefansf@linux.ibm.com>
Date:   Tue Oct 25 10:37:19 2022 +0200

    IBM zSystems: Fix function_ok_for_sibcall [PR106355]

    For a parameter with BLKmode we cannot use REG_NREGS in order to
    determine the number of consecutive registers.  Streamlined this with
    the implementation of s390_function_arg.

    Fix some indentation whitespace, too.

    gcc/ChangeLog:

            PR target/106355
            * config/s390/s390.c (s390_call_saved_register_used): For a
            parameter with BLKmode fix determining number of consecutive
            registers.

    gcc/testsuite/ChangeLog:

            * gcc.target/s390/pr106355.h: Common code for new tests.
            * gcc.target/s390/pr106355-1.c: New test.
            * gcc.target/s390/pr106355-2.c: New test.
            * gcc.target/s390/pr106355-3.c: New test.

    (cherry picked from commit cb994acc08b67f26a54e7c5dc1f4995a2ce24d98)

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

* [Bug target/106355] Linux s390x -O2 argument passing miscompile
  2022-07-19 14:28 [Bug other/106355] New: Linux s390x -O2 argument passing miscompile sbergman at redhat dot com
                   ` (6 preceding siblings ...)
  2022-10-25  8:37 ` cvs-commit at gcc dot gnu.org
@ 2022-10-25  8:39 ` cvs-commit at gcc dot gnu.org
  2024-02-29 20:19 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-10-25  8:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Stefan Schulze Frielinghaus
<stefansf@gcc.gnu.org>:

https://gcc.gnu.org/g:97509e98d9199ff43916250fc0a20f3d1838d067

commit r10-11059-g97509e98d9199ff43916250fc0a20f3d1838d067
Author: Stefan Schulze Frielinghaus <stefansf@linux.ibm.com>
Date:   Tue Oct 25 10:38:23 2022 +0200

    IBM zSystems: Fix function_ok_for_sibcall [PR106355]

    For a parameter with BLKmode we cannot use REG_NREGS in order to
    determine the number of consecutive registers.  Streamlined this with
    the implementation of s390_function_arg.

    Fix some indentation whitespace, too.

    gcc/ChangeLog:

            PR target/106355
            * config/s390/s390.c (s390_call_saved_register_used): For a
            parameter with BLKmode fix determining number of consecutive
            registers.

    gcc/testsuite/ChangeLog:

            * gcc.target/s390/pr106355.h: Common code for new tests.
            * gcc.target/s390/pr106355-1.c: New test.
            * gcc.target/s390/pr106355-2.c: New test.
            * gcc.target/s390/pr106355-3.c: New test.

    (cherry picked from commit cb994acc08b67f26a54e7c5dc1f4995a2ce24d98)

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

* [Bug target/106355] Linux s390x -O2 argument passing miscompile
  2022-07-19 14:28 [Bug other/106355] New: Linux s390x -O2 argument passing miscompile sbergman at redhat dot com
                   ` (7 preceding siblings ...)
  2022-10-25  8:39 ` cvs-commit at gcc dot gnu.org
@ 2024-02-29 20:19 ` mpolacek at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-29 20:19 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #9 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Assuming fixed.

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

end of thread, other threads:[~2024-02-29 20:19 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19 14:28 [Bug other/106355] New: Linux s390x -O2 argument passing miscompile sbergman at redhat dot com
2022-07-20  8:06 ` [Bug target/106355] " rguenth at gcc dot gnu.org
2022-07-20  8:14 ` sbergman at redhat dot com
2022-08-15 13:00 ` dan at danny dot cz
2022-08-15 13:20 ` stefansf at linux dot ibm.com
2022-10-19 12:29 ` cvs-commit at gcc dot gnu.org
2022-10-25  8:35 ` cvs-commit at gcc dot gnu.org
2022-10-25  8:37 ` cvs-commit at gcc dot gnu.org
2022-10-25  8:39 ` cvs-commit at gcc dot gnu.org
2024-02-29 20:19 ` mpolacek 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).