diff options
author | Anastasia Stulova <anastasia.stulova@arm.com> | 2016-03-03 18:38:40 +0000 |
---|---|---|
committer | Anastasia Stulova <anastasia.stulova@arm.com> | 2016-03-03 18:38:40 +0000 |
commit | 782d5f43ca4e22e0cc36d8a3f4cd1ba45650b32b (patch) | |
tree | a7b458a3043e0e05c19e814e82d01be693da6190 /clang/lib/Sema/SemaDecl.cpp | |
parent | 3928910fe6b120f296854edd4c160d521de5efe2 (diff) | |
download | bcm5719-llvm-782d5f43ca4e22e0cc36d8a3f4cd1ba45650b32b.tar.gz bcm5719-llvm-782d5f43ca4e22e0cc36d8a3f4cd1ba45650b32b.zip |
[OpenCL] Improve diagnostics of address spaces for variables in function
- Prevent local variables to be declared in global AS
- Diagnose AS of local variables with an extern storage class
as if they would be in a program scope
Review: http://reviews.llvm.org/D17345
llvm-svn: 262641
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 74d6f918972..db741bc6e30 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -6633,34 +6633,26 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) { // OpenCL v2.0 s6.5.1 - Variables defined at program scope and static // variables inside a function can also be declared in the global // address space. - if (NewVD->isFileVarDecl()) { + if (NewVD->isFileVarDecl() || NewVD->isStaticLocal() || + NewVD->hasExternalStorage()) { if (!T->isSamplerT() && !(T.getAddressSpace() == LangAS::opencl_constant || (T.getAddressSpace() == LangAS::opencl_global && getLangOpts().OpenCLVersion == 200))) { + int Scope = NewVD->isStaticLocal() | NewVD->hasExternalStorage() << 1; if (getLangOpts().OpenCLVersion == 200) Diag(NewVD->getLocation(), diag::err_opencl_global_invalid_addr_space) - << "global or constant"; + << Scope << "global or constant"; else Diag(NewVD->getLocation(), diag::err_opencl_global_invalid_addr_space) - << "constant"; + << Scope << "constant"; NewVD->setInvalidDecl(); return; } } else { - // OpenCL v2.0 s6.5.1 - Variables defined at program scope and static - // variables inside a function can also be declared in the global - // address space. - if (NewVD->isStaticLocal() && - !(T.getAddressSpace() == LangAS::opencl_constant || - (T.getAddressSpace() == LangAS::opencl_global && - getLangOpts().OpenCLVersion == 200))) { - if (getLangOpts().OpenCLVersion == 200) - Diag(NewVD->getLocation(), diag::err_opencl_global_invalid_addr_space) - << "global or constant"; - else - Diag(NewVD->getLocation(), diag::err_opencl_global_invalid_addr_space) - << "constant"; + if (T.getAddressSpace() == LangAS::opencl_global) { + Diag(NewVD->getLocation(), diag::err_opencl_function_variable) + << 1 /*is any function*/ << "global"; NewVD->setInvalidDecl(); return; } @@ -6671,11 +6663,11 @@ void Sema::CheckVariableDeclarationType(VarDecl *NewVD) { FunctionDecl *FD = getCurFunctionDecl(); if (FD && !FD->hasAttr<OpenCLKernelAttr>()) { if (T.getAddressSpace() == LangAS::opencl_constant) - Diag(NewVD->getLocation(), diag::err_opencl_non_kernel_variable) - << "constant"; + Diag(NewVD->getLocation(), diag::err_opencl_function_variable) + << 0 /*non-kernel only*/ << "constant"; else - Diag(NewVD->getLocation(), diag::err_opencl_non_kernel_variable) - << "local"; + Diag(NewVD->getLocation(), diag::err_opencl_function_variable) + << 0 /*non-kernel only*/ << "local"; NewVD->setInvalidDecl(); return; } |