There's 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. This patch fixes it.
rdar://38888477
Differential D49051
[libclang] check that the cursor is declaration before trying to evaluate the cursor like a declaration Authored by arphaman on Jul 6 2018, 7:11 PM.
Details
There's 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. This patch fixes it. rdar://38888477
Diff Detail
Event TimelineComment Actions LGTM.
| ||||||||||||||
There's unfortunate nesting here. It would be nice if, either pre-commit or post-commit, you could refactor this to be more straightline using early returns. E.g.:
static CXEvalResult evaluateDeclExpr(const Decl *D) { if (!D) return nullptr; // ... } static CXEvalResult evaluateCompoundStmtExpr(const CompoundStmt *CS) { if (!CS) return nullptr; // ... } CXEvalResult clang_Cursor_Evaluate(CXCursor C) { if (clang_isDeclaration(C.kind)) { return evaluateDeclExpr(getCursorDecl(C)); return evaluateCompoundStmtExpr( dyn_cast_or_null<CompoundStmt>(getCursorStmt(C))); }