aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
authorBalázs Kéri <balazs.keri@ericsson.com>2024-06-21 12:51:43 +0200
committerGitHub <noreply@github.com>2024-06-21 12:51:43 +0200
commit0290a0e64f0d235e0e6b38283f9a389c7ab977dc (patch)
treecda7f11daf2ff8f31312673d6027808b87b4de4f /clang
parent0ae6cfc5990b0b739166bd7db370125ca66494c2 (diff)
downloadllvm-0290a0e64f0d235e0e6b38283f9a389c7ab977dc.zip
llvm-0290a0e64f0d235e0e6b38283f9a389c7ab977dc.tar.gz
llvm-0290a0e64f0d235e0e6b38283f9a389c7ab977dc.tar.bz2
[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.
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/AST/ASTImporter.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 1b67fea..4e1b3a5 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -6565,6 +6565,11 @@ ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl(
return D2;
}
+ // Update InsertPos, because preceding import calls may have invalidated
+ // it by adding new specializations.
+ if (!VarTemplate->findSpecialization(TemplateArgs, InsertPos))
+ VarTemplate->AddSpecialization(D2, InsertPos);
+
QualType T;
if (Error Err = importInto(T, D->getType()))
return std::move(Err);
@@ -6603,8 +6608,6 @@ ExpectedDecl ASTNodeImporter::VisitVarTemplateSpecializationDecl(
if (FoundSpecialization)
D2->setPreviousDecl(FoundSpecialization->getMostRecentDecl());
- VarTemplate->AddSpecialization(D2, InsertPos);
-
addDeclToContexts(D, D2);
// Import the rest of the chain. I.e. import all subsequent declarations.