LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 17863 - Clang doesn't devirtualize all vcalls in ctors/dtors
Summary: Clang doesn't devirtualize all vcalls in ctors/dtors
Status: NEW
Alias: None
Product: clang
Classification: Unclassified
Component: C++ (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-09 07:15 PST by Timur Iskhodzhanov
Modified: 2013-11-11 12:18 PST (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Timur Iskhodzhanov 2013-11-09 07:15:08 PST
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.