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

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