r341553 - [OpenCL] Relax diagnostics on OpenCL access qualifiers
Andrew Savonichev via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 6 08:10:26 PDT 2018
Author: asavonic
Date: Thu Sep 6 08:10:26 2018
New Revision: 341553
URL: http://llvm.org/viewvc/llvm-project?rev=341553&view=rev
Log:
[OpenCL] Relax diagnostics on OpenCL access qualifiers
Summary:
Emit warning for multiple access qualifiers if they do not conflict.
Patch by Alexey Bader
Reviewers: Anastasia, yaxunl
Reviewed By: Anastasia
Subscribers: asavonic, bader, cfe-commits
Differential Revision: https://reviews.llvm.org/D51302
Modified:
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCL/access-qualifier.cl
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=341553&r1=341552&r2=341553&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Sep 6 08:10:26 2018
@@ -5900,10 +5900,16 @@ static void handleOpenCLAccessAttr(Sema
// Check if there is only one access qualifier.
if (D->hasAttr<OpenCLAccessAttr>()) {
- S.Diag(AL.getLoc(), diag::err_opencl_multiple_access_qualifiers)
- << D->getSourceRange();
- D->setInvalidDecl(true);
- return;
+ if (D->getAttr<OpenCLAccessAttr>()->getSemanticSpelling() ==
+ AL.getSemanticSpelling()) {
+ S.Diag(AL.getLoc(), diag::warn_duplicate_declspec)
+ << AL.getName()->getName() << AL.getRange();
+ } else {
+ S.Diag(AL.getLoc(), diag::err_opencl_multiple_access_qualifiers)
+ << D->getSourceRange();
+ D->setInvalidDecl(true);
+ return;
+ }
}
// OpenCL v2.0 s6.6 - read_write can be used for image types to specify that an
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=341553&r1=341552&r2=341553&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Sep 6 08:10:26 2018
@@ -7105,23 +7105,43 @@ static void HandleOpenCLAccessAttr(QualT
}
if (const TypedefType* TypedefTy = CurType->getAs<TypedefType>()) {
- QualType PointeeTy = TypedefTy->desugar();
- S.Diag(Attr.getLoc(), diag::err_opencl_multiple_access_qualifiers);
+ QualType BaseTy = TypedefTy->desugar();
std::string PrevAccessQual;
- switch (cast<BuiltinType>(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.");
+ if (BaseTy->isPipeType()) {
+ if (TypedefTy->getDecl()->hasAttr<OpenCLAccessAttr>()) {
+ OpenCLAccessAttr *Attr =
+ TypedefTy->getDecl()->getAttr<OpenCLAccessAttr>();
+ PrevAccessQual = Attr->getSpelling();
+ } else {
+ PrevAccessQual = "read_only";
+ }
+ } else if (const BuiltinType* ImgType = BaseTy->getAs<BuiltinType>()) {
+
+ switch (ImgType->getKind()) {
+ #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
+ case BuiltinType::Id: \
+ PrevAccessQual = #Access; \
+ break;
+ #include "clang/Basic/OpenCLImageTypes.def"
+ default:
+ llvm_unreachable("Unable to find corresponding image type.");
+ }
+ } else {
+ llvm_unreachable("unexpected type");
+ }
+ StringRef AttrName = Attr.getName()->getName();
+ if (PrevAccessQual == AttrName.ltrim("_")) {
+ // Duplicated qualifiers
+ S.Diag(Attr.getLoc(), diag::warn_duplicate_declspec)
+ << AttrName << Attr.getRange();
+ } else {
+ // Contradicting qualifiers
+ S.Diag(Attr.getLoc(), diag::err_opencl_multiple_access_qualifiers);
}
S.Diag(TypedefTy->getDecl()->getBeginLoc(),
- diag::note_opencl_typedef_access_qualifier)
- << PrevAccessQual;
+ diag::note_opencl_typedef_access_qualifier) << PrevAccessQual;
} else if (CurType->isPipeType()) {
if (Attr.getSemanticSpelling() == OpenCLAccessAttr::Keyword_write_only) {
QualType ElemType = CurType->getAs<PipeType>()->getElementType();
Modified: cfe/trunk/test/SemaOpenCL/access-qualifier.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/access-qualifier.cl?rev=341553&r1=341552&r2=341553&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/access-qualifier.cl (original)
+++ cfe/trunk/test/SemaOpenCL/access-qualifier.cl Thu Sep 6 08:10:26 2018
@@ -60,7 +60,7 @@ kernel void k10(read_only Int img){} //
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}}
+kernel void k12(read_only read_only image1d_t i){} // expected-warning {{duplicate 'read_only' declaration specifier}}
#if __OPENCL_C_VERSION__ >= 200
kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'read_only pipe int'}}
@@ -78,3 +78,33 @@ kernel void k14(read_only pipe int p) {
#if __OPENCL_C_VERSION__ < 200
kernel void test_image3d_wo(write_only image3d_t img) {} // expected-error {{use of type '__write_only image3d_t' requires cl_khr_3d_image_writes extension to be enabled}}
#endif
+
+#if __OPENCL_C_VERSION__ >= 200
+kernel void read_write_twice_typedef(read_write img1d_rw i){} // expected-warning {{duplicate 'read_write' declaration specifier}}
+// expected-note at -74 {{previously declared 'read_write' here}}
+
+kernel void pipe_ro_twice(read_only read_only pipe int i){} // expected-warning{{duplicate 'read_only' declaration specifier}}
+// Conflicting access qualifiers
+kernel void pipe_ro_twice_tw(read_write read_only read_only pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'read_only pipe int'}}
+kernel void pipe_ro_wo(read_only write_only pipe int i){} // expected-error{{multiple access qualifiers}}
+
+typedef read_only pipe int ROPipeInt;
+kernel void pipe_ro_twice_typedef(read_only ROPipeInt i){} // expected-warning{{duplicate 'read_only' declaration specifier}}
+// expected-note at -2 {{previously declared 'read_only' here}}
+
+kernel void pass_ro_typedef_to_wo(ROPipeInt p) {
+ myPipeWrite(p); // expected-error {{passing 'ROPipeInt' (aka 'read_only pipe int') to parameter of incompatible type 'write_only pipe int'}}
+ // expected-note at -25 {{passing argument to parameter here}}
+}
+#endif
+
+kernel void read_only_twice_typedef(__read_only img1d_ro i){} // expected-warning {{duplicate '__read_only' declaration specifier}}
+// expected-note at -95 {{previously declared 'read_only' here}}
+
+kernel void read_only_twice_default(read_only img1d_ro_default img){} // expected-warning {{duplicate 'read_only' declaration specifier}}
+// expected-note at -101 {{previously declared 'read_only' here}}
+
+kernel void image_wo_twice(write_only __write_only image1d_t i){} // expected-warning {{duplicate '__write_only' declaration specifier}}
+kernel void image_wo_twice_typedef(write_only img1d_wo i){} // expected-warning {{duplicate 'write_only' declaration specifier}}
+// expected-note at -103 {{previously declared 'write_only' here}}
+
More information about the cfe-commits
mailing list