From 8367c1d3cfa90c76cb8fa149bdc01174c45c42b5 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Wed, 14 Mar 2018 13:18:30 +0000 Subject: [PATCH] [Sema] Pop function scope when instantiating a func with skipped body Summary: By calling ActOnFinishFunctionBody(). Previously we were only calling ActOnSkippedFunctionBody, which didn't pop the function scope. This causes a crash when running on our internal code. No test-case, though, since I couldn't come up with a small example in reasonable time. The bug was introduced in r321174. Reviewers: bkramer, sammccall, sepavloff, aaron.ballman Reviewed By: sammccall, aaron.ballman Subscribers: aaron.ballman, cfe-commits Differential Revision: https://reviews.llvm.org/D44439 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@327504 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaTemplateInstantiateDecl.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 97d0f8ea02..8875eb2aa3 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -3937,8 +3937,10 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, TemplateArgs)) return; + StmtResult Body; if (PatternDecl->hasSkippedBody()) { ActOnSkippedFunctionBody(Function); + Body = nullptr; } else { if (CXXConstructorDecl *Ctor = dyn_cast(Function)) { // If this is a constructor, instantiate the member initializers. @@ -3954,16 +3956,14 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation, } // Instantiate the function body. - StmtResult Body = SubstStmt(Pattern, TemplateArgs); + Body = SubstStmt(Pattern, TemplateArgs); if (Body.isInvalid()) Function->setInvalidDecl(); - - // FIXME: finishing the function body while in an expression evaluation - // context seems wrong. Investigate more. - ActOnFinishFunctionBody(Function, Body.get(), - /*IsInstantiation=*/true); } + // FIXME: finishing the function body while in an expression evaluation + // context seems wrong. Investigate more. + ActOnFinishFunctionBody(Function, Body.get(), /*IsInstantiation=*/true); PerformDependentDiagnostics(PatternDecl, TemplateArgs); -- 2.40.0