[PATCH] D58570: [libclang] Expose warn_unused and warn_unused_result attributes.
Emilio Cobos Álvarez via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 22 20:35:13 PST 2019
emilio created this revision.
emilio added reviewers: arphaman, Anastasia.
Herald added subscribers: cfe-commits, JDevlieghere.
Herald added a project: clang.
This is helpful to properly detect them, and fixing issues like
https://github.com/rust-lang/rust-bindgen/issues/1518.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D58570
Files:
clang/include/clang-c/Index.h
clang/test/Index/attributes.c
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp
Index: clang/tools/libclang/CXCursor.cpp
===================================================================
--- clang/tools/libclang/CXCursor.cpp
+++ clang/tools/libclang/CXCursor.cpp
@@ -79,6 +79,8 @@
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;
Index: clang/tools/libclang/CIndex.cpp
===================================================================
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -5477,6 +5477,10 @@
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: clang/test/Index/attributes.c
===================================================================
--- clang/test/Index/attributes.c
+++ clang/test/Index/attributes.c
@@ -14,6 +14,12 @@
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 @@
// 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: clang/include/clang-c/Index.h
===================================================================
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -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 @@
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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58570.188026.patch
Type: text/x-patch
Size: 3347 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190223/bbb8169d/attachment.bin>
More information about the cfe-commits
mailing list