[clang] e4b9f5e - DebugInfo: Add support for template parameters with reference qualifiers

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 15 13:59:50 PDT 2021


On Wed, Sep 15, 2021 at 10:11 AM <paul.robinson at sony.com> wrote:

> Nice to see this work coming to fruition.
>

Yeah, this is fallout/cleanup for the "rebuild pretty names from template
parameter DIEs" - I have a bunch of work locally that manages to round-trip
names identically for all of clang, which is pretty good. A few types of
names are flagged in the frontend as unrebuildable, so they get the full
name - operator overloads (owing to potential ambiguity between a
conversion operator that converts to a template specialization, and a
conversion operator to a non-template type where the conversion operator
itself is a template - and atomic integer types, which we currently don't
have any DWARF structural representation of them being atomic, so far as I
can tell)

I'll be peeling some more formatting improvements/fixes off that can be
tested with the normal type printing work we have in llvm-dwarfdump, and
then eventually the full name rebuilding pieces.


>
> Comment on a comment inline.
> --paulr
>
> > -----Original Message-----
> > From: cfe-commits <cfe-commits-bounces at lists.llvm.org> On Behalf Of
> David
> > Blaikie via cfe-commits
> > Sent: Tuesday, September 14, 2021 3:41 AM
> > To: cfe-commits at lists.llvm.org
> > Subject: [clang] e4b9f5e - DebugInfo: Add support for template parameters
> > with reference qualifiers
> >
> >
> > Author: David Blaikie
> > Date: 2021-09-14T00:39:47-07:00
> > New Revision: e4b9f5e851d1fe0ba93cbb11b2ed4558602c379e
> >
> > URL: https://urldefense.com/v3/__https://github.com/llvm/llvm-
> >
> project/commit/e4b9f5e851d1fe0ba93cbb11b2ed4558602c379e__;!!JmoZiZGBv3RvKR
> > Sx!pPDWW11rGokficZF20VnsBpjjCjLLhat-SnLoi9Iun-i_taCUiQMW_3RbXPXB8CHMg$
> > DIFF: https://urldefense.com/v3/__https://github.com/llvm/llvm-
> >
> project/commit/e4b9f5e851d1fe0ba93cbb11b2ed4558602c379e.diff__;!!JmoZiZGBv
> > 3RvKRSx!pPDWW11rGokficZF20VnsBpjjCjLLhat-SnLoi9Iun-
> > i_taCUiQMW_3RbXOfYKwRDQ$
> >
> > LOG: DebugInfo: Add support for template parameters with reference
> > qualifiers
> >
> > Followon from the previous commit supporting cvr qualifiers.
> >
> > Added:
> >
> >
> > Modified:
> >     clang/lib/CodeGen/CGDebugInfo.cpp
> >     clang/test/CodeGenCXX/debug-info-template.cpp
> >
> > Removed:
> >
> >
> >
> >
> ##########################################################################
> > ######
> > diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp
> > b/clang/lib/CodeGen/CGDebugInfo.cpp
> > index b7a6cd4fdf84..e4dc3121a10f 100644
> > --- a/clang/lib/CodeGen/CGDebugInfo.cpp
> > +++ b/clang/lib/CodeGen/CGDebugInfo.cpp
> > @@ -1338,6 +1338,15 @@ static unsigned getDwarfCC(CallingConv CC) {
> >    return 0;
> >  }
> >
> > +static llvm::DINode::DIFlags getRefFlags(const FunctionProtoType *Func)
> {
> > +  llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
> > +  if (Func->getExtProtoInfo().RefQualifier == RQ_LValue)
> > +    Flags |= llvm::DINode::FlagLValueReference;
> > +  if (Func->getExtProtoInfo().RefQualifier == RQ_RValue)
> > +    Flags |= llvm::DINode::FlagRValueReference;
> > +  return Flags;
> > +}
> > +
> >  llvm::DIType *CGDebugInfo::CreateType(const FunctionType *Ty,
> >                                        llvm::DIFile *Unit) {
> >    const auto *FPT = dyn_cast<FunctionProtoType>(Ty);
> > @@ -1353,11 +1362,13 @@ llvm::DIType *CGDebugInfo::CreateType(const
> > FunctionType *Ty,
> >    // Add the result type at least.
> >    EltTys.push_back(getOrCreateType(Ty->getReturnType(), Unit));
> >
> > +  llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
> >    // Set up remainder of arguments if there is a prototype.
> >    // otherwise emit it as a variadic function.
> >    if (!FPT)
> >      EltTys.push_back(DBuilder.createUnspecifiedParameter());
> >    else {
> > +    Flags = getRefFlags(FPT);
> >      for (const QualType &ParamType : FPT->param_types())
> >        EltTys.push_back(getOrCreateType(ParamType, Unit));
> >      if (FPT->isVariadic())
> > @@ -1365,7 +1376,7 @@ llvm::DIType *CGDebugInfo::CreateType(const
> > FunctionType *Ty,
> >    }
> >
> >    llvm::DITypeRefArray EltTypeArray =
> > DBuilder.getOrCreateTypeArray(EltTys);
> > -  llvm::DIType *F = DBuilder.createSubroutineType(EltTypeArray,
> > llvm::DINode::FlagZero,
> > +  llvm::DIType *F = DBuilder.createSubroutineType(EltTypeArray, Flags,
> >                                         getDwarfCC(Ty->getCallConv()));
> >    return F;
> >  }
> > @@ -1640,15 +1651,17 @@
> > CGDebugInfo::getOrCreateInstanceMethodType(QualType ThisPtr,
> >    Qc.removeUnaligned();
> >    // Keep the removed qualifiers in sync with
> >    // CreateQualifiedType(const FunctionPrototype*, DIFile *Unit)
> > +  // on a 'real' member function type, these qualifiers are carried on
> > the type
> > +  // of the first parameter, not as separate DW_TAG_const_type (etc)
> > decorator
> > +  // tags around them. (but in the raw function types with qualifiers,
> > they have
> > +  // to use wrapper types)
>
> Please use proper capitalization and punctuation in comments.
> s/on/On/, s/(but/(But/, s/types)/types.)/
>
>
Oh, sure - done in

8264846c0ef847adeacca9b8fe0f867a8a378c5e


> >
> >    // Add "this" pointer.
> > -  llvm::DITypeRefArray Args(
> > -      cast<llvm::DISubroutineType>(
> > -          getOrCreateType(
> > -              CGM.getContext().getFunctionType(Func->getReturnType(),
> > -                                               Func->getParamTypes(),
> > EPI),
> > -              Unit))
> > -          ->getTypeArray());
> > +  const auto *OriginalFunc = cast<llvm::DISubroutineType>(
> > +      getOrCreateType(CGM.getContext().getFunctionType(
> > +                          Func->getReturnType(), Func->getParamTypes(),
> > EPI),
> > +                      Unit));
> > +  llvm::DITypeRefArray Args = OriginalFunc->getTypeArray();
> >    assert(Args.size() && "Invalid number of arguments!");
> >
> >    SmallVector<llvm::Metadata *, 16> Elts;
> > @@ -1690,13 +1703,7 @@
> CGDebugInfo::getOrCreateInstanceMethodType(QualType
> > ThisPtr,
> >
> >    llvm::DITypeRefArray EltTypeArray =
> > DBuilder.getOrCreateTypeArray(Elts);
> >
> > -  llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
> > -  if (Func->getExtProtoInfo().RefQualifier == RQ_LValue)
> > -    Flags |= llvm::DINode::FlagLValueReference;
> > -  if (Func->getExtProtoInfo().RefQualifier == RQ_RValue)
> > -    Flags |= llvm::DINode::FlagRValueReference;
> > -
> > -  return DBuilder.createSubroutineType(EltTypeArray, Flags,
> > +  return DBuilder.createSubroutineType(EltTypeArray, OriginalFunc-
> > >getFlags(),
> >                                         getDwarfCC(Func->getCallConv()));
> >  }
> >
> >
> > diff  --git a/clang/test/CodeGenCXX/debug-info-template.cpp
> > b/clang/test/CodeGenCXX/debug-info-template.cpp
> > index 0abb669b6535..510c82a5074f 100644
> > --- a/clang/test/CodeGenCXX/debug-info-template.cpp
> > +++ b/clang/test/CodeGenCXX/debug-info-template.cpp
> > @@ -218,13 +218,13 @@ template void f1<>();
> >
> >  namespace RawFuncQual {
> >  struct t1; // use this to ensure the type parameter doesn't shift due to
> > other test cases in this file
> > -template<typename T1, typename T2>
> > +template<typename T1, typename T2, typename T3, typename T4>
> >  void f1() { }
> > -template void f1<t1 () volatile, t1 () const volatile>();
> > -// CHECK: !DISubprogram(name: "f1<RawFuncQual::t1 () volatile,
> > RawFuncQual::t1 () const volatile>",
> > +template void f1<t1 () volatile, t1 () const volatile, t1 () &, t1 ()
> > &&>();
> > +// CHECK: !DISubprogram(name: "f1<RawFuncQual::t1 () volatile,
> > RawFuncQual::t1 () const volatile, RawFuncQual::t1 () &, RawFuncQual::t1
> > () &&>",
> >  // CHECK-SAME: templateParams: ![[RAW_FUNC_QUAL_ARGS:[0-9]*]],
> >
> > -// CHECK: ![[RAW_FUNC_QUAL_ARGS]] = !{![[RAW_FUNC_QUAL_T1:[0-9]*]],
> > ![[RAW_FUNC_QUAL_T2:[0-9]*]]}
> > +// CHECK: ![[RAW_FUNC_QUAL_ARGS]] = !{![[RAW_FUNC_QUAL_T1:[0-9]*]],
> > ![[RAW_FUNC_QUAL_T2:[0-9]*]], ![[RAW_FUNC_QUAL_T3:[0-9]*]],
> > ![[RAW_FUNC_QUAL_T4:[0-9]*]]}
> >  // CHECK: ![[RAW_FUNC_QUAL_T1]] = !DITemplateTypeParameter(name: "T1",
> > type: ![[RAW_FUNC_QUAL_VOL:[0-9]*]])
> >  // CHECK: ![[RAW_FUNC_QUAL_VOL]] = !DIDerivedType(tag:
> > DW_TAG_volatile_type, baseType: ![[RAW_FUNC_QUAL_TYPE:[0-9]*]])
> >  // CHECK: ![[RAW_FUNC_QUAL_TYPE]] = !DISubroutineType(types:
> > ![[RAW_FUNC_QUAL_LIST:[0-9]*]]
> > @@ -232,5 +232,9 @@ template void f1<t1 () volatile, t1 () const
> > volatile>();
> >  // CHECK: ![[RAW_FUNC_QUAL_STRUCT]] = !DICompositeType(tag:
> > DW_TAG_structure_type, name: "t1"
> >  // CHECK: ![[RAW_FUNC_QUAL_T2]] = !DITemplateTypeParameter(name: "T2",
> > type: ![[RAW_FUNC_QUAL_CNST:[0-9]*]])
> >  // CHECK: ![[RAW_FUNC_QUAL_CNST]] = !DIDerivedType(tag:
> > DW_TAG_const_type, baseType: ![[RAW_FUNC_QUAL_TYPE:[0-9]*]])
> > +// CHECK: ![[RAW_FUNC_QUAL_T3]] = !DITemplateTypeParameter(name: "T3",
> > type: ![[RAW_FUNC_QUAL_REF:[0-9]*]])
> > +// CHECK: ![[RAW_FUNC_QUAL_REF]] = !DISubroutineType(flags:
> > DIFlagLValueReference, types: ![[RAW_FUNC_QUAL_LIST]])
> > +// CHECK: ![[RAW_FUNC_QUAL_T4]] = !DITemplateTypeParameter(name: "T4",
> > type: ![[RAW_FUNC_QUAL_REF_REF:[0-9]*]])
> > +// CHECK: ![[RAW_FUNC_QUAL_REF_REF]] = !DISubroutineType(flags:
> > DIFlagRValueReference, types: ![[RAW_FUNC_QUAL_LIST]])
> >
> >  } // namespace RawFuncQual
> >
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at lists.llvm.org
> > https://urldefense.com/v3/__https://lists.llvm.org/cgi-
> > bin/mailman/listinfo/cfe-
> > commits__;!!JmoZiZGBv3RvKRSx!pPDWW11rGokficZF20VnsBpjjCjLLhat-SnLoi9Iun-
> > i_taCUiQMW_3RbXOKUGruLQ$
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210915/cb47d937/attachment.html>


More information about the llvm-commits mailing list