Expose CUDA function attributes to the C interface.
authorEli Bendersky <eliben@google.com>
Wed, 28 May 2014 19:29:58 +0000 (19:29 +0000)
committerEli Bendersky <eliben@google.com>
Wed, 28 May 2014 19:29:58 +0000 (19:29 +0000)
Until now all CUDA-specific attributes were represented with
CXCursor_UnexposedAttr; now they are actually implemented, including the Python
bindings.

llvm-svn: 209767

clang/bindings/python/clang/cindex.py
clang/include/clang-c/Index.h
clang/test/Index/attributes-cuda.cu [new file with mode: 0644]
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp

index cfc27d9..779fa14 100644 (file)
@@ -1082,6 +1082,10 @@ CursorKind.PACKED_ATTR = CursorKind(408)
 CursorKind.PURE_ATTR = CursorKind(409)
 CursorKind.CONST_ATTR = CursorKind(410)
 CursorKind.NODUPLICATE_ATTR = CursorKind(411)
+CursorKind.CUDACONSTANT_ATTR = CursorKind(412)
+CursorKind.CUDADEVICE_ATTR = CursorKind(413)
+CursorKind.CUDAGLOBAL_ATTR = CursorKind(414)
+CursorKind.CUDAHOST_ATTR = CursorKind(415)
 
 ###
 # Preprocessing
index 3d4a229..49d2bc4 100644 (file)
@@ -2168,8 +2168,12 @@ enum CXCursorKind {
   CXCursor_PureAttr                      = 409,
   CXCursor_ConstAttr                     = 410,
   CXCursor_NoDuplicateAttr               = 411,
-  CXCursor_LastAttr                      = CXCursor_NoDuplicateAttr,
-     
+  CXCursor_CUDAConstantAttr              = 412,
+  CXCursor_CUDADeviceAttr                = 413,
+  CXCursor_CUDAGlobalAttr                = 414,
+  CXCursor_CUDAHostAttr                  = 415,
+  CXCursor_LastAttr                      = CXCursor_CUDAHostAttr,
+
   /* Preprocessing */
   CXCursor_PreprocessingDirective        = 500,
   CXCursor_MacroDefinition               = 501,
diff --git a/clang/test/Index/attributes-cuda.cu b/clang/test/Index/attributes-cuda.cu
new file mode 100644 (file)
index 0000000..e0023a1
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: c-index-test -test-load-source all -x cuda %s | FileCheck %s
+
+__attribute__((device)) void f_device();
+__attribute__((global)) void f_global();
+__attribute__((constant)) int* g_constant;
+__attribute__((host)) void f_host();
+
+
+// CHECK:       attributes-cuda.cu:3:30: FunctionDecl=f_device:3:30
+// CHECK-NEXT:  attributes-cuda.cu:3:16: attribute(device)
+// CHECK:       attributes-cuda.cu:4:30: FunctionDecl=f_global:4:30
+// CHECK-NEXT:  attributes-cuda.cu:4:16: attribute(global)
+// CHECK:       attributes-cuda.cu:5:32: VarDecl=g_constant:5:32 (Definition)
+// CHECK-NEXT:  attributes-cuda.cu:5:16: attribute(constant)
+// CHECK:       attributes-cuda.cu:6:28: FunctionDecl=f_host:6:28
+// CHECK-NEXT:  attributes-cuda.cu:6:16: attribute(host)
index bc1174a..ef4ddea 100644 (file)
@@ -3879,6 +3879,14 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
     return cxstring::createRef("attribute(const)");
   case CXCursor_NoDuplicateAttr:
     return cxstring::createRef("attribute(noduplicate)");
+  case CXCursor_CUDAConstantAttr:
+    return cxstring::createRef("attribute(constant)");
+  case CXCursor_CUDADeviceAttr:
+    return cxstring::createRef("attribute(device)");
+  case CXCursor_CUDAGlobalAttr:
+    return cxstring::createRef("attribute(global)");
+  case CXCursor_CUDAHostAttr:
+    return cxstring::createRef("attribute(host)");
   case CXCursor_PreprocessingDirective:
     return cxstring::createRef("preprocessing directive");
   case CXCursor_MacroDefinition:
index fb4ce66..1d4d14e 100644 (file)
@@ -53,6 +53,10 @@ static CXCursorKind GetCursorKind(const Attr *A) {
     case attr::Pure: return CXCursor_PureAttr;
     case attr::Const: return CXCursor_ConstAttr;
     case attr::NoDuplicate: return CXCursor_NoDuplicateAttr;
+    case attr::CUDAConstant: return CXCursor_CUDAConstantAttr;
+    case attr::CUDADevice: return CXCursor_CUDADeviceAttr;
+    case attr::CUDAGlobal: return CXCursor_CUDAGlobalAttr;
+    case attr::CUDAHost: return CXCursor_CUDAHostAttr;
   }
 
   return CXCursor_UnexposedAttr;