public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "wqpfelix at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/103303] New: compiler have trouble to point to the correct destructor address while for large align objects with complex inheritance while destruct object
Date: Wed, 17 Nov 2021 15:30:59 +0000	[thread overview]
Message-ID: <bug-103303-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 103303
           Summary: compiler have trouble to point to the correct
                    destructor address while for large align objects with
                    complex inheritance while destruct object
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wqpfelix at gmail dot com
  Target Milestone: ---

Created attachment 51825
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51825&action=edit
c++ code trigger the 0x8 offset for movaps

the error is reproduced on compiler explorer:
https://godbolt.org/z/v8roq3641
where I can trigger this problem while gcc after 8.1

more details: 
while running with the following compiler
```sh
$Compiler/bin/g++ -v
Using built-in specs.
COLLECT_GCC=/net/binlib/build-kits/build-kit-20191029-x86_64-pc-linux-gnu-gcc-8.2.0-gcc82_u18_v3/bin/g++
COLLECT_LTO_WRAPPER=/net/binlib/build-kits/build-kit-20191029-x86_64-pc-linux-gnu-gcc-8.2.0-gcc82_u18_v3/bin/../libexec/gcc/x86_64-pc-linux-gnu/8.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: .../gcc/configure --with-gmp={PathTo_gcc82_u18_v3}
--with-mpfr={PathTo_gcc82_u18_v3} --with-mpc={PathTo_gcc82_u18_v3}
--with-isl={PathTo_gcc82_u18_v3} --prefix={PathTo_gcc82_u18_v3}
--exec-prefix={PathTo_gcc82_u18_v3} --enable-languages=c,c++ --enable-shared
--enable-static --enable-threads=posix --disable-host-shared --enable-lto
--with-ld={PathTo_gcc82_u18_v3}/bin/ld --target=x86_64-pc-linux-gnu
--with-sysroot=/.
--with-gxx-include-dir={PathTo_gcc82_u18_v3}/include/libstdc++
--disable-multilib --verbose
Thread model: posix
gcc version 8.2.0 (GCC)
```

on C++ program with
```C++
#include <iostream>
#include <cstddef>

struct alignas(16) largeAligned{ // change to 8, no crash
    uint32_t u_arr[128];
};

template<typename Base>
struct ICategory: public virtual Base{
    ICategory(){
        std::cout << __PRETTY_FUNCTION__ << std::endl;
    }
};

struct PureInterfaceHandler{
    virtual ~PureInterfaceHandler() = default;
};

template<typename...MsgCategoryNotifierS>
class TemplateNotifier
          : public PureInterfaceHandler,
             public MsgCategoryNotifierS...{
public:
    TemplateNotifier() {
        std::cout << __PRETTY_FUNCTION__  << std::endl;
    }

    virtual ~TemplateNotifier() {
        std::cout << __PRETTY_FUNCTION__  << std::endl;
    }
};


struct Base1{
    Base1(){
        std::cout << __PRETTY_FUNCTION__  << std::endl;
    }
    virtual ~Base1(){
        std::cout << __PRETTY_FUNCTION__  << std::endl;
    }
    largeAligned aligned1;
};


struct Base2{
    Base2(){
        std::cout << __PRETTY_FUNCTION__  << std::endl;
    }
    virtual ~Base2(){
        std::cout << __PRETTY_FUNCTION__  << std::endl;
    }
    largeAligned aligned2;
};

using Category2 = ICategory<Base1>;
using Category1 = ICategory<Base2>;
struct ProblematicNotifier: TemplateNotifier<Category1, Category2>{};

int main(){
    static_assert(alignof(ProblematicNotifier) == 16, "128 is great" );
    static_assert( alignof(std::max_align_t) == 16, "16? is great" );
    ProblematicNotifier* objPtr = new ProblematicNotifier();
    delete objPtr;
    std::cout << "Done" << std::endl;
}
```


with: 
    $Compiler/bin/g++ -I $Compiler/include -I $Compiler/include/libstdc++
crash.cpp -O3
I found: 
    Program received signal SIGSEGV, Segmentation fault.
    0x000000000040228a in ProblematicNotifier::~ProblematicNotifier() ()
on instruction: 
    0x40228a <_ZN19ProblematicNotifierD0Ev+202>     movaps %xmm0,0x8(%rbx)
where (gdb) x/i $rbx
      0x417e70:    mov    $0x34,%al

it looks like compiler generates 
movaps with offset 0x8 while handling aligned object, while is not expected for
movaps

             reply	other threads:[~2021-11-17 15:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-17 15:30 wqpfelix at gmail dot com [this message]
2021-11-17 22:06 ` [Bug c++/103303] compiler have trouble to point to the correct destructor address while for large align objects with complex inheritance while destructing object pinskia at gcc dot gnu.org
2021-11-18  7:51 ` rguenth at gcc dot gnu.org
2021-11-26 14:36 ` wqpfelix at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-103303-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).