This is an archive of the discontinued LLVM Phabricator instance.

[clang] fix profiling of template arguments of template and declaration kind
ClosedPublic

Authored by mizvekov on Aug 31 2022, 5:05 PM.

Details

Summary

Template arguments of template and declaration kind were being profiled
only by their canonical properties, which would cause incorrect
uniquing of constrained AutoTypes, leading to a crash in some cases.

This exposed some places in CheckTemplateArgumentList where non-canonical
arguments where being pushed into the resulting converted list.

We also throw in some asserts to catch early and explain the crashes.

Note that the fix for the 'declaration' kind is untestable at this point,
because there should be no cases right now in the AST where we try
to unique a non-canonical converted template argument.

This fixes GH55567.

Depends on D133082

Signed-off-by: Matheus Izvekov <mizvekov@gmail.com>

Diff Detail

Event Timeline

mizvekov created this revision.Aug 31 2022, 5:05 PM
Herald added projects: Restricted Project, Restricted Project, Restricted Project. · View Herald TranscriptAug 31 2022, 5:05 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
mizvekov requested review of this revision.Aug 31 2022, 5:05 PM
mizvekov added reviewers: Restricted Project, rsmith, davrec.Aug 31 2022, 8:05 PM
mizvekov retitled this revision from WIP: [clang] fix profiling of template arguments of template and declaration kind to [clang] fix profiling of template arguments of template and declaration kind.Sep 1 2022, 1:37 AM
mizvekov added reviewers: aaron.ballman, erichkeane.

Generally happy here. Two quick suggestions, otherewise LGTM.

clang/lib/AST/ASTContext.cpp
5119–5121

Instead of maybe_unused put this and the assert inside of a #if NDEBUG so we don't do the Nothing work. Same below.

clang/lib/Sema/SemaTemplate.cpp
5817–5818

Ooh, thats a transform!

llvm::transform(ArgumentPack, std::back_inserter(Converted), [](const auto &I) { return Context.getCanonicalTemplateArgument(I));

mizvekov added inline comments.Sep 1 2022, 6:27 AM
clang/lib/AST/ASTContext.cpp
5119–5121

We still need to do the FindNodeOrInsertPos bit, to refresh the insert position.
So I think this would end up too noisy to add two sets of blocks.

clang/lib/Sema/SemaTemplate.cpp
5817–5818

That is true, though unless we can come up with a clearer spelling for that, it looks less readable to me.

erichkeane accepted this revision.Sep 1 2022, 6:29 AM
erichkeane added inline comments.
clang/lib/AST/ASTContext.cpp
5119–5121

Ah! I didn't realize we were counting on the side-effects here. Thanks!

clang/lib/Sema/SemaTemplate.cpp
5817–5818

But I like transform :(

mizvekov added inline comments.Sep 1 2022, 6:35 AM
clang/lib/Sema/SemaTemplate.cpp
5817–5818

I will think of something, even if we have to add a new helper :)

mizvekov updated this revision to Diff 457819.Sep 3 2022, 2:24 PM
mizvekov edited the summary of this revision. (Show Details)
mizvekov marked 2 inline comments as done.
mizvekov added inline comments.Sep 6 2022, 9:28 AM
clang/lib/Sema/SemaTemplate.cpp
5817–5818

I'll try to address this concern, about having a helper which returns a transformed copy of a container, in a way that reads better than the pure transform as suggested, in a follow up patch. Meanwhile I'll offload this patch, as my stack is too big right now.

This revision was not accepted when it landed; it landed in state Needs Review.Sep 6 2022, 9:28 AM
This revision was automatically updated to reflect the committed changes.