[clang] 0290a0e - [clang][ASTImporter] Fix possible crash "given incorrect InsertPos for specialization". (#89887)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 21 03:51:47 PDT 2024
Author: Balázs Kéri
Date: 2024-06-21T12:51:43+02:00
New Revision: 0290a0e64f0d235e0e6b38283f9a389c7ab977dc
URL: https://github.com/llvm/llvm-project/commit/0290a0e64f0d235e0e6b38283f9a389c7ab977dc
DIFF: https://github.com/llvm/llvm-project/commit/0290a0e64f0d235e0e6b38283f9a389c7ab977dc.diff
LOG: [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.
Added:
Modified:
clang/lib/AST/ASTImporter.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 1b67feaae8874..4e1b3a5a94de7 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.
More information about the cfe-commits
mailing list