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

            Bug ID: 89627
           Summary: Miscompiled constructor call
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sch...@linux-m68k.org
                CC: wilson at gcc dot gnu.org
  Target Milestone: ---
            Target: riscv64-*-*

$ cat bind2nd.cc
#include <iostream>
#include <functional>

int
main ()
{
  auto b = std::bind2nd (std::divides<double> (), 2.0);
  double v = b (1);
  std::cout << "v = " << v << '\n';
}
$ g++ -g bind2nd.cc
$ ./a.out
v = Inf

I think the miscompilation occurs in the bind2nd function after the call to the
binder2nd constructor:

Dump of assembler code for function std::bind2nd<std::divides<double>,
double>(std::divides<double> const&, double const&):
   0x0000000000010902 <+0>:     addi    sp,sp,-96
   0x0000000000010904 <+2>:     sd      ra,88(sp)
   0x0000000000010906 <+4>:     sd      s0,80(sp)
   0x0000000000010908 <+6>:     addi    s0,sp,96
   0x000000000001090a <+8>:     sd      a0,-72(s0)
   0x000000000001090e <+12>:    sd      a1,-80(s0)
=> 0x0000000000010912 <+16>:    ld      a5,-80(s0)
   0x0000000000010916 <+20>:    fld     fa5,0(a5)
   0x0000000000010918 <+22>:    fsd     fa5,-24(s0)
   0x000000000001091c <+26>:    addi    a4,s0,-24
   0x0000000000010920 <+30>:    addi    a5,s0,-40
   0x0000000000010924 <+34>:    mv      a2,a4
   0x0000000000010926 <+36>:    ld      a1,-72(s0)
   0x000000000001092a <+40>:    mv      a0,a5
   0x000000000001092c <+42>:    jal     ra,0x10986
<std::binder2nd<std::divides<double> >::binder2nd(std::divides<double> const&,
double const&)>
   0x0000000000010930 <+46>:    ld      a5,-40(s0)
   0x0000000000010934 <+50>:    sd      a5,-56(s0)
   0x0000000000010938 <+54>:    ld      a5,-32(s0)
   0x000000000001093c <+58>:    sd      a5,-48(s0)
   0x0000000000010940 <+62>:    fld     fa5,-56(s0)
   0x0000000000010944 <+66>:    fmv.d   fa0,fa5
   0x0000000000010948 <+70>:    ld      ra,88(sp)
   0x000000000001094a <+72>:    ld      s0,80(sp)
   0x000000000001094c <+74>:    addi    sp,sp,96
   0x000000000001094e <+76>:    ret

Reply via email to