[PATCH] D47896: [CodeComplete] suppress define X X macros

2018-06-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Going to put this on hold until someone actually reports the bug.


Repository:
  rC Clang

https://reviews.llvm.org/D47896



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47896: [CodeComplete] suppress define X X macros

2018-06-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In https://reviews.llvm.org/D47896#1126171, @sammccall wrote:

> Hmm, musl does `#define stderr (stderr)` :-( And they discussed #define 
> stderr (stderr+0).
>  (To enforce it's not assigned to etc)
>  https://github.com/cloudius-systems/musl/blob/master/include/stdio.h#L61
>
> Ilya also pointed out offline the windows API convention: CreateFile is a 
> macro for CreateFileW or CreateFileA. In these cases merely suppressing the 
> macro isn't enough, we'd want to replace its info with the underlying decl.
>
> Not sure how/whether to generalize this hack...


Yeah, I'm not sure. Maybe we should just special-case the known cases...


Repository:
  rC Clang

https://reviews.llvm.org/D47896



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47896: [CodeComplete] suppress define X X macros

2018-06-08 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Hmm, musl does `#define stderr (stderr)` :-( And they discussed #define stderr 
(stderr+0).
(To enforce it's not assigned to etc)
https://github.com/cloudius-systems/musl/blob/master/include/stdio.h#L61

Ilya also pointed out offline the windows API convention: CreateFile is a macro 
for CreateFileW or CreateFileA. In these cases merely suppressing the macro 
isn't enough, we'd want to replace its info with the underlying decl.

Not sure how/whether to generalize this hack...


Repository:
  rC Clang

https://reviews.llvm.org/D47896



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D47896: [CodeComplete] suppress define X X macros

2018-06-07 Thread Sam McCall via Phabricator via cfe-commits
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