diff options
author | Alexey Bader <aleksey.bader@mail.ru> | 2016-11-29 10:21:40 +0000 |
---|---|---|
committer | Alexey Bader <aleksey.bader@mail.ru> | 2016-11-29 10:21:40 +0000 |
commit | c211c6c8844a46f8ac795ef7998b81772bc99103 (patch) | |
tree | 6ed39f052d22484e375b831e8c99db89397fb19c /clang/lib/Sema | |
parent | bba2d59ea49d4ee27f9b532e6da7a5f3c0eec084 (diff) | |
download | bcm5719-llvm-c211c6c8844a46f8ac795ef7998b81772bc99103.tar.gz bcm5719-llvm-c211c6c8844a46f8ac795ef7998b81772bc99103.zip |
[OpenCL] Prohibit using reserve_id_t in program scope.
Patch by Egor Churaev (echuraev).
Reviewers: Anastasia
Subscribers: cfe-commits, yaxunl, bader
Differential Revision: https://reviews.llvm.org/D27099
llvm-svn: 288126
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 105 |
1 files changed, 55 insertions, 50 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index fb2468f9ab9..58776e8705b 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -5909,32 +5909,31 @@ NamedDecl *Sema::ActOnVariableDeclarator( return nullptr; } - // 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()); - - // dllimport globals without explicit storage class are treated as extern. We - // have to change the storage class this early to get the right DeclContext. - if (SC == SC_None && !DC->isRecord() && - hasParsedAttr(S, D, AttributeList::AT_DLLImport) && - !hasParsedAttr(S, D, AttributeList::AT_DLLExport)) - SC = SC_Extern; + if (getLangOpts().OpenCL) { + // 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 (R->isImageType() || R->isPipeType()) { + Diag(D.getIdentifierLoc(), + diag::err_opencl_type_can_only_be_used_as_function_parameter) + << R; + D.setInvalidType(); + return nullptr; + } - DeclContext *OriginalDC = DC; - bool IsLocalExternDecl = SC == SC_Extern && - adjustContextForLocalExternDecl(DC); + // OpenCL v1.2 s6.9.r: + // The event type cannot be used to declare a program scope variable. + // OpenCL v2.0 s6.9.q: + // The clk_event_t and reserve_id_t types cannot be declared in program scope. + if (NULL == S->getParent()) { + if (R->isReserveIDT() || R->isClkEventT() || R->isEventT()) { + Diag(D.getIdentifierLoc(), + diag::err_invalid_type_for_program_scope_var) << R; + D.setInvalidType(); + return nullptr; + } + } - if (getLangOpts().OpenCL) { // OpenCL v1.0 s6.8.a.3: Pointers to functions are not allowed. QualType NR = R; while (NR->isPointerType()) { @@ -5954,8 +5953,40 @@ NamedDecl *Sema::ActOnVariableDeclarator( D.setInvalidType(); } } + + // OpenCL v1.2 s6.9.b p4: + // The sampler type cannot be used with the __local and __global address + // space qualifiers. + if (R->isSamplerT() && (R.getAddressSpace() == LangAS::opencl_local || + R.getAddressSpace() == LangAS::opencl_global)) { + Diag(D.getIdentifierLoc(), diag::err_wrong_sampler_addressspace); + } + + // OpenCL v1.2 s6.9.r: + // The event type cannot be used with the __local, __constant and __global + // address space qualifiers. + if (R->isEventT()) { + if (R.getAddressSpace()) { + Diag(D.getLocStart(), diag::err_event_t_addr_space_qual); + D.setInvalidType(); + } + } } + DeclSpec::SCS SCSpec = D.getDeclSpec().getStorageClassSpec(); + StorageClass SC = StorageClassSpecToVarDeclStorageClass(D.getDeclSpec()); + + // dllimport globals without explicit storage class are treated as extern. We + // have to change the storage class this early to get the right DeclContext. + if (SC == SC_None && !DC->isRecord() && + hasParsedAttr(S, D, AttributeList::AT_DLLImport) && + !hasParsedAttr(S, D, AttributeList::AT_DLLExport)) + SC = SC_Extern; + + DeclContext *OriginalDC = DC; + bool IsLocalExternDecl = SC == SC_Extern && + adjustContextForLocalExternDecl(DC); + if (SCSpec == DeclSpec::SCS_mutable) { // mutable can only appear on non-static class members, so it's always // an error here @@ -5988,32 +6019,6 @@ NamedDecl *Sema::ActOnVariableDeclarator( } } - if (getLangOpts().OpenCL) { - // OpenCL v1.2 s6.9.b p4: - // The sampler type cannot be used with the __local and __global address - // space qualifiers. - if (R->isSamplerT() && (R.getAddressSpace() == LangAS::opencl_local || - R.getAddressSpace() == LangAS::opencl_global)) { - Diag(D.getIdentifierLoc(), diag::err_wrong_sampler_addressspace); - } - - // OpenCL 1.2 spec, p6.9 r: - // The event type cannot be used to declare a program scope variable. - // The event type cannot be used with the __local, __constant and __global - // address space qualifiers. - if (R->isEventT()) { - if (S->getParent() == nullptr) { - Diag(D.getLocStart(), diag::err_event_t_global_var); - D.setInvalidType(); - } - - if (R.getAddressSpace()) { - Diag(D.getLocStart(), diag::err_event_t_addr_space_qual); - D.setInvalidType(); - } - } - } - bool IsExplicitSpecialization = false; bool IsVariableTemplateSpecialization = false; bool IsPartialSpecialization = false; |