diff options
author | Nico Weber <nicolasweber@gmx.de> | 2014-08-15 23:21:41 +0000 |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2014-08-15 23:21:41 +0000 |
commit | 4a38c1f9dd8045503a8c6bb7855232a5eba4566b (patch) | |
tree | 24491e378995d56b8428b072a267836ddd9a3c20 /lib/Sema/SemaTemplateInstantiateDecl.cpp | |
parent | 170ebf4f19459ae51a9561d0e65c87ee4c9b2c97 (diff) |
Make sure that vtables referenced from delay-parsed templates get referenced.
This fixes PR20671, see the bug for details. In short, ActOnTranslationUnit()
calls DefineUsedVTables() and only then PerformPendingInstantiations(). But
PerformPendingInstantiations() is what does delayed template parsing, so
vtables only references from late-parsed templates weren't marked used.
As a fix, move the SavePendingInstantiationsAndVTableUsesRAII in
PerformPendingInstantiations() up above the delayed template parsing code.
That way, vtables referenced from templates end up in the RAII object, and the
call to DefineUsedVTables() in PerformPendingInstantiations() marks them used.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215786 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiateDecl.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index b73c2b137c..747eaf6d96 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3319,6 +3319,20 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, return; } + // If we're performing recursive template instantiation, create our own + // queue of pending implicit instantiations that we will instantiate later, + // while we're still within our own instantiation context. + // This has to happen before LateTemplateParser below is called, so that + // it marks vtables used in late parsed templates as used. + SavePendingLocalImplicitInstantiationsRAII + SavedPendingLocalImplicitInstantiations(*this); + std::unique_ptr<SavePendingInstantiationsAndVTableUsesRAII> + SavePendingInstantiationsAndVTableUses; + if (Recursive) { + SavePendingInstantiationsAndVTableUses.reset( + new SavePendingInstantiationsAndVTableUsesRAII(*this)); + } + // Call the LateTemplateParser callback if there is a need to late parse // a templated function definition. if (!Pattern && PatternDecl->isLateTemplateParsed() && @@ -3350,6 +3364,7 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, Function->setInvalidDecl(); } else if (Function->getTemplateSpecializationKind() == TSK_ExplicitInstantiationDefinition) { + assert(!Recursive); PendingInstantiations.push_back( std::make_pair(Function, PointOfInstantiation)); } @@ -3386,18 +3401,6 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, // Copy the inner loc start from the pattern. Function->setInnerLocStart(PatternDecl->getInnerLocStart()); - // If we're performing recursive template instantiation, create our own - // queue of pending implicit instantiations that we will instantiate later, - // while we're still within our own instantiation context. - SavePendingLocalImplicitInstantiationsRAII - SavedPendingLocalImplicitInstantiations(*this); - std::unique_ptr<SavePendingInstantiationsAndVTableUsesRAII> - SavePendingInstantiationsAndVTableUses; - if (Recursive) { - SavePendingInstantiationsAndVTableUses.reset( - new SavePendingInstantiationsAndVTableUsesRAII(*this)); - } - EnterExpressionEvaluationContext EvalContext(*this, Sema::PotentiallyEvaluated); |