Skip to content

Commit 0290a0e

Browse files
authored
[clang][ASTImporter] Fix possible crash "given incorrect InsertPos for specialization". (#89887)
In some situations a new `VarTemplateSpecializationDecl` (for the same template) can be added during import of another one. The "insert position" that is used to insert the current object into the list of specializations is stored at start of the import and is used later. If the list changes before the insertion the position is not valid any more.
1 parent 0ae6cfc commit 0290a0e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

clang/lib/AST/ASTImporter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6565,6 +6565,11 @@ ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl(
65656565
return D2;
65666566
}
65676567

6568+
// Update InsertPos, because preceding import calls may have invalidated
6569+
// it by adding new specializations.
6570+
if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
6571+
VarTemplate->AddSpecialization(D2, InsertPos);
6572+
65686573
QualType T;
65696574
if (Error Err = importInto(T, D->getType()))
65706575
return std::move(Err);
@@ -6603,8 +6608,6 @@ ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl(
66036608
if (FoundSpecialization)
66046609
D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
66056610

6606-
VarTemplate->AddSpecialization(D2, InsertPos);
6607-
66086611
addDeclToContexts(D, D2);
66096612

66106613
// Import the rest of the chain. I.e. import all subsequent declarations.

0 commit comments

Comments
 (0)