diff options
author | Alex Lorenz <arphaman@gmail.com> | 2018-07-09 19:41:28 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2018-07-09 19:41:28 +0000 |
commit | 0b6fe1495ec1565f554715b650e7e13b391e0ab1 (patch) | |
tree | 473860b38322c2b5665ccd41ef27688b2f2a6775 /tools | |
parent | f983ca81222092615a93802c6820e9a46b5b9ac2 (diff) | |
download | clang-0b6fe1495ec1565f554715b650e7e13b391e0ab1.tar.gz |
[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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336590 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/libclang/CIndex.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp index b61dff3238..a4698830d9 100644 --- a/tools/libclang/CIndex.cpp +++ b/tools/libclang/CIndex.cpp @@ -3890,6 +3890,19 @@ static const ExprEvalResult* evaluateExpr(Expr *expr, CXCursor C) { } CXEvalResult clang_Cursor_Evaluate(CXCursor C) { + if (clang_getCursorKind(C) == CXCursor_CompoundStmt) { + const CompoundStmt *compoundStmt = cast<CompoundStmt>(getCursorStmt(C)); + Expr *expr = nullptr; + for (auto *bodyIterator : compoundStmt->body()) { + if ((expr = dyn_cast<Expr>(bodyIterator))) { + break; + } + } + if (expr) + return const_cast<CXEvalResult>( + reinterpret_cast<const void *>(evaluateExpr(expr, C))); + } + const Decl *D = getCursorDecl(C); if (D) { const Expr *expr = nullptr; @@ -3903,19 +3916,6 @@ CXEvalResult clang_Cursor_Evaluate(CXCursor C) { evaluateExpr(const_cast<Expr *>(expr), C))); return nullptr; } - - const CompoundStmt *compoundStmt = dyn_cast_or_null<CompoundStmt>(getCursorStmt(C)); - if (compoundStmt) { - Expr *expr = nullptr; - for (auto *bodyIterator : compoundStmt->body()) { - if ((expr = dyn_cast<Expr>(bodyIterator))) { - break; - } - } - if (expr) - return const_cast<CXEvalResult>( - reinterpret_cast<const void *>(evaluateExpr(expr, C))); - } return nullptr; } |