Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only parse body of restricted function when compiling in restricted context #144

Open
wants to merge 2 commits into
base: clang_tot_upgrade
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<CXXAMPRestrictAUTOAttr>();
const bool IsHC = DP->hasAttr<CXXAMPRestrictAMPAttr>();
const bool IsCPU = DP->hasAttr<CXXAMPRestrictCPUAttr>();

SkipBody->ShouldSkip =
!IsAuto && (LangOpts.DevicePath ? (!IsHC && IsCPU) : (IsHC && !IsCPU));

if (SkipBody->ShouldSkip) {
auto Empty = new (getASTContext()) NullStmt{DP->getLocation()};
cast<FunctionDecl>(DP)->setBody(Empty);
cast<FunctionDecl>(DP)->addAttr(CXX11NoReturnAttr::CreateImplicit(getASTContext()));
return DP;
}
}

return ActOnStartOfFunctionDef(FnBodyScope, DP, SkipBody);
}

Expand Down