On Mon, Oct 18, 2010 at 10:43:24AM -0700, John McCall wrote: > On Oct 18, 2010, at 10:33 AM, Peter Collingbourne wrote: > >> From my understanding of the OpenCL specification, setting the address > > space on an automatic variable is supposed to not only change the > > address space but also make the variable static (as the term is defined > > in standard C). Adding 'static' to the qualifier macro definitions > > won't work too well because the qualifiers can also appear in other > > places. > > If that's how OpenCL is specified to work, then changing the front-end to > automatically add 'static' to local variables of address-space-qualified type > is a very reasonable solution. We would accept a patch for this.
Patch attached. OK to commit? Thanks, -- Peter
>From f9fc657138168673f1e0f9e2cf0b348121f32667 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne <[email protected]> Date: Mon, 18 Oct 2010 20:19:46 +0100 Subject: [PATCH] OpenCL: assign static storage-class to local variables in non-standard address space The OpenCL specification requires that local variables in non-standard address spaces (namely the "local" address space) be supported. The semantics of such variables essentially matches those of C's "static" storage class. Therefore, assign local variables in non-zero address spaces a static storage class in OpenCL mode. --- lib/Sema/SemaDecl.cpp | 8 ++++++-- test/Sema/opencl-addrspace.c | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 test/Sema/opencl-addrspace.c diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 315bc4d..7cbfdfa 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3027,8 +3027,12 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, // automatic variables that point to other address spaces. // ISO/IEC TR 18037 S5.1.2 if (NewVD->hasLocalStorage() && T.getAddressSpace() != 0) { - Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl); - return NewVD->setInvalidDecl(); + if (getLangOptions().OpenCL) + NewVD->setStorageClass(SC_Static); + else { + Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl); + return NewVD->setInvalidDecl(); + } } if (NewVD->hasLocalStorage() && T.isObjCGCWeak() diff --git a/test/Sema/opencl-addrspace.c b/test/Sema/opencl-addrspace.c new file mode 100644 index 0000000..34ca8d3 --- /dev/null +++ b/test/Sema/opencl-addrspace.c @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -x cl -verify -pedantic -fsyntax-only + +#define __local __attribute__((address_space(1))) + +void foo(void) { + __local int x; +} -- 1.6.5
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
