aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/libclang/LibclangTest.cpp
diff options
context:
space:
mode:
authorfridtjof <fridtjof@das-labor.org>2023-08-10 12:40:23 -0400
committerAaron Ballman <aaron@aaronballman.com>2023-08-10 12:40:23 -0400
commit5aa06b18940c9b96cbf1c31da6aee3fbb92183ed (patch)
tree30540c78eb1c73834ebd3921ce734d154ffa747d /clang/unittests/libclang/LibclangTest.cpp
parent2df9328fe3a0575fa415964a3c3544b0912b168e (diff)
downloadllvm-5aa06b18940c9b96cbf1c31da6aee3fbb92183ed.zip
llvm-5aa06b18940c9b96cbf1c31da6aee3fbb92183ed.tar.gz
llvm-5aa06b18940c9b96cbf1c31da6aee3fbb92183ed.tar.bz2
[libclang] Expose arguments of clang::annotate
This enables easy consumption of arbitrary data added to this annotation in addition to the annotation category, which was already exposed. Differential Revision: https://reviews.llvm.org/D151373
Diffstat (limited to 'clang/unittests/libclang/LibclangTest.cpp')
-rw-r--r--clang/unittests/libclang/LibclangTest.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp
index 295706c..fe40352 100644
--- a/clang/unittests/libclang/LibclangTest.cpp
+++ b/clang/unittests/libclang/LibclangTest.cpp
@@ -1246,6 +1246,50 @@ static_assert(true, message);
EXPECT_EQ(fromCXString(clang_getCursorSpelling(*staticAssertCsr)), "");
}
+TEST_F(LibclangParseTest, ExposesAnnotateArgs) {
+ const char testSource[] = R"cpp(
+[[clang::annotate("category", 42)]]
+void func() {}
+)cpp";
+ std::string fileName = "main.cpp";
+ WriteFile(fileName, testSource);
+
+ const char *Args[] = {"-xc++"};
+ ClangTU = clang_parseTranslationUnit(Index, fileName.c_str(), Args, 1,
+ nullptr, 0, TUFlags);
+
+ int attrCount = 0;
+
+ Traverse(
+ [&attrCount](CXCursor cursor, CXCursor parent) -> CXChildVisitResult {
+ if (cursor.kind == CXCursor_AnnotateAttr) {
+ int childCount = 0;
+ clang_visitChildren(
+ cursor,
+ [](CXCursor child, CXCursor,
+ CXClientData data) -> CXChildVisitResult {
+ int *pcount = static_cast<int *>(data);
+
+ // we only expect one argument here, so bail otherwise
+ EXPECT_EQ(*pcount, 0);
+
+ auto *result = clang_Cursor_Evaluate(child);
+ EXPECT_NE(result, nullptr);
+ EXPECT_EQ(clang_EvalResult_getAsInt(result), 42);
+ ++*pcount;
+
+ return CXChildVisit_Recurse;
+ },
+ &childCount);
+ attrCount++;
+ return CXChildVisit_Continue;
+ }
+ return CXChildVisit_Recurse;
+ });
+
+ EXPECT_EQ(attrCount, 1);
+}
+
class LibclangRewriteTest : public LibclangParseTest {
public:
CXRewriter Rew = nullptr;