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

            Bug ID: 99952
           Summary: Incompatible function call ABI between 7.5 and 9.2
           Product: gcc
           Version: 7.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gdutor at gmail dot com
  Target Milestone: ---

For such a snipet, g++-7.5.0 and g++-9.2.0 generate different ABI for function
`foo`:
```
#include <optional>

enum E {
    kA,kB,kC,kD,kE,kF
};

struct S {
    E e;
    std::optional<unsigned int> o;
};

void foo(S s) {
    fprintf(stderr, "%d\n", (int)s.e);
}

int main() {
    S s;
    foo(s);
    return 0;
}
```
7.5.0:
```
Dump of assembler code for function foo(S):
   0x0000000000400767 <+0>:     push   %rbp
   0x0000000000400768 <+1>:     mov    %rsp,%rbp
   0x000000000040076b <+4>:     sub    $0x10,%rsp
   0x000000000040076f <+8>:     mov    %rdi,-0x8(%rbp)
   0x0000000000400773 <+12>:    mov    -0x8(%rbp),%rax
   0x0000000000400777 <+16>:    mov    (%rax),%eax
   0x0000000000400779 <+18>:    mov    %eax,%edx
   0x000000000040077b <+20>:    mov    0x2008de(%rip),%rax        # 0x601060
<stderr@@GLIBC_2.2.5>
   0x0000000000400782 <+27>:    mov    $0x400a3c,%esi
   0x0000000000400787 <+32>:    mov    %rax,%rdi
   0x000000000040078a <+35>:    mov    $0x0,%eax
   0x000000000040078f <+40>:    callq  0x400650 <fprintf@plt>
   0x0000000000400794 <+45>:    nop
   0x0000000000400795 <+46>:    leaveq
   0x0000000000400796 <+47>:    retq
```
9.2.0:
```
Dump of assembler code for function foo(S):
   0x0000000000401152 <+0>:     push   %rbp
   0x0000000000401153 <+1>:     mov    %rsp,%rbp
   0x0000000000401156 <+4>:     sub    $0x10,%rsp
   0x000000000040115a <+8>:     mov    %rdi,%rdx
   0x000000000040115d <+11>:    mov    %esi,%eax
   0x000000000040115f <+13>:    mov    %rdx,-0x10(%rbp)
   0x0000000000401163 <+17>:    mov    %eax,-0x8(%rbp)
   0x0000000000401166 <+20>:    mov    -0x10(%rbp),%eax
   0x0000000000401169 <+23>:    mov    %eax,%edx
   0x000000000040116b <+25>:    mov    0x2eee(%rip),%rax        # 0x404060
<stderr@@GLIBC_2.2.5>
   0x0000000000401172 <+32>:    mov    $0x402004,%esi
   0x0000000000401177 <+37>:    mov    %rax,%rdi
   0x000000000040117a <+40>:    mov    $0x0,%eax
   0x000000000040117f <+45>:    callq  0x401040 <fprintf@plt>
   0x0000000000401184 <+50>:    nop
   0x0000000000401185 <+51>:    leaveq
   0x0000000000401186 <+52>:    retq

```

Such an incompatibility issue causes a program crash when the program is
compiled by g++ 9.2.0, and linked against a library which is compiled by g++
7.5.0

Reply via email to