public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [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
@ 2021-11-17 15:30 wqpfelix at gmail dot com
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
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: wqpfelix at gmail dot com @ 2021-11-17 15:30 UTC (permalink / raw)
To: gcc-bugs
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/103303] compiler have trouble to point to the correct destructor address while for large align objects with complex inheritance while destructing object
2021-11-17 15:30 [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 wqpfelix at gmail dot com
@ 2021-11-17 22:06 ` 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
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-17 22:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103303
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
#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::uintptr_t t = (std::uintptr_t)this;
printf("this:%lx\n", (long)(t&0xff));
printf("this->PureInterfaceHandler:%lx\n",
(long)((std::uintptr_t)(PureInterfaceHandler*)this&0xff));
(printf("this->%s:%lx\n", typeid
(MsgCategoryNotifierS).name(),(long)((std::uintptr_t)(MsgCategoryNotifierS*)this&0xff)),...);
std::cout << __PRETTY_FUNCTION__ << std::endl;
}
};
struct Base1{
Base1(){
std::cout << __PRETTY_FUNCTION__ << std::endl;
std::uintptr_t t = (std::uintptr_t)&aligned1;
printf("%lx\n", (long)(t&0xff));
}
virtual ~Base1(){
std::uintptr_t t = (std::uintptr_t)&aligned1;
printf("%lx\n", (long)(t&0xff));
std::cout << __PRETTY_FUNCTION__ << std::endl;
}
largeAligned aligned1;
};
struct Base2{
Base2(){
std::cout << __PRETTY_FUNCTION__ << std::endl;
std::uintptr_t t = (std::uintptr_t)&aligned2;
printf("%lx\n", (long)(t&0xff));
}
virtual ~Base2(){
std::uintptr_t t = (std::uintptr_t)&aligned2;
printf("%lx\n", (long)(t&0xff));
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;
}
Looks like there is some wrong alignment information feed to the rest of the
compiler.
this->9ICategoryI5Base2E:b8
this->9ICategoryI5Base1E:c0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/103303] compiler have trouble to point to the correct destructor address while for large align objects with complex inheritance while destructing object
2021-11-17 15:30 [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 wqpfelix at gmail dot com
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
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-11-18 7:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103303
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |11.2.0, 8.2.0
Version|8.2.0 |11.2.0
CC| |jason at gcc dot gnu.org
Keywords| |ABI
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Maybe an issue in the C++ layout engine.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/103303] compiler have trouble to point to the correct destructor address while for large align objects with complex inheritance while destructing object
2021-11-17 15:30 [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 wqpfelix at gmail dot com
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
2 siblings, 0 replies; 4+ messages in thread
From: wqpfelix at gmail dot com @ 2021-11-26 14:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103303
--- Comment #3 from Felix Wang <wqpfelix at gmail dot com> ---
Could I assume this is a compiler bug in layout engine?
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-26 14:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-17 15:30 [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 wqpfelix at gmail dot com
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
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).