diff options
author | Xiuli Pan <xiulipan@outlook.com> | 2016-02-25 03:34:20 +0000 |
---|---|---|
committer | Xiuli Pan <xiulipan@outlook.com> | 2016-02-25 03:34:20 +0000 |
commit | 379554ac5b15a4c76719d1241dd149b294f93331 (patch) | |
tree | a5431c462e35764f6c3b73ff2cdabbe44e8e76f0 /clang/lib/Sema/SemaDecl.cpp | |
parent | 73ef3c7fbcb1a2d7c8fd66c4b0af070f0f725b06 (diff) | |
download | bcm5719-llvm-379554ac5b15a4c76719d1241dd149b294f93331.tar.gz bcm5719-llvm-379554ac5b15a4c76719d1241dd149b294f93331.zip |
[OpenCL] Add Sema checks for types
Summary:
Add Sema checks for opencl type: image, pipe....
This patch is partitioned from http://reviews.llvm.org/D16047
Reviewers: Anastasia, yaxunl
Subscribers: pekka.jaaskelainen, cfe-commits
Differential Revision: http://reviews.llvm.org/D17437
llvm-svn: 261818
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 378abe94e87..61ec1a77529 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5710,6 +5710,17 @@ Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, QualType R = TInfo->getType(); DeclarationName Name = GetNameForDeclarator(D).getName(); + // OpenCL v2.0 s6.9.b - Image type can only be used as a function argument. + // OpenCL v2.0 s6.13.16.1 - Pipe type can only be used as a function + // argument. + if (getLangOpts().OpenCL && (R->isImageType() || R->isPipeType())) { + Diag(D.getIdentifierLoc(), + diag::err_opencl_type_can_only_be_used_as_function_parameter) + << R; + D.setInvalidType(); + return nullptr; + } + DeclSpec::SCS SCSpec = D.getDeclSpec().getStorageClassSpec(); StorageClass SC = StorageClassSpecToVarDeclStorageClass(D.getDeclSpec()); @@ -10737,7 +10748,17 @@ ParmVarDecl *Sema::CheckParameter(DeclContext *DC, SourceLocation StartLoc, Diag(NameLoc, diag::err_arg_with_address_space); New->setInvalidDecl(); } - } + } + + // OpenCL v2.0 s6.9b - Pointer to image/sampler cannot be used. + // OpenCL v2.0 s6.13.16.1 - Pointer to pipe cannot be used. + if (getLangOpts().OpenCL && T->isPointerType()) { + const QualType PTy = T->getPointeeType(); + if (PTy->isImageType() || PTy->isSamplerT() || PTy->isPipeType()) { + Diag(NameLoc, diag::err_opencl_pointer_to_type) << PTy; + New->setInvalidDecl(); + } + } return New; } |