Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang doesn't devirtualize all vcalls in ctors/dtors #18237

Open
timurrrr opened this issue Nov 9, 2013 · 0 comments
Open

Clang doesn't devirtualize all vcalls in ctors/dtors #18237

timurrrr opened this issue Nov 9, 2013 · 0 comments
Labels
bugzilla Issues migrated from bugzilla c++ missed-devirtualization

Comments

@timurrrr
Copy link
Contributor

timurrrr commented Nov 9, 2013

Bugzilla Link 17863
Version trunk
OS Linux
CC @DougGregor,@hfinkel

Extended Description

e.g. for this code:

struct A { virtual void a(); };
struct B { virtual void b(); };
struct C : virtual A, virtual B {
C();
virtual void key_function();
virtual void a();
virtual void b();
};

C::C() { a(); b(); }
void C::key_function() {}

the assembly for C::C() at -O3 is

_ZN1CC1Ev: # complete ctor
pushq %rbx
movq %rdi, %rbx
movq $_ZTV1C+40, (%rbx)
movq $_ZTV1C+88, 8(%rbx)
callq _ZN1C1aEv # call to C::a is devirtualized
movq (%rbx), %rax
movq %rbx, %rdi
popq %rbx
jmpq *16(%rax) # call to C::b is not!
...
_ZN1CC2Ev: # base ctor
pushq %rbx
movq %rdi, %rbx
movq (%rsi), %rax
movq %rax, (%rbx)
movq 8(%rsi), %rcx
movq -32(%rax), %rax
movq %rcx, (%rbx,%rax)
movq 16(%rsi), %rax
movq (%rbx), %rcx
movq -40(%rcx), %rcx
movq %rax, (%rbx,%rcx)
movq (%rbx), %rax
callq *(%rax) # looks like even C::a is not devirtualized
movq (%rbx), %rax
movq %rbx, %rdi
popq %rbx
jmpq *16(%rax) # call C::b is not devirtualized

The same pattern holds if I define C::C() as "b(); a();" - only the
first vcall in the complete ctor is devirtualized.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++ missed-devirtualization
Projects
None yet
Development

No branches or pull requests

2 participants