pirama created this revision.
pirama added reviewers: aaron.ballman, rsmith.
pirama added subscribers: srhines, cfe-commits.

Address post-patch comments to r272342.

- Rename the 'kernel' attribute's name
- Idiomatically restrict the attribute to the 'RenderScript' LangOpt.

http://reviews.llvm.org/D21240

Files:
  include/clang/Basic/Attr.td
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/renderscript.rs

Index: test/Sema/renderscript.rs
===================================================================
--- test/Sema/renderscript.rs
+++ test/Sema/renderscript.rs
@@ -2,11 +2,15 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -x c %s
 
 #ifndef __RENDERSCRIPT__
-// expected-warning@+2 {{kernel attribute ignored}}
+// expected-warning@+2 {{'kernel' attribute ignored}}
 #endif
-void __attribute__((kernel)) kernel();
+void __attribute__((kernel)) kernel() {}
 
-// expected-warning@+1 {{'kernel' attribute only applies to functions}}
+#ifndef __RENDERSCRIPT__
+// expected-warning@+4 {{'kernel' attribute ignored}}
+#else
+// expected-warning@+2 {{'kernel' attribute only applies to functions}}
+#endif
 int __attribute__((kernel)) global;
 
 #ifndef __RENDERSCRIPT__
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4185,17 +4185,6 @@
                                     Attr.getAttributeSpellingListIndex()));
 }
 
-static void handleKernelAttr(Sema &S, Decl *D, const AttributeList &Attr) {
-  if (S.LangOpts.RenderScript) {
-    D->addAttr(::new (S.Context)
-               KernelAttr(Attr.getRange(), S.Context,
-                          Attr.getAttributeSpellingListIndex()));
-  } else {
-    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "kernel";
-  }
-}
-
-
 
//===----------------------------------------------------------------------===//
 // Checker-specific attribute handlers.
 
//===----------------------------------------------------------------------===//
@@ -5926,8 +5915,8 @@
     handleTypeTagForDatatypeAttr(S, D, Attr);
     break;
 
-  case AttributeList::AT_Kernel:
-    handleKernelAttr(S, D, Attr);
+  case AttributeList::AT_RenderScriptKernel:
+    handleSimpleAttribute<RenderScriptKernelAttr>(S, D, Attr);
     break;
   }
 }
Index: include/clang/Basic/Attr.td
===================================================================
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -240,6 +240,7 @@
 def CUDA : LangOpt<"CUDA">;
 def COnly : LangOpt<"CPlusPlus", 1>;
 def OpenCL : LangOpt<"OpenCL">;
+def RenderScript : LangOpt<"RenderScript">;
 
 // Defines targets for target-specific attributes. The list of strings should
 // specify architectures for which the target applies, based off the ArchType
@@ -728,10 +729,11 @@
   let ASTNode = 0;
 }
 
-def Kernel : Attr {
+def RenderScriptKernel : Attr {
   let Spellings = [GNU<"kernel">];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [Undocumented];
+  let LangOpts = [RenderScript];
 }
 
 def Deprecated : InheritableAttr {


Index: test/Sema/renderscript.rs
===================================================================
--- test/Sema/renderscript.rs
+++ test/Sema/renderscript.rs
@@ -2,11 +2,15 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -x c %s
 
 #ifndef __RENDERSCRIPT__
-// expected-warning@+2 {{kernel attribute ignored}}
+// expected-warning@+2 {{'kernel' attribute ignored}}
 #endif
-void __attribute__((kernel)) kernel();
+void __attribute__((kernel)) kernel() {}
 
-// expected-warning@+1 {{'kernel' attribute only applies to functions}}
+#ifndef __RENDERSCRIPT__
+// expected-warning@+4 {{'kernel' attribute ignored}}
+#else
+// expected-warning@+2 {{'kernel' attribute only applies to functions}}
+#endif
 int __attribute__((kernel)) global;
 
 #ifndef __RENDERSCRIPT__
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4185,17 +4185,6 @@
                                     Attr.getAttributeSpellingListIndex()));
 }
 
-static void handleKernelAttr(Sema &S, Decl *D, const AttributeList &Attr) {
-  if (S.LangOpts.RenderScript) {
-    D->addAttr(::new (S.Context)
-               KernelAttr(Attr.getRange(), S.Context,
-                          Attr.getAttributeSpellingListIndex()));
-  } else {
-    S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "kernel";
-  }
-}
-
-
 //===----------------------------------------------------------------------===//
 // Checker-specific attribute handlers.
 //===----------------------------------------------------------------------===//
@@ -5926,8 +5915,8 @@
     handleTypeTagForDatatypeAttr(S, D, Attr);
     break;
 
-  case AttributeList::AT_Kernel:
-    handleKernelAttr(S, D, Attr);
+  case AttributeList::AT_RenderScriptKernel:
+    handleSimpleAttribute<RenderScriptKernelAttr>(S, D, Attr);
     break;
   }
 }
Index: include/clang/Basic/Attr.td
===================================================================
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -240,6 +240,7 @@
 def CUDA : LangOpt<"CUDA">;
 def COnly : LangOpt<"CPlusPlus", 1>;
 def OpenCL : LangOpt<"OpenCL">;
+def RenderScript : LangOpt<"RenderScript">;
 
 // Defines targets for target-specific attributes. The list of strings should
 // specify architectures for which the target applies, based off the ArchType
@@ -728,10 +729,11 @@
   let ASTNode = 0;
 }
 
-def Kernel : Attr {
+def RenderScriptKernel : Attr {
   let Spellings = [GNU<"kernel">];
   let Subjects = SubjectList<[Function]>;
   let Documentation = [Undocumented];
+  let LangOpts = [RenderScript];
 }
 
 def Deprecated : InheritableAttr {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to