]> granicus.if.org Git - clang/commitdiff
[libclang] Expose warn_unused and warn_unused_result attributes.
authorEmilio Cobos Alvarez <emilio@crisal.io>
Mon, 25 Feb 2019 21:24:52 +0000 (21:24 +0000)
committerEmilio Cobos Alvarez <emilio@crisal.io>
Mon, 25 Feb 2019 21:24:52 +0000 (21:24 +0000)
This is helpful to properly detect them, and fixing issues like
https://github.com/rust-lang/rust-bindgen/issues/1518.

Differential Revision: https://reviews.llvm.org/D58570

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

bindings/python/clang/cindex.py
include/clang-c/Index.h
test/Index/attributes.c
tools/libclang/CIndex.cpp
tools/libclang/CXCursor.cpp

index 50e6f0e5b64e5cec99750bf9d76a558f4dcffb35..d9684db17512be38fcdf3a4804ec22b0a85c88fa 100644 (file)
@@ -1343,6 +1343,8 @@ CursorKind.VISIBILITY_ATTR = CursorKind(417)
 CursorKind.DLLEXPORT_ATTR = CursorKind(418)
 CursorKind.DLLIMPORT_ATTR = CursorKind(419)
 CursorKind.CONVERGENT_ATTR = CursorKind(438)
+CursorKind.WARN_UNUSED_ATTR = CursorKind(439)
+CursorKind.WARN_UNUSED_RESULT_ATTR = CursorKind(440)
 
 ###
 # Preprocessing
index 38af8aa6d8b6c3783df76a6446d52452bff789f0..e6555fae78a08b32bc813dfc28c52ddfd1f52725 100644 (file)
@@ -32,7 +32,7 @@
  * compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
  */
 #define CINDEX_VERSION_MAJOR 0
-#define CINDEX_VERSION_MINOR 51
+#define CINDEX_VERSION_MINOR 52
 
 #define CINDEX_VERSION_ENCODE(major, minor) ( \
       ((major) * 10000)                       \
@@ -2587,7 +2587,9 @@ enum CXCursorKind {
   CXCursor_ObjCBoxable                   = 436,
   CXCursor_FlagEnum                      = 437,
   CXCursor_ConvergentAttr                = 438,
-  CXCursor_LastAttr                      = CXCursor_ConvergentAttr,
+  CXCursor_WarnUnusedAttr                = 439,
+  CXCursor_WarnUnusedResultAttr          = 440,
+  CXCursor_LastAttr                      = CXCursor_WarnUnusedResultAttr,
 
   /* Preprocessing */
   CXCursor_PreprocessingDirective        = 500,
index 3aedacd33fa4b648c8bdfb2fbf5bb5aeb2d89b8c..1db3be9bcbbe5c9b852d7b35cd1c61a98001d7a7 100644 (file)
@@ -14,6 +14,12 @@ enum __attribute((flag_enum)) FlagEnum {
 
 void convergent_fn() __attribute__((convergent));
 
+int warn_unused_result_fn() __attribute__((warn_unused_result));
+
+struct __attribute__((warn_unused)) WarnUnused {
+  int b;
+};
+
 // CHECK: attributes.c:3:32: StructDecl=Test2:3:32 (Definition) Extent=[3:1 - 5:2]
 // CHECK: attributes.c:3:23: attribute(packed)=packed Extent=[3:23 - 3:29]
 // CHECK: attributes.c:4:8: FieldDecl=a:4:8 (Definition) Extent=[4:3 - 4:9] [access=public]
@@ -29,3 +35,7 @@ void convergent_fn() __attribute__((convergent));
 // CHECK: attributes.c:12:3: EnumConstantDecl=Foo:12:3 (Definition) Extent=[12:3 - 12:6]
 // CHECK: attributes.c:15:6: FunctionDecl=convergent_fn:15:6 Extent=[15:1 - 15:49]
 // CHECK: attributes.c:15:37: attribute(convergent)= Extent=[15:37 - 15:47]
+// CHECK: attributes.c:17:5: FunctionDecl=warn_unused_result_fn:17:5 Extent=[17:1 - 17:64]
+// CHECK: attributes.c:17:44: attribute(warn_unused_result)= Extent=[17:44 - 17:62]
+// CHECK: attributes.c:19:37: StructDecl=WarnUnused:19:37 (Definition) Extent=[19:1 - 21:2]
+// CHECK: attributes.c:19:23: attribute(warn_unused)= Extent=[19:23 - 19:34]
index a931fccdf60f0838b2a959bba74c35557c2ba9c7..78a1290de658ebde92e0e7c983562707b0962167 100644 (file)
@@ -5477,6 +5477,10 @@ CXString clang_getCursorKindSpelling(enum CXCursorKind Kind) {
       return cxstring::createRef("FriendDecl");
   case CXCursor_ConvergentAttr:
       return cxstring::createRef("attribute(convergent)");
+  case CXCursor_WarnUnusedAttr:
+      return cxstring::createRef("attribute(warn_unused)");
+  case CXCursor_WarnUnusedResultAttr:
+      return cxstring::createRef("attribute(warn_unused_result)");
   }
 
   llvm_unreachable("Unhandled CXCursorKind");
index fdd24261cb1bdf011290145303b835e5d56147b9..e4a0291f1407ebad6a70307bf7a11ee21b2d70cc 100644 (file)
@@ -79,6 +79,8 @@ static CXCursorKind GetCursorKind(const Attr *A) {
     case attr::ObjCBoxable: return CXCursor_ObjCBoxable;
     case attr::FlagEnum: return CXCursor_FlagEnum;
     case attr::Convergent: return CXCursor_ConvergentAttr;
+    case attr::WarnUnused: return CXCursor_WarnUnusedAttr;
+    case attr::WarnUnusedResult: return CXCursor_WarnUnusedResultAttr;
   }
 
   return CXCursor_UnexposedAttr;