aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2019-01-08 22:32:51 +0000
committerAlex Lorenz <arphaman@gmail.com>2019-01-08 22:32:51 +0000
commit65317e1ca0700fc124612cb6659679b6d8e73601 (patch)
tree2391646812587a49135048cf61bba19bf937199f /clang/unittests
parentb6d674f6feca095a52891ac692858e1a251cb5c3 (diff)
[libclang] Recommit r336590 with a fix for the memory leak in the test
The original commit had a memory leak in the test has a leak as it doesn't dispose of the evaluated cursor result. This also contains the follow-up NFC refactoring commit r336591. rdar://45893054 Original commit message: [libclang] evalute compound statement cursors before trying to evaluate the cursor like a declaration This change fixes a bug in libclang in which it tries to evaluate a statement cursor as a declaration cursor, because that statement still has a pointer to the declaration parent. rdar://38888477 Differential Revision: https://reviews.llvm.org/D49051 llvm-svn: 350666
Diffstat (limited to 'clang/unittests')
-rw-r--r--clang/unittests/libclang/LibclangTest.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/clang/unittests/libclang/LibclangTest.cpp b/clang/unittests/libclang/LibclangTest.cpp
index 6fddcb2cbf26..b88b88dac338 100644
--- a/clang/unittests/libclang/LibclangTest.cpp
+++ b/clang/unittests/libclang/LibclangTest.cpp
@@ -461,6 +461,48 @@ TEST_F(LibclangParseTest, AllSkippedRanges) {
clang_disposeSourceRangeList(Ranges);
}
+TEST_F(LibclangParseTest, EvaluateChildExpression) {
+ std::string Main = "main.m";
+ WriteFile(Main, "#define kFOO @\"foo\"\n"
+ "void foobar(void) {\n"
+ " {kFOO;}\n"
+ "}\n");
+ ClangTU = clang_parseTranslationUnit(Index, Main.c_str(), nullptr, 0, nullptr,
+ 0, TUFlags);
+
+ CXCursor C = clang_getTranslationUnitCursor(ClangTU);
+ clang_visitChildren(
+ C,
+ [](CXCursor cursor, CXCursor parent,
+ CXClientData client_data) -> CXChildVisitResult {
+ if (clang_getCursorKind(cursor) == CXCursor_FunctionDecl) {
+ int numberedStmt = 0;
+ clang_visitChildren(
+ cursor,
+ [](CXCursor cursor, CXCursor parent,
+ CXClientData client_data) -> CXChildVisitResult {
+ int &numberedStmt = *((int *)client_data);
+ if (clang_getCursorKind(cursor) == CXCursor_CompoundStmt) {
+ if (numberedStmt) {
+ CXEvalResult RE = clang_Cursor_Evaluate(cursor);
+ EXPECT_NE(RE, nullptr);
+ EXPECT_EQ(clang_EvalResult_getKind(RE),
+ CXEval_ObjCStrLiteral);
+ clang_EvalResult_dispose(RE);
+ return CXChildVisit_Break;
+ }
+ numberedStmt++;
+ }
+ return CXChildVisit_Recurse;
+ },
+ &numberedStmt);
+ EXPECT_EQ(numberedStmt, 1);
+ }
+ return CXChildVisit_Continue;
+ },
+ nullptr);
+}
+
class LibclangReparseTest : public LibclangParseTest {
public:
void DisplayDiagnostics() {