sammccall created this revision.
sammccall added a reviewer: ilya-biryukov.
Herald added a subscriber: cfe-commits.
In particular, stderr etc where the equivalent symbols exist in the global
namespace. Having the symbol instead of the macro helps with ranking, and avoids
the current duplicate stderr suggestions.
@ilya-biryukov: think this is the right way to fix the duplicate completions?
Hiding the shadowed decl might be more correct, but it'd be hard *and* give
unfortunate ranking.
Repository:
rC Clang
https://reviews.llvm.org/D47896
Files:
lib/Sema/SemaCodeComplete.cpp
test/Index/complete-macros.c
Index: test/Index/complete-macros.c
===
--- test/Index/complete-macros.c
+++ test/Index/complete-macros.c
@@ -25,6 +25,12 @@
}
+int shadow;
+#define shadow shadow
+void test_shadow() {
+
+}
+
// RUN: c-index-test -code-completion-at=%s:7:1 %s -I%S | FileCheck
-check-prefix=CHECK-CC0 %s
// CHECK-CC0-NOT: FOO
// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test
-code-completion-at=%s:7:1 %s -I%S | FileCheck -check-prefix=CHECK-CC1 %s
@@ -45,3 +51,7 @@
// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test
-code-completion-at=%s:15:5 %s -I%S | FileCheck -check-prefix=CHECK-CC4 %s
// CHECK-CC4-NOT: COMPLETE_MACROS_H_GUARD
+
+// RUN: c-index-test -code-completion-at=%s:31:1 %s -I%S | FileCheck
-check-prefix=CHECK-SHADOW %s
+// CHECK-SHADOW: FunctionDecl:{ResultType void}{TypedText g}
+// CHECK-SHADOW-NOT: macro definition:{TypedText shadow}
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -3308,9 +3308,18 @@
M != MEnd; ++M) {
auto MD = PP.getMacroDefinition(M->first);
if (IncludeUndefined || MD) {
- if (MacroInfo *MI = MD.getMacroInfo())
+ if (MacroInfo *MI = MD.getMacroInfo()) {
if (MI->isUsedForHeaderGuard())
continue;
+// Some standard libraries e.g. #define stderr stderr, the underlying
+// decl is more useful.
+if (MI->getNumTokens() == 1 && MI->isObjectLike()) {
+ const Token = MI->getReplacementToken(0);
+ if (Tok.is(tok::identifier) &&
+ Tok.getIdentifierInfo()->getName() == M->first->getName())
+continue;
+}
+ }
Results.AddResult(Result(M->first,
getMacroUsagePriority(M->first->getName(),
Index: test/Index/complete-macros.c
===
--- test/Index/complete-macros.c
+++ test/Index/complete-macros.c
@@ -25,6 +25,12 @@
}
+int shadow;
+#define shadow shadow
+void test_shadow() {
+
+}
+
// RUN: c-index-test -code-completion-at=%s:7:1 %s -I%S | FileCheck -check-prefix=CHECK-CC0 %s
// CHECK-CC0-NOT: FOO
// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:7:1 %s -I%S | FileCheck -check-prefix=CHECK-CC1 %s
@@ -45,3 +51,7 @@
// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_COMPLETION_CACHING=1 c-index-test -code-completion-at=%s:15:5 %s -I%S | FileCheck -check-prefix=CHECK-CC4 %s
// CHECK-CC4-NOT: COMPLETE_MACROS_H_GUARD
+
+// RUN: c-index-test -code-completion-at=%s:31:1 %s -I%S | FileCheck -check-prefix=CHECK-SHADOW %s
+// CHECK-SHADOW: FunctionDecl:{ResultType void}{TypedText g}
+// CHECK-SHADOW-NOT: macro definition:{TypedText shadow}
Index: lib/Sema/SemaCodeComplete.cpp
===
--- lib/Sema/SemaCodeComplete.cpp
+++ lib/Sema/SemaCodeComplete.cpp
@@ -3308,9 +3308,18 @@
M != MEnd; ++M) {
auto MD = PP.getMacroDefinition(M->first);
if (IncludeUndefined || MD) {
- if (MacroInfo *MI = MD.getMacroInfo())
+ if (MacroInfo *MI = MD.getMacroInfo()) {
if (MI->isUsedForHeaderGuard())
continue;
+// Some standard libraries e.g. #define stderr stderr, the underlying
+// decl is more useful.
+if (MI->getNumTokens() == 1 && MI->isObjectLike()) {
+ const Token = MI->getReplacementToken(0);
+ if (Tok.is(tok::identifier) &&
+ Tok.getIdentifierInfo()->getName() == M->first->getName())
+continue;
+}
+ }
Results.AddResult(Result(M->first,
getMacroUsagePriority(M->first->getName(),
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits