C: don't suggest names that came from earlier failures (PR c/83056)
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 21 Nov 2017 21:59:53 +0000 (21:59 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Tue, 21 Nov 2017 21:59:53 +0000 (21:59 +0000)
PR c/83056 reports an issue affecting trunk and gcc-7 in which
the C frontend's implementation of lookup_name_fuzzy uses undeclared
identifiers as suggestions when encountering subsequent undeclared
identifiers.

The fix is to filter out the names bound to error_mark_node
in lookup_name_fuzzy.

The C++ frontend is unaffected, as it already does this.

gcc/c/ChangeLog:
PR c/83056
* c-decl.c (lookup_name_fuzzy): Don't suggest names that came from
earlier failed lookups.

gcc/testsuite/ChangeLog:
PR c/83056
* gcc.dg/spellcheck-pr83056.c: New test case.

From-SVN: r255038

gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/spellcheck-pr83056.c [new file with mode: 0644]

index a2773b0956f343c1e747fb0045c91f408ec05445..a4dc563bb755699fbf6d7adf09cc5d8d6705968f 100644 (file)
@@ -1,3 +1,9 @@
+2017-11-21  David Malcolm  <dmalcolm@redhat.com>
+
+       PR c/83056
+       * c-decl.c (lookup_name_fuzzy): Don't suggest names that came from
+       earlier failed lookups.
+
 2017-11-21  Marc Glisse  <marc.glisse@inria.fr>
 
        * c-fold.c (c_fully_fold_internal): Handle POINTER_DIFF_EXPR.
index e0a4dd1661af815061cd3d68a19eada1945f8367..9c3beab0a8d0e218a09ec0bb7cc2c078ceb215e6 100644 (file)
@@ -4035,6 +4035,8 @@ lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind, location_t loc)
       {
        if (!binding->id || binding->invisible)
          continue;
+       if (binding->decl == error_mark_node)
+         continue;
        /* Don't use bindings from implicitly declared functions,
           as they were likely misspellings themselves.  */
        if (TREE_CODE (binding->decl) == FUNCTION_DECL)
index 0d86a8685345eaa99e57df8baa4326cc0d7b7ca1..b3e371e6e3159b73cc1e23be78f9ff1f0e7ef240 100644 (file)
@@ -1,3 +1,8 @@
+2017-11-21  David Malcolm  <dmalcolm@redhat.com>
+
+       PR c/83056
+       * gcc.dg/spellcheck-pr83056.c: New test case.
+
 2017-11-21  Martin Sebor  <msebor@redhat.com>
 
        PR tree-optimization/82945
diff --git a/gcc/testsuite/gcc.dg/spellcheck-pr83056.c b/gcc/testsuite/gcc.dg/spellcheck-pr83056.c
new file mode 100644 (file)
index 0000000..8b90887
--- /dev/null
@@ -0,0 +1,11 @@
+enum { TYPE_A };
+
+/* Verify that the incorrect "TYPE_B" etc don't get re-used for
+   suggestions for the later incorrect values.  */
+
+void pr83056(void)
+{
+  int b = TYPE_B; /* { dg-error "did you mean 'TYPE_A'" } */
+  int c = TYPE_C; /* { dg-error "did you mean 'TYPE_A'" } */
+  int d = TYPE_D; /* { dg-error "did you mean 'TYPE_A'" } */
+}