From 7e4a2a7e6a7a806100608bfea10bfba2090a18cb Mon Sep 17 00:00:00 2001 From: Alex Voicu Date: Fri, 15 Jun 2018 12:15:16 +0100 Subject: [PATCH 1/2] Only parse body of restricted function when compiling in restricted context --- lib/Sema/SemaDecl.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 2eba7efa6fd..a46283b3299 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -13187,6 +13187,23 @@ Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D, D.setFunctionDefinitionKind(FDK_Definition); Decl *DP = HandleDeclarator(ParentScope, D, TemplateParameterLists); + + if (LangOpts.CPlusPlusAMP && SkipBody) { + const bool IsAuto = DP->hasAttr(); + const bool IsHC = DP->hasAttr(); + const bool IsCPU = DP->hasAttr(); + + SkipBody->ShouldSkip = + !IsAuto && LangOpts.DevicePath ? (!IsHC && IsCPU) : (IsHC && !IsCPU); + + if (SkipBody->ShouldSkip) { + auto Empty = new (getASTContext()) NullStmt{DP->getLocation()}; + cast(DP)->setBody(Empty); + cast(DP)->addAttr(CXX11NoReturnAttr::CreateImplicit(getASTContext())); + return DP; + } + } + return ActOnStartOfFunctionDef(FnBodyScope, DP, SkipBody); } From 0af329527e1183fc2efcd21cd7b2fed9bc3ed7e6 Mon Sep 17 00:00:00 2001 From: Alex Voicu Date: Mon, 18 Jun 2018 21:57:38 +0100 Subject: [PATCH 2/2] Parentheses make everything clearer --- lib/Sema/SemaDecl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index a46283b3299..83b32d36fbf 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -13194,7 +13194,7 @@ Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D, const bool IsCPU = DP->hasAttr(); SkipBody->ShouldSkip = - !IsAuto && LangOpts.DevicePath ? (!IsHC && IsCPU) : (IsHC && !IsCPU); + !IsAuto && (LangOpts.DevicePath ? (!IsHC && IsCPU) : (IsHC && !IsCPU)); if (SkipBody->ShouldSkip) { auto Empty = new (getASTContext()) NullStmt{DP->getLocation()};