[cfe-commits] r124753 - in /cfe/trunk: lib/CodeGen/CGDebugInfo.cpp test/CodeGenCXX/debug-info-template.cpp

Douglas Gregor dgregor at apple.com
Mon Mar 14 08:30:54 PDT 2011


On Feb 2, 2011, at 1:38 PM, Devang Patel wrote:

> Author: dpatel
> Date: Wed Feb  2 15:38:49 2011
> New Revision: 124753
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=124753&view=rev
> Log:
> Emit debug info for template type parameters.
> 
> Modified:
>    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>    cfe/trunk/test/CodeGenCXX/debug-info-template.cpp
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=124753&r1=124752&r2=124753&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Feb  2 15:38:49 2011
> @@ -953,9 +953,23 @@
>     }
> 
>   CollectRecordFields(RD, Unit, EltTys);
> +  llvm::SmallVector<llvm::Value *, 16> TemplateParams;
>   if (CXXDecl) {
>     CollectCXXMemberFunctions(CXXDecl, Unit, EltTys, FwdDecl);
>     CollectCXXFriends(CXXDecl, Unit, EltTys, FwdDecl);
> +    if (ClassTemplateSpecializationDecl *TSpecial
> +        = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
> +      const TemplateArgumentList &TAL = TSpecial->getTemplateArgs();
> +      for (unsigned i = 0, e = TAL.size(); i != e; ++i) {
> +        const TemplateArgument &TA = TAL[i];
> +        if (TA.getKind() == TemplateArgument::Type) {
> +          llvm::DIType TTy = getOrCreateType(TA.getAsType(), Unit);
> +          llvm::DITemplateTypeParameter TTP =
> +            DBuilder.CreateTemplateTypeParameter(TheCU, TTy.getName(), TTy);
> +          TemplateParams.push_back(TTP);
> +        }
> +      }
> +    }

This is not going to work for class template partial specializations, and it doesn't give access to the parameter name itself. 

A better approach would be to determine the class template or class template partial specialization from which this class was instantiated/specialized (using ClassTemplateSpecializationDecl::getSpecializedTemplateOrPartial) and extracting it's TemplateParameterList. The template parameter list has the template parameters in order, including their names.

For the template arguments that correspond to the template parameters, use ClassTemplateSpecializationDecl::getTemplateInstantiationArgs(). There's a 1-1 mapping between the template parameters and the instantiation arguments, so you can index the resulting TemplateArgumentList the same way you index the TemplateParameterList (to retrieve the substituted values).

I suggest abstracting the generation of the template parameter information in some subroutine that takes a TemplateParameterList and a TemplateArgumentList, since you'll also want it for function template instantiations/specializations.

	- Doug



More information about the cfe-commits mailing list