[cfe-commits] r89736 - in /cfe/trunk: lib/CodeGen/CGCall.cpp lib/CodeGen/CGVtable.cpp lib/CodeGen/CodeGenTypes.h test/CodeGenCXX/virtual-functions-incomplete-types.cpp

Eli Friedman eli.friedman at gmail.com
Mon Nov 23 21:35:30 PST 2009


On Mon, Nov 23, 2009 at 9:08 PM, Anders Carlsson <andersca at mac.com> wrote:
> Author: andersca
> Date: Mon Nov 23 23:08:52 2009
> New Revision: 89736
>
> URL: http://llvm.org/viewvc/llvm-project?rev=89736&view=rev
> Log:
> It is common for vtables to contain pointers to functions that have either incomplete return types or incomplete argument types.
>
> Handle this by returning the llvm::OpaqueType for those cases, which CodeGenModule::GetOrCreateLLVMFunction knows about, and treats as being an "incomplete function".
>
> Added:
>    cfe/trunk/test/CodeGenCXX/virtual-functions-incomplete-types.cpp
> Modified:
>    cfe/trunk/lib/CodeGen/CGCall.cpp
>    cfe/trunk/lib/CodeGen/CGVtable.cpp
>    cfe/trunk/lib/CodeGen/CodeGenTypes.h
>
> Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=89736&r1=89735&r2=89736&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Nov 23 23:08:52 2009
> @@ -418,6 +418,32 @@
>   return llvm::FunctionType::get(ResultType, ArgTys, IsVariadic);
>  }
>
> +static bool HasIncompleteReturnTypeOrArgumentTypes(const FunctionProtoType *T) {
> +  if (const TagType *TT = T->getResultType()->getAs<TagType>()) {
> +    if (!TT->getDecl()->isDefinition())
> +      return true;
> +  }
> +
> +  for (unsigned i = 0, e = T->getNumArgs(); i != e; ++i) {
> +    if (const TagType *TT = T->getArgType(i)->getAs<TagType>()) {
> +      if (!TT->getDecl()->isDefinition())
> +        return true;
> +    }
> +  }
> +
> +  return false;
> +}
> +
> +const llvm::Type *
> +CodeGenTypes::GetFunctionTypeForVtable(const CXXMethodDecl *MD) {
> +  const FunctionProtoType *FPT = MD->getType()->getAs<FunctionProtoType>();
> +
> +  if (!HasIncompleteReturnTypeOrArgumentTypes(FPT))
> +    return GetFunctionType(getFunctionInfo(MD), FPT->isVariadic());
> +
> +  return llvm::OpaqueType::get(getLLVMContext());
> +}

I'm not sure if this matters other than the cleanliness of the IR, but
this isn't quite the same as the normal handling for incomplete
function types in CodeGenTypes::ConvertNewType.  Specifically, this
bypasses the handling to resolve the opaque type to a proper function
type.

Also, HasIncompleteReturnTypeOrArgumentTypes is roughly equivalent to
VerifyFuncTypeComplete in CodeGenTypes.cpp.

-Eli




More information about the cfe-commits mailing list