diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp index f19067941e71..ff56c8c85a27 100644 --- a/clang/lib/CodeGen/CGCXX.cpp +++ b/clang/lib/CodeGen/CGCXX.cpp @@ -210,10 +210,14 @@ static bool canDevirtualizeMemberFunctionCalls(const Expr *Base) { return false; } - // We can always devirtualize calls on temporaries. + // We can always devirtualize calls on temporary object expressions. if (isa(Base)) return true; + // And calls on bound temporaries. + if (isa(Base)) + return true; + // Check if this is a call expr that returns a record type. if (const CallExpr *CE = dyn_cast(Base)) return CE->getCallReturnType()->isRecordType(); diff --git a/clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp b/clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp index 76f9520bfd1a..cbf55ad61331 100644 --- a/clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp +++ b/clang/test/CodeGenCXX/devirtualize-virtual-function-calls.cpp @@ -29,3 +29,19 @@ void f(A a, A *ap, A& ar) { // CHECK: call void @_ZN1A1fEv a.h().f(); } + +struct B { + virtual void f(); + ~B(); + + B h(); +}; + + +void f() { + // CHECK: call void @_ZN1B1fEv + B().f(); + + // CHECK: call void @_ZN1B1fEv + B().h().f(); +}