diff options
author | Anastasia Stulova <anastasia.stulova@arm.com> | 2019-05-07 14:22:34 +0000 |
---|---|---|
committer | Anastasia Stulova <anastasia.stulova@arm.com> | 2019-05-07 14:22:34 +0000 |
commit | 96177dc49e3cc8d175f80b0469e6b09837858a97 (patch) | |
tree | ee95378da177e4552fb8af4bf749c219459418b7 /lib | |
parent | 81af6acbd988223940e497387e2a1bc7d8913ad7 (diff) | |
download | clang-96177dc49e3cc8d175f80b0469e6b09837858a97.tar.gz |
[OpenCL] Prevent mangling kernel functions.
Kernel function names have to be preserved as in the original
source to be able to access them from the host API side.
This commit also adds restriction to kernels that prevents them
from being used in overloading, templates, etc.
Differential Revision: https://reviews.llvm.org/D60454
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360152 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/Decl.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 34 |
2 files changed, 26 insertions, 10 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 19fd3882bd..79db14af49 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -2961,6 +2961,8 @@ bool FunctionDecl::isExternC() const { } bool FunctionDecl::isInExternCContext() const { + if (hasAttr<OpenCLKernelAttr>()) + return true; return getLexicalDeclContext()->isExternCContext(); } diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 379e2aefb4..8fd6ab860a 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -9214,18 +9214,9 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, MarkUnusedFileScopedDecl(NewFD); - if (getLangOpts().CPlusPlus) { - if (FunctionTemplate) { - if (NewFD->isInvalidDecl()) - FunctionTemplate->setInvalidDecl(); - return FunctionTemplate; - } - if (isMemberSpecialization && !NewFD->isInvalidDecl()) - CompleteMemberSpecialization(NewFD, Previous); - } - if (NewFD->hasAttr<OpenCLKernelAttr>()) { + if (getLangOpts().OpenCL && NewFD->hasAttr<OpenCLKernelAttr>()) { // OpenCL v1.2 s6.8 static is invalid for kernel functions. if ((getLangOpts().OpenCLVersion >= 120) && (SC == SC_Static)) { @@ -9245,7 +9236,30 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC, llvm::SmallPtrSet<const Type *, 16> ValidTypes; for (auto Param : NewFD->parameters()) checkIsValidOpenCLKernelParameter(*this, D, Param, ValidTypes); + + if (getLangOpts().OpenCLCPlusPlus) { + if (DC->isRecord()) { + Diag(D.getIdentifierLoc(), diag::err_method_kernel); + D.setInvalidType(); + } + if (FunctionTemplate) { + Diag(D.getIdentifierLoc(), diag::err_template_kernel); + D.setInvalidType(); + } + } + } + + if (getLangOpts().CPlusPlus) { + if (FunctionTemplate) { + if (NewFD->isInvalidDecl()) + FunctionTemplate->setInvalidDecl(); + return FunctionTemplate; + } + + if (isMemberSpecialization && !NewFD->isInvalidDecl()) + CompleteMemberSpecialization(NewFD, Previous); } + for (const ParmVarDecl *Param : NewFD->parameters()) { QualType PT = Param->getType(); |