This is an archive of the discontinued LLVM Phabricator instance.

[SemaCXX] Properly scope ArgumentPackSubstitutionIndex when expanding base types
Needs ReviewPublic

Authored by colavitam on Feb 5 2022, 2:50 PM.

Details

Summary

Resolve the crash in issue #53609. The ArgumentPackSubstitutionIndex
from expanding base types containing parameter packs should not persist
when we check the resulting types. Checking the types may lead to
template substitution in the base type, where the index will no longer
be valid.

Fixes #53609

Diff Detail

Event Timeline

colavitam created this revision.Feb 5 2022, 2:50 PM
colavitam requested review of this revision.Feb 5 2022, 2:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 5 2022, 2:50 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
colavitam updated this revision to Diff 406213.Feb 5 2022, 2:55 PM

Fix comments for new test case.

colavitam edited the summary of this revision. (Show Details)Feb 7 2022, 3:10 PM
RKSimon added inline comments.Feb 23 2022, 4:21 AM
clang/lib/Sema/SemaTemplateInstantiate.cpp
2536

I'm not familiar with this code at all - but we've gone from having a local shadow BaseTypeLoc variable to reusing the BaseTypeLoc declared at line#2510 - is that what we actually want?

Yes, in my opinion the original shadow was accidental—you can see that every usage of BaseTypeLoc is immediately preceded by an initialization, though sometimes in a more nested scope. When initialized in the parameter pack loop, we skip to the next iteration of the outer loop instead of accessing it in the non-parameter pack path.

Ping. Is there anyone familiar with the template instantiation code I should add as a reviewer?

Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2022, 2:30 PM

Adding Erich as he's been staring at the template instantiation code recently and may have thoughts/opinions. To me, this seems like the correct approach though.

clang/lib/Sema/SemaTemplateInstantiate.cpp
2536

I don't think it matters. After this for loop terminates, we continue the outer loop. That said, this does make the code harder to read, we may want to use a local instead of reusing the outer variable like this.

clang/test/SemaCXX/template-base-class-pack-expansion.cpp
2

Can we test more than just not crashing? (e.g., can we test that the expansion happened properly?) Perhaps an AST dump test, at a minimum?

I think this patch makes sense to me. I Do like the ideas of making sure these instantiate properly though.