This is an archive of the discontinued LLVM Phabricator instance.

[clang] Don't call inheritDefaultTemplateArguments() on CXXDeductionGuideDecl's template parameters
Needs ReviewPublic

Authored by aeubanks on Dec 1 2021, 1:42 PM.

Details

Summary

A CXXDeductionGuideDecl references its class's template parameters
(rather than cloning them). This causes us to currently call
inheritDefaultTemplateArguments() on the class template parameters
twice, which causes crashes because DefaultArgStorage::setInherited()
should only be called once.

Diff Detail

Event Timeline

aeubanks requested review of this revision.Dec 1 2021, 1:42 PM
aeubanks created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 1 2021, 1:42 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rnk added a subscriber: rnk.

Friendly ping for a modules CTAD bugfix.

rsmith added inline comments.Jan 7 2022, 12:51 PM
clang/lib/Serialization/ASTReaderDecl.cpp
3784–3790

An implicit deduction guide can get template parameters from both the class template and the constructor template. The ones from the class template are not copied and owned by the deduction guide, but the ones from the constructor template are. So I think we may need to do this for *some* of the template parameters and not others. Perhaps we could check to see if the template parameter is actually owned by this template and skip updating it if not.

(Alternatively, I think it'd be fine, and probably simpler and cleaner, to make implicit deduction guide generation always clone the template parameters of the class template. The confusion caused by having the template parameters appear in the "wrong" template is probably not justified by the time / memory savings.)

aeubanks added inline comments.Jan 10 2022, 5:13 PM
clang/lib/Serialization/ASTReaderDecl.cpp
3784–3790

I tried https://reviews.llvm.org/D116983 and it still doesn't fix this issue, although I'm having trouble understanding the Clang AST and the decl chains.
How would you check that the template parameter is owned by this template?

Friendly ping for a modules CTAD bugfix.

Not sure if you met the same problem with me. In our downstream, we did a workaround like:

if (Context.getLangOpts().CPlusPlusModules &&
      To->getOwningModule() != From->getOwningModule())
    return false;

We workarounded the problem by inserting the above checking in inheritDefaultTemplateArgument() in ASTReaderDecl. Hope this helps.
(I understand this is not a good solution)