Index: cfe/trunk/include/clang/Basic/Attr.td =================================================================== --- cfe/trunk/include/clang/Basic/Attr.td +++ cfe/trunk/include/clang/Basic/Attr.td @@ -688,7 +688,8 @@ let Spellings = [Keyword<"__read_only">, Keyword<"read_only">, Keyword<"__write_only">, Keyword<"write_only">, Keyword<"__read_write">, Keyword<"read_write">]; - let Subjects = SubjectList<[ParmVar], ErrorDiag>; + let Subjects = SubjectList<[ParmVar, TypedefName], ErrorDiag, + "ExpectedParameterOrTypedef">; let Accessors = [Accessor<"isReadOnly", [Keyword<"__read_only">, Keyword<"read_only">]>, Accessor<"isReadWrite", [Keyword<"__read_write">, Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td @@ -2506,8 +2506,8 @@ "variables and functions|functions and methods|parameters|" "functions, methods and blocks|functions, methods, and classes|" "functions, methods, and parameters|classes|enums|variables|methods|" - "fields and global variables|structs|variables and typedefs|thread-local variables|" - "variables and fields|variables, data members and tag types|" + "fields and global variables|structs|parameters and typedefs|variables and typedefs|" + "thread-local variables|variables and fields|variables, data members and tag types|" "types and namespaces|Objective-C interfaces|methods and properties|" "struct or union|struct, union or class|types|" "Objective-C instance methods|init methods of interface or class extension declarations|" @@ -7923,9 +7923,11 @@ def err_opencl_invalid_access_qualifier : Error< "access qualifier can only be used for pipe and image type">; def err_opencl_invalid_read_write : Error< - "access qualifier %0 can not be used for %1 %select{|earlier than OpenCL version 2.0}2">; + "access qualifier %0 can not be used for %1 %select{|prior to OpenCL version 2.0}2">; def err_opencl_multiple_access_qualifiers : Error< "multiple access qualifiers">; +def note_opencl_typedef_access_qualifier : Note< + "previously declared '%0' here">; // OpenCL Section 6.8.g def err_opencl_unknown_type_specifier : Error< Index: cfe/trunk/include/clang/Sema/AttributeList.h =================================================================== --- cfe/trunk/include/clang/Sema/AttributeList.h +++ cfe/trunk/include/clang/Sema/AttributeList.h @@ -880,6 +880,7 @@ ExpectedMethod, ExpectedFieldOrGlobalVar, ExpectedStruct, + ExpectedParameterOrTypedef, ExpectedVariableOrTypedef, ExpectedTLSVar, ExpectedVariableOrField, Index: cfe/trunk/lib/Sema/SemaType.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaType.cpp +++ cfe/trunk/lib/Sema/SemaType.cpp @@ -6481,12 +6481,31 @@ /// Handle OpenCL Access Qualifier Attribute. static void HandleOpenCLAccessAttr(QualType &CurType, const AttributeList &Attr, Sema &S) { - // OpenCL v2.0 s6.6 - Access qualifier can used only for image and pipe type. + // OpenCL v2.0 s6.6 - Access qualifier can be used only for image and pipe type. if (!(CurType->isImageType() || CurType->isPipeType())) { S.Diag(Attr.getLoc(), diag::err_opencl_invalid_access_qualifier); Attr.setInvalid(); return; } + + if (const TypedefType* TypedefTy = CurType->getAs()) { + QualType PointeeTy = TypedefTy->desugar(); + S.Diag(Attr.getLoc(), diag::err_opencl_multiple_access_qualifiers); + + std::string PrevAccessQual; + switch (cast(PointeeTy.getTypePtr())->getKind()) { + #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: \ + PrevAccessQual = #Access; \ + break; + #include "clang/Basic/OpenCLImageTypes.def" + default: + assert(0 && "Unable to find corresponding image type."); + } + + S.Diag(TypedefTy->getDecl()->getLocStart(), + diag::note_opencl_typedef_access_qualifier) << PrevAccessQual; + } } static void processTypeAttrs(TypeProcessingState &state, QualType &type, Index: cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl =================================================================== --- cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl +++ cfe/trunk/test/CodeGenOpenCL/kernel-arg-info.cl @@ -49,7 +49,7 @@ // ARGINFO: !kernel_arg_name ![[MD46:[0-9]+]] typedef image1d_t myImage; -kernel void foo5(read_only myImage img1, write_only image1d_t img2) { +kernel void foo5(myImage img1, write_only image1d_t img2) { } // CHECK: define spir_kernel void @foo5{{[^!]+}} // CHECK: !kernel_arg_addr_space ![[MD41:[0-9]+]] Index: cfe/trunk/test/SemaOpenCL/access-qualifier.cl =================================================================== --- cfe/trunk/test/SemaOpenCL/access-qualifier.cl +++ cfe/trunk/test/SemaOpenCL/access-qualifier.cl @@ -0,0 +1,69 @@ +// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL1.2 %s +// RUN: %clang_cc1 -verify -pedantic -fsyntax-only -cl-std=CL2.0 %s + +typedef image1d_t img1d_ro_default; // expected-note {{previously declared 'read_only' here}} + +typedef write_only image1d_t img1d_wo; // expected-note {{previously declared 'write_only' here}} +typedef read_only image1d_t img1d_ro; + +#if __OPENCL_C_VERSION__ >= 200 +typedef read_write image1d_t img1d_rw; +#endif + +typedef int Int; +typedef read_only int IntRO; // expected-error {{access qualifier can only be used for pipe and image type}} + + +void myWrite(write_only image1d_t); // expected-note {{passing argument to parameter here}} expected-note {{passing argument to parameter here}} +void myRead(read_only image1d_t); // expected-note {{passing argument to parameter here}} + +#if __OPENCL_C_VERSION__ >= 200 +void myReadWrite(read_write image1d_t); +#else +void myReadWrite(read_write image1d_t); // expected-error {{access qualifier 'read_write' can not be used for '__read_write image1d_t' prior to OpenCL version 2.0}} +#endif + + +kernel void k1(img1d_wo img) { + myRead(img); // expected-error {{passing 'img1d_wo' (aka '__write_only image1d_t') to parameter of incompatible type '__read_only image1d_t'}} +} + +kernel void k2(img1d_ro img) { + myWrite(img); // expected-error {{passing 'img1d_ro' (aka '__read_only image1d_t') to parameter of incompatible type '__write_only image1d_t'}} +} + +kernel void k3(img1d_wo img) { + myWrite(img); +} + +#if __OPENCL_C_VERSION__ >= 200 +kernel void k4(img1d_rw img) { + myReadWrite(img); +} +#endif + +kernel void k5(img1d_ro_default img) { + myWrite(img); // expected-error {{passing 'img1d_ro_default' (aka '__read_only image1d_t') to parameter of incompatible type '__write_only image1d_t'}} +} + +kernel void k6(img1d_ro img) { + myRead(img); +} + +kernel void k7(read_only img1d_wo img){} // expected-error {{multiple access qualifiers}} + +kernel void k8(write_only img1d_ro_default img){} // expected-error {{multiple access qualifiers}} + +kernel void k9(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}} + +kernel void k10(read_only Int img){} // expected-error {{access qualifier can only be used for pipe and image type}} + +kernel void k11(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}} + +kernel void k12(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}} + +#if __OPENCL_C_VERSION__ >= 200 +kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe int'}} +#else +kernel void k13(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' prior to OpenCL version 2.0}} +#endif Index: cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl =================================================================== --- cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl +++ cfe/trunk/test/SemaOpenCL/invalid-access-qualifier.cl @@ -1,14 +0,0 @@ -// RUN: %clang_cc1 -verify %s -// RUN: %clang_cc1 -verify -cl-std=CL2.0 -DCL20 %s - -void test1(read_only int i){} // expected-error{{access qualifier can only be used for pipe and image type}} - -void test2(read_only write_only image1d_t i){} // expected-error{{multiple access qualifiers}} - -void test3(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}} - -#ifdef CL20 -void test4(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe int'}} -#else -void test4(__read_write image1d_t i) {} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' earlier than OpenCL version 2.0}} -#endif