diff mbox

[C] Ignore invisible bindings for misspelling hints (PR c/71858)

Message ID 20160714145016.GE7387@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek July 14, 2016, 2:50 p.m. UTC
Hi!

As mentioned in the PR, anticipated decls should be ignored from fuzzy
lookups, unless the corresponding decl is declared first.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2016-07-13  Jakub Jelinek  <jakub@redhat.com>

	PR c/71858
	* c-decl.c (lookup_name_fuzzy): Ignore binding->invisible.

	* gcc.dg/spellcheck-identifiers.c (snprintf): Declare.
	* gcc.dg/spellcheck-identifiers-2.c: New test.
	* gcc.dg/diagnostic-token-ranges.c (nanl): Declare.
	* c-c++-common/attributes-1.c: Adjust dg-prune-output.


	Jakub

Comments

Marek Polacek July 14, 2016, 2:55 p.m. UTC | #1
On Thu, Jul 14, 2016 at 04:50:16PM +0200, Jakub Jelinek wrote:
> Hi!
> 
> As mentioned in the PR, anticipated decls should be ignored from fuzzy
> lookups, unless the corresponding decl is declared first.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2016-07-13  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c/71858
> 	* c-decl.c (lookup_name_fuzzy): Ignore binding->invisible.
> 
> 	* gcc.dg/spellcheck-identifiers.c (snprintf): Declare.
> 	* gcc.dg/spellcheck-identifiers-2.c: New test.
> 	* gcc.dg/diagnostic-token-ranges.c (nanl): Declare.
> 	* c-c++-common/attributes-1.c: Adjust dg-prune-output.
> 
> --- gcc/c/c-decl.c.jj	2016-06-24 12:59:22.000000000 +0200
> +++ gcc/c/c-decl.c	2016-07-13 22:40:23.410658411 +0200
> @@ -4021,7 +4021,7 @@ lookup_name_fuzzy (tree name, enum looku
>    for (c_scope *scope = current_scope; scope; scope = scope->outer)
>      for (c_binding *binding = scope->bindings; binding; binding = binding->prev)
>        {
> -	if (!binding->id)
> +	if (!binding->id || binding->invisible)
>  	  continue;
>  	/* Don't use bindings from implicitly declared functions,
>  	   as they were likely misspellings themselves.  */

This is OK as long as David is fine with the testsuite part.  Thanks,

	Marek
diff mbox

Patch

--- gcc/c/c-decl.c.jj	2016-06-24 12:59:22.000000000 +0200
+++ gcc/c/c-decl.c	2016-07-13 22:40:23.410658411 +0200
@@ -4021,7 +4021,7 @@  lookup_name_fuzzy (tree name, enum looku
   for (c_scope *scope = current_scope; scope; scope = scope->outer)
     for (c_binding *binding = scope->bindings; binding; binding = binding->prev)
       {
-	if (!binding->id)
+	if (!binding->id || binding->invisible)
 	  continue;
 	/* Don't use bindings from implicitly declared functions,
 	   as they were likely misspellings themselves.  */
--- gcc/testsuite/gcc.dg/spellcheck-identifiers.c.jj	2016-06-24 12:59:12.000000000 +0200
+++ gcc/testsuite/gcc.dg/spellcheck-identifiers.c	2016-07-14 10:03:36.147466813 +0200
@@ -121,7 +121,7 @@  test_6 (enum foo f)
     }
 }
 
-/* Verify that we offer names of builtins as suggestions.  */
+int snprintf (char *, __SIZE_TYPE__, const char *, ...);
 
 void
 test_7 (int i, int j)
--- gcc/testsuite/gcc.dg/spellcheck-identifiers-2.c.jj	2016-07-14 09:44:16.351537449 +0200
+++ gcc/testsuite/gcc.dg/spellcheck-identifiers-2.c	2016-07-14 10:02:21.965426567 +0200
@@ -0,0 +1,33 @@ 
+/* PR c/71858 */
+/* Make sure anticipated builtins are not considered before they are declared.  */
+/* { dg-do compile } */
+/* { dg-options "-Wimplicit-function-declaration -fdiagnostics-show-caret" } */
+
+int sscafn (const char *, const char *, ...);
+
+int
+test_1 (const char *p)
+{
+  int i;
+  return ssacnf (p, "%d", &i); /* { dg-warning "10: implicit declaration of function .ssacnf.; did you mean .sscafn.?" } */
+  /* { dg-begin-multiline-output "" }
+   return ssacnf (p, "%d", &i);
+          ^~~~~~
+          sscafn
+   { dg-end-multiline-output "" } */
+}
+
+int scafn (const char *, ...);
+int scanf (const char *, ...);
+
+int
+test_2 (void)
+{
+  int i;
+  return sacnf ("%d", &i); /* { dg-warning "10: implicit declaration of function .sacnf.; did you mean .scanf.?" } */
+  /* { dg-begin-multiline-output "" }
+   return sacnf ("%d", &i);
+          ^~~~~
+          scanf
+   { dg-end-multiline-output "" } */
+}
--- gcc/testsuite/gcc.dg/diagnostic-token-ranges.c.jj	2016-06-24 12:59:12.000000000 +0200
+++ gcc/testsuite/gcc.dg/diagnostic-token-ranges.c	2016-07-14 11:06:23.013803011 +0200
@@ -2,6 +2,8 @@ 
 
 /* Verify that various diagnostics show source code ranges.  */
 
+long double nanl (const char *);
+
 /* These ones merely use token ranges; they don't use tree ranges.  */
 
 void undeclared_identifier (void)
--- gcc/testsuite/c-c++-common/attributes-1.c.jj	2016-06-23 14:31:57.000000000 +0200
+++ gcc/testsuite/c-c++-common/attributes-1.c	2016-07-14 14:51:34.871006659 +0200
@@ -1,5 +1,5 @@ 
 /* { dg-do compile } */
-/* { dg-prune-output "undeclared here \\(not in a function\\); did you mean .carg..|\[^\n\r\]* was not declared in this scope" } */
+/* { dg-prune-output "undeclared here \\(not in a function\\); did you mean .char..|\[^\n\r\]* was not declared in this scope" } */
 
 void* my_calloc(unsigned, unsigned) __attribute__((alloc_size(1,bar))); /* { dg-warning "outside range" } */
 void* my_realloc(void*, unsigned) __attribute__((alloc_size(bar))); /* { dg-warning "outside range" } */