This is an archive of the discontinued LLVM Phabricator instance.

[clang][DebugInfo] Simplify logic to determine DW_AT_default_value for template parameters
ClosedPublic

Authored by Michael137 on Dec 13 2022, 5:52 PM.

Details

Summary

DWARFv5 added support for labelling template parameters with
DW_AT_default_value to indicate whether the particular instantiation
defaulted parameter. The current implementation only supports a limited
set of possible cases. Namely for non-value-dependent integral template
parameters and simple type template parameters.

Useful cases that don't work are:

  1. Type template parameters with defaults that are

themselves templates. E.g.,

template<typename T1, typename T2 = Foo<T1>> class C1;
template<typename T = Foo<int>> class C2;
etc.
  1. Template template parameters

clang::isSubstitutedDefaultArgument already implement the required logic
to determine whether a template argument is defaulted. This patch re-uses
this logic for DWARF CodeGen.

Diff Detail

Event Timeline

Michael137 created this revision.Dec 13 2022, 5:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2022, 5:52 PM
Michael137 requested review of this revision.Dec 13 2022, 5:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2022, 5:52 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aprantl accepted this revision.Dec 14 2022, 9:26 AM

That looks nicer than the old code.

This revision is now accepted and ready to land.Dec 14 2022, 9:26 AM

Partly feedback on D139989 too - if we could move this logic outside the switch, then it wouldn't need to be done in each different template parameter type? (& then D139989 I guess wouldn't be needed - this patch and the other would be subsumed by removing the old logic from distinct switch cases, and putting the new logic that works across different template parameter kinds outside the switch - solving things more generically)

  • Hoist common code out of switch
dblaikie accepted this revision.Dec 15 2022, 12:27 PM

Looks good to me, thanks!

Patch description might need a tweak, this bit:

Type template parameters where the type is itself a template instantiation (e.g., template<typename T = Foo<T>>)

The quoted example is impossible (infinitely recursive) & the description might be less specific than necessary - is any template instantiation a problem (eg: template<typename T = Foo<int>) for the existing code/addressed by this patch, or only defaults that are instantiated with a prior template parameter in the same template parameter list? If it's the latter, would be good to include that nuance, if it's the former might be worth clarifying that/using some Foo<int> in the example insetad of Foo<T>

Looks good to me, thanks!

Patch description might need a tweak, this bit:

Type template parameters where the type is itself a template instantiation (e.g., template<typename T = Foo<T>>)

The quoted example is impossible (infinitely recursive) & the description might be less specific than necessary - is any template instantiation a problem (eg: template<typename T = Foo<int>) for the existing code/addressed by this patch, or only defaults that are instantiated with a prior template parameter in the same template parameter list? If it's the latter, would be good to include that nuance, if it's the former might be worth clarifying that/using some Foo<int> in the example insetad of Foo<T>

Whoops good catch. What I meant to say is template<typename T1, typename T2 = Foo<T1>>. Will update the commit message

Michael137 retitled this revision from [clang][DebugInfo] Re-use clang::TemplateUtils to determine guide DW_AT_default_value for template parameters to [clang][DebugInfo] Simplify logic to determine DW_AT_default_value for template parameters.Dec 15 2022, 2:25 PM
Michael137 edited the summary of this revision. (Show Details)
  • Remove now redundant header
This revision was landed with ongoing or failed builds.Dec 16 2022, 3:39 AM
This revision was automatically updated to reflect the committed changes.