This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/79077] New: [7 regression][new inheriting ctors] bad code for inherited ctor


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

            Bug ID: 79077
           Summary: [7 regression][new inheriting ctors]  bad code for
                    inherited ctor
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sss@li-snyder.org
  Target Milestone: ---
            Target: x86_64-pc-linux-gnu

hi -

This bug may be related to 78495.
gcc version 7.0.0 20170111 generates bad code for this example
(tested on x86_64-pc-linux-gnu):

================================================================
extern "C" {
int printf(const char* fmt, ...);
}

class xstring
{
public:
  xstring(const char* s) : m_str(s) {}
  xstring(const xstring& s) : m_str(s.m_str) {}
  const char* c_str() const { return m_str; }
  const char* m_str;
};

class Service
{
public:
  Service( xstring name)
  {
    printf (" bbb %s\n", name.c_str());
  }

};


class extends: public Service
{
public:
  using Service::Service;
};


class AlgExecStateSvc : public extends
{
public:
  AlgExecStateSvc( const xstring& name)
    : extends(name)
  {
    printf (" aaa %s\n", name.c_str());
  }
};


int main()
{
  AlgExecStateSvc ss ("asd");
  return 0;
}

================================================================


I expect this to print:


================================================================
 bbb asd
 aaa asd
================================================================

and this is what it does print with gcc6 or when compiled
with -fno-new-inheriting-ctors.  But with new-inheriting-ctors on,
then the example prints garbage after the `bbb ' in the first line;
the second line is still printed correctly.

Things seem to go wrong in the code generated for the ctor in extends
wrapping the base class.  The base Service ctor expects that %rsi
contain a pointer to the xstring structure, and the extends ctor
is called wiht %rsi being a pointer to the xstring.  However, the derived
ctor actually calls the base ctor with a pointer to a pointer to the xstring.

_ZN7extendsCI27ServiceE7xstring:
.LFB12:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
        subq    $32, %rsp
        movq    %rdi, -24(%rbp)
        movq    %rsi, -32(%rbp)
        movq    -32(%rbp), %rax
        movq    %rax, -8(%rbp)
        leaq    -8(%rbp), %rdx
        movq    -24(%rbp), %rax
        movq    %rdx, %rsi
        movq    %rax, %rdi
        call    _ZN7ServiceC2E7xstring
        nop
        leave

One can also see what appears to be an extra `&' in the 003t.original dump:

;; Function extends::extends(xstring) [inherited from Service] (null)
;; enabled by -tree-original


{
  <<cleanup_point <<< Unknown tree: expr_stmt
  Service::Service ((struct Service *) this, &*(struct xstring &) &D.2371)
>>>>>;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]