]> granicus.if.org Git - clang/commitdiff
[CUDA] Added stubs for new attributes used by CUDA headers.
authorArtem Belevich <tra@google.com>
Mon, 10 Aug 2015 20:33:56 +0000 (20:33 +0000)
committerArtem Belevich <tra@google.com>
Mon, 10 Aug 2015 20:33:56 +0000 (20:33 +0000)
The main purpose is to avoid errors and warnings while parsing CUDA
header files. The attributes are currently unused otherwise.

Differential version: http://reviews.llvm.org/D11690

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244497 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Attr.td
test/Index/attributes-cuda.cu
test/SemaCUDA/attributes.cu [new file with mode: 0644]

index c72187454bc1e9885afd4611c20b36f54c3c9e6e..6f10ee62723d8b11a692f7807e1b73936b733e5c 100644 (file)
@@ -557,6 +557,11 @@ def CUDAConstant : InheritableAttr {
   let Documentation = [Undocumented];
 }
 
+def CUDACudartBuiltin : IgnoredAttr {
+  let Spellings = [GNU<"cudart_builtin">];
+  let LangOpts = [CUDA];
+}
+
 def CUDADevice : InheritableAttr {
   let Spellings = [GNU<"device">];
   let Subjects = SubjectList<[Function, Var]>;
@@ -564,6 +569,21 @@ def CUDADevice : InheritableAttr {
   let Documentation = [Undocumented];
 }
 
+def CUDADeviceBuiltin : IgnoredAttr {
+  let Spellings = [GNU<"device_builtin">];
+  let LangOpts = [CUDA];
+}
+
+def CUDADeviceBuiltinSurfaceType : IgnoredAttr {
+  let Spellings = [GNU<"device_builtin_surface_type">];
+  let LangOpts = [CUDA];
+}
+
+def CUDADeviceBuiltinTextureType : IgnoredAttr {
+  let Spellings = [GNU<"device_builtin_texture_type">];
+  let LangOpts = [CUDA];
+}
+
 def CUDAGlobal : InheritableAttr {
   let Spellings = [GNU<"global">];
   let Subjects = SubjectList<[Function]>;
@@ -1015,6 +1035,11 @@ def NoThrow : InheritableAttr {
   let Documentation = [Undocumented];
 }
 
+def NvWeak : IgnoredAttr {
+  let Spellings = [GNU<"nv_weak">];
+  let LangOpts = [CUDA];
+}
+
 def ObjCBridge : InheritableAttr {
   let Spellings = [GNU<"objc_bridge">];
   let Subjects = SubjectList<[Record, TypedefName], ErrorDiag,
index 51f4aedd198d06514e6f3c2a7a1a69a0cab42e5b..83ac8d389fe6e9df323e48e3d93f31168e1ce776 100644 (file)
@@ -7,6 +7,14 @@ __attribute__((global)) void f_global();
 __attribute__((constant)) int* g_constant;
 __attribute__((shared)) float *g_shared;
 __attribute__((host)) void f_host();
+__attribute__((device_builtin)) void f_device_builtin();
+typedef __attribute__((device_builtin)) const void *t_device_builtin;
+enum __attribute__((device_builtin)) e_device_builtin {};
+__attribute__((device_builtin)) int v_device_builtin;
+__attribute__((cudart_builtin)) void f_cudart_builtin();
+__attribute__((nv_weak)) void f_nv_weak();
+__attribute__((device_builtin_surface_type)) unsigned long long surface_var;
+__attribute__((device_builtin_texture_type)) unsigned long long texture_var;
 
 // CHECK:       attributes-cuda.cu:5:30: FunctionDecl=f_device:5:30
 // CHECK-NEXT:  attributes-cuda.cu:5:16: attribute(device)
@@ -18,3 +26,11 @@ __attribute__((host)) void f_host();
 // CHECK-NEXT:  attributes-cuda.cu:8:16: attribute(shared)
 // CHECK:       attributes-cuda.cu:9:28: FunctionDecl=f_host:9:28
 // CHECK-NEXT:  attributes-cuda.cu:9:16: attribute(host)
+// CHECK:      attributes-cuda.cu:10:38: FunctionDecl=f_device_builtin:10:38
+// CHECK:      attributes-cuda.cu:11:53: TypedefDecl=t_device_builtin:11:53
+// CHECK:      attributes-cuda.cu:12:38: EnumDecl=e_device_builtin:12:38
+// CHECK:      attributes-cuda.cu:13:37: VarDecl=v_device_builtin:13:37
+// CHECK:      attributes-cuda.cu:14:38: FunctionDecl=f_cudart_builtin:14:38
+// CHECK:      attributes-cuda.cu:15:31: FunctionDecl=f_nv_weak:15:31
+// CHECK:      attributes-cuda.cu:16:65: VarDecl=surface_var:16:65
+// CHECK:      attributes-cuda.cu:17:65: VarDecl=texture_var:17:65
diff --git a/test/SemaCUDA/attributes.cu b/test/SemaCUDA/attributes.cu
new file mode 100644 (file)
index 0000000..ce4dc92
--- /dev/null
@@ -0,0 +1,33 @@
+// Tests handling of CUDA attributes.
+//
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fcuda-is-device -verify %s
+// Now pretend that we're compiling a C file. There should be warnings.
+// RUN: %clang_cc1 -DEXPECT_WARNINGS -fsyntax-only -verify -x c %s
+
+#if defined(EXPECT_WARNINGS)
+// expected-warning@+12 {{'device' attribute ignored}}
+// expected-warning@+12 {{'global' attribute ignored}}
+// expected-warning@+12 {{'constant' attribute ignored}}
+// expected-warning@+12 {{'shared' attribute ignored}}
+// expected-warning@+12 {{'host' attribute ignored}}
+//
+// NOTE: IgnoredAttr in clang which is used for the rest of
+// attributes ignores LangOpts, so there are no warnings.
+#else
+// expected-no-diagnostics
+#endif
+
+__attribute__((device)) void f_device();
+__attribute__((global)) void f_global();
+__attribute__((constant)) int* g_constant;
+__attribute__((shared)) float *g_shared;
+__attribute__((host)) void f_host();
+__attribute__((device_builtin)) void f_device_builtin();
+typedef __attribute__((device_builtin)) const void *t_device_builtin;
+enum __attribute__((device_builtin)) e_device_builtin {E};
+__attribute__((device_builtin)) int v_device_builtin;
+__attribute__((cudart_builtin)) void f_cudart_builtin();
+__attribute__((nv_weak)) void f_nv_weak();
+__attribute__((device_builtin_surface_type)) unsigned long long surface_var;
+__attribute__((device_builtin_texture_type)) unsigned long long texture_var;