On Oct 11, 2009, at 4:55 PM, Anders Carlsson wrote: > Author: andersca > Date: Sun Oct 11 18:55:52 2009 > New Revision: 83816 > > URL: http://llvm.org/viewvc/llvm-project?rev=83816&view=rev > Log: > If the base type of a member call is a record type we don't need to > emit a virtual call.
This doesn't look right... details below. > Modified: > cfe/trunk/lib/CodeGen/CGCXX.cpp > cfe/trunk/test/CodeGenCXX/virtual-function-calls.cpp > > Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=83816&r1=83815&r2=83816&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- cfe/trunk/lib/CodeGen/CGCXX.cpp (original) > +++ cfe/trunk/lib/CodeGen/CGCXX.cpp Sun Oct 11 18:55:52 2009 > @@ -230,10 +230,13 @@ > // C++ [class.virtual]p12: > // Explicit qualification with the scope operator (5.1) > suppresses the > // virtual call mechanism. > + // > + // We also don't emit a virtual call if the base expression has a > record type > + // because then we know what the type is. > llvm::Value *Callee; > - if (MD->isVirtual() && !ME->hasQualifier()) > - // FIXME: push getCanonicalDecl as a conversion using the > static type system (CanCXXMethodDecl). > - Callee = BuildVirtualCall(MD->getCanonicalDecl(), This, Ty); > + if (MD->isVirtual() && !ME->hasQualifier() && > + !ME->getBase()->getType()->isRecordType()) > + Callee = BuildVirtualCall(MD, This, Ty); The type of the expression could be a record type even if the dynamic type of the object isn't known at compile time. If I tweak your example like this: void f(A &a) { a.f('c'); } I now get a direct call, when I should get a virtual call. To do this devirtualization, I suggest abstracting the "find the dynamic type of this expression" logic into a separate function. Then, we can teach it about common cases, such as referring to a VarDecl of (non-reference) type, constructing a temporary of a specific type, etc. I expect that this logic will get smarter over time, as we think of more analyses that can help make this distinction. - Doug _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
