https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80577
Bug ID: 80577
Summary: Avoid using adj in member function pointers
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: drepper.fsp+rhbz at gmail dot com
Target Milestone: ---
Consider the following code:
struct foo final {
int a = 0, b = 0;
int get1() const { return a; }
int get2() const { return a + b; }
};
foo f;
int (foo::*mfp)() const = &foo::get1;
int get()
{
return (f.*mfp)();
}
When compiled get() looks on x86-64 like this:
movq mfp+8(%rip), %rax
leaq f(%rax), %rdi
jmp *mfp(%rip)
The compiler knows the type 'foo'. It can determine that there is no multiple
inheritence. This means that the adj field in the member function pointer will
always be zero. Hence the generated code should be
movl $f, %esi
jmp *mfp(%rip)