On Aug 25, 2009, at 6:54 PM, Mike Stump wrote: > Author: mrs > Date: Tue Aug 25 20:54:35 2009 > New Revision: 80064 > > URL: http://llvm.org/viewvc/llvm-project?rev=80064&view=rev > Log: > Implement virtual dispatch. :-) This is self-consistent with > clang, but not yet > necessarily perfectly consistent with gcc.
Sweet. > Modified: > cfe/trunk/lib/CodeGen/CGCXX.cpp > cfe/trunk/lib/CodeGen/CodeGenFunction.h > cfe/trunk/test/CodeGenCXX/virt.cpp > > Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=80064&r1=80063&r2=80064&view=diff > > = > = > = > = > = > = > = > = > ====================================================================== > --- cfe/trunk/lib/CodeGen/CGCXX.cpp (original) > +++ cfe/trunk/lib/CodeGen/CGCXX.cpp Tue Aug 25 20:54:35 2009 > @@ -200,15 +200,9 @@ > > const FunctionProtoType *FPT = MD->getType()- > >getAsFunctionProtoType(); > > - if (MD->isVirtual()) { > - ErrorUnsupported(CE, "virtual dispatch"); > - } > - > const llvm::Type *Ty = > CGM.getTypes().GetFunctionType(CGM.getTypes().getFunctionInfo(MD), > FPT->isVariadic()); > - llvm::Constant *Callee = CGM.GetAddrOfFunction(GlobalDecl(MD), Ty); > - > llvm::Value *This; > > if (ME->isArrow()) > @@ -217,6 +211,12 @@ > LValue BaseLV = EmitLValue(ME->getBase()); > This = BaseLV.getAddress(); > } > + > + llvm::Value *Callee; > + if (MD->isVirtual()) > + Callee = BuildVirtualCall(MD, This, Ty); Checking that this is a reference to a virtual method is necessary, but not sufficient. We also need to check that the name was not qualified, e.g., Base::foo(my); is a static dispatch rather than a virtual dispatch. This will probably require some more AST support, to keep track of the nested- name-specifier in a MemberExpr. - Doug _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
