https://llvm.org/bugs/show_bug.cgi?id=27096

            Bug ID: 27096
           Summary: clang does not devirtualize method pointer calls
                    against final classes when method identity is known at
                    compile time
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Keywords: code-quality
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangb...@nondot.org
          Reporter: hlan...@devever.net
                CC: dgre...@apple.com, llvm-bugs@lists.llvm.org
    Classification: Unclassified

// Example:
struct Foo final {
  virtual int bar();  
};

int a(Foo &f, int (Foo::*fp)()) {
  return (f.*fp)(); 
}

int b(Foo &f) {
  return a(f, &Foo::bar);
}

// Generated assembly:
b(Foo&):                                # @b(Foo&)
        mov     rax, qword ptr [rdi]
        jmp     qword ptr [rax]         # TAILCALL

// Expected assembly:
b(Foo&):                              # @b(Foo&)
        jmp     Foo::bar()            # TAILCALL

// Generates expected assembly:
int c(Foo &f) {
  return f.bar();
}

// This is the assembly for a, which generates a more conservative
// method pointer call, demonstrating that the knowledge about the identity of
// fp when inlining in b is definitely used to generate the code above.
// Yet the devirtualization which could be taken as a further step above does
not occur.
a(Foo&, int (Foo::*)()):                       # @a(Foo&, int (Foo::*)())
        add     rdi, rdx
        test    sil, 1
        je      .LBB0_2
        mov     rax, qword ptr [rdi]
        mov     rsi, qword ptr [rsi + rax - 1]
.LBB0_2:
        jmp     rsi                            # TAILCALL

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to