From: Eli Bendersky Date: Wed, 28 May 2014 19:29:58 +0000 (+0000) Subject: Expose CUDA function attributes to the C interface. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f722606af2c9dbc2d24705254bdf89bcc48a7a79;p=clang Expose CUDA function attributes to the C interface. Until now all CUDA-specific attributes were represented with CXCursor_UnexposedAttr; now they are actually implemented, including the Python bindings. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209767 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/bindings/python/clang/cindex.py b/bindings/python/clang/cindex.py index cfc27d9b35..779fa14c88 100644 --- a/bindings/python/clang/cindex.py +++ b/bindings/python/clang/cindex.py @@ -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 diff --git a/include/clang-c/Index.h b/include/clang-c/Index.h index 3d4a229d28..49d2bc4047 100644 --- a/include/clang-c/Index.h +++ b/include/clang-c/Index.h @@ -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/test/Index/attributes-cuda.cu b/test/Index/attributes-cuda.cu new file mode 100644 index 0000000000..e0023a1366 --- /dev/null +++ b/test/Index/attributes-cuda.cu @@ -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) diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index bc1174ae3c..ef4ddeab94 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -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: diff --git a/tools/libclang/CXCursor.cpp b/tools/libclang/CXCursor.cpp index fb4ce66d3a..1d4d14ef91 100644 --- a/tools/libclang/CXCursor.cpp +++ b/tools/libclang/CXCursor.cpp @@ -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;