aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-12-10 07:23:11 +0000
committerDouglas Gregor <dgregor@apple.com>2010-12-10 07:23:11 +0000
commit85fe1560b061b5f93a52dbd07cddd6e808854710 (patch)
treebcd0dc8eea9c1b8000f267f385fc00150087a5f8
parent30daefc5b559d4f32683503e36c14eba3c58ea62 (diff)
In clang_getCursor(), don't override a preprocessing cursor within
another preprocessing cursor, since we want the outermost one. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121470 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--test/Index/c-index-getCursor-pp.c7
-rw-r--r--tools/libclang/CIndex.cpp6
2 files changed, 13 insertions, 0 deletions
diff --git a/test/Index/c-index-getCursor-pp.c b/test/Index/c-index-getCursor-pp.c
index 2393965c28..8f986912cd 100644
--- a/test/Index/c-index-getCursor-pp.c
+++ b/test/Index/c-index-getCursor-pp.c
@@ -8,6 +8,11 @@ void OBSCURE(func)(int x) {
#include "a.h"
+#define A(X) X
+#define B(X) A(X)
+
+B(int x);
+
// RUN: c-index-test -cursor-at=%s:1:11 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-1 %s
// CHECK-1: macro definition=OBSCURE
// RUN: c-index-test -cursor-at=%s:2:14 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-2 %s
@@ -20,6 +25,8 @@ void OBSCURE(func)(int x) {
// CHECK-5: macro instantiation=DECORATION:2:9
// RUN: c-index-test -cursor-at=%s:9:10 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-6 %s
// CHECK-6: inclusion directive=a.h
+// RUN: c-index-test -cursor-at=%s:14:1 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-7 %s
+// CHECK-7: macro instantiation=B:12:9
// Same tests, but with "editing" optimizations
// RUN: env CINDEXTEST_EDITING=1 c-index-test -cursor-at=%s:1:11 -I%S/Inputs %s | FileCheck -check-prefix=CHECK-1 %s
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index a74a7a9895..d9aec47558 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -3069,6 +3069,12 @@ enum CXChildVisitResult GetCursorVisitor(CXCursor cursor,
cursor.kind == CXCursor_TypeRef)
return CXChildVisit_Recurse;
+ // Don't override a preprocessing cursor with another preprocessing
+ // cursor; we want the outermost preprocessing cursor.
+ if (clang_isPreprocessing(cursor.kind) &&
+ clang_isPreprocessing(BestCursor->kind))
+ return CXChildVisit_Recurse;
+
*BestCursor = cursor;
return CXChildVisit_Recurse;
}