r287100 - [OpenCL] Use the semantic spelling of the Access attribute, rather than a string.

Joey Gouly via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 16 03:34:09 PST 2016


Author: joey
Date: Wed Nov 16 05:34:09 2016
New Revision: 287100

URL: http://llvm.org/viewvc/llvm-project?rev=287100&view=rev
Log:
[OpenCL] Use the semantic spelling of the Access attribute, rather than a string.
    
Also fix a latent bug, due to an incorrect traversal of the AttributeList.

Modified:
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/SemaOpenCL/invalid-image.cl

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=287100&r1=287099&r2=287100&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Nov 16 05:34:09 2016
@@ -1209,19 +1209,19 @@ TypeResult Sema::actOnObjCTypeArgsAndPro
   return CreateParsedType(Result, ResultTInfo);
 }
 
-static StringRef getImageAccessAttrStr(AttributeList *attrs) {
-  if (attrs) {
-
-    AttributeList *Next;
+static OpenCLAccessAttr::Spelling getImageAccess(const AttributeList *Attrs) {
+  if (Attrs) {
+    const AttributeList *Next = Attrs;
     do {
-      AttributeList &Attr = *attrs;
+      const AttributeList &Attr = *Next;
       Next = Attr.getNext();
       if (Attr.getKind() == AttributeList::AT_OpenCLAccess) {
-        return Attr.getName()->getName();
+        return static_cast<OpenCLAccessAttr::Spelling>(
+            Attr.getSemanticSpelling());
       }
     } while (Next);
   }
-  return "";
+  return OpenCLAccessAttr::Keyword_read_only;
 }
 
 /// \brief Convert the specified declspec to the appropriate type
@@ -1619,11 +1619,14 @@ static QualType ConvertDeclSpecToType(Ty
 
 #define GENERIC_IMAGE_TYPE(ImgType, Id) \
   case DeclSpec::TST_##ImgType##_t: \
-    Result = llvm::StringSwitch<QualType>( \
-                 getImageAccessAttrStr(DS.getAttributes().getList())) \
-                 .Cases("write_only", "__write_only", Context.Id##WOTy) \
-                 .Cases("read_write", "__read_write", Context.Id##RWTy) \
-                 .Default(Context.Id##ROTy); \
+    switch (getImageAccess(DS.getAttributes().getList())) { \
+    case OpenCLAccessAttr::Keyword_write_only: \
+      Result = Context.Id##WOTy; break; \
+    case OpenCLAccessAttr::Keyword_read_write: \
+      Result = Context.Id##RWTy; break; \
+    case OpenCLAccessAttr::Keyword_read_only: \
+      Result = Context.Id##ROTy; break; \
+    } \
     break;
 #include "clang/Basic/OpenCLImageTypes.def"
 

Modified: cfe/trunk/test/SemaOpenCL/invalid-image.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-image.cl?rev=287100&r1=287099&r2=287100&view=diff
==============================================================================
--- cfe/trunk/test/SemaOpenCL/invalid-image.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-image.cl Wed Nov 16 05:34:09 2016
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify -D=ATTR_TEST -fms-compatibility %s
 
 void test1(image1d_t *i) {} // expected-error{{pointer to type '__read_only image1d_t' is invalid in OpenCL}}
 
@@ -12,3 +13,8 @@ void test2(image1d_t i) {
 }
 
 image1d_t test3() {} // expected-error{{declaring function return value of type '__read_only image1d_t' is not allowed}}
+
+#ifdef ATTR_TEST
+// Test case for an infinite loop bug.
+kernel void foob(read_only __ptr32  image2d_t i) { } // expected-error{{'__ptr32' attribute only applies to pointer arguments}}
+#endif




More information about the cfe-commits mailing list