From: David Malcolm <dmalcolm@redhat.com>
To: gcc-patches@gcc.gnu.org
Cc: David Malcolm <dmalcolm@redhat.com>
Subject: [PATCH] C: don't suggest names that came from earlier failures (PR c/83056)
Date: Tue, 21 Nov 2017 15:51:00 -0000 [thread overview]
Message-ID: <1511279156-23452-1-git-send-email-dmalcolm@redhat.com> (raw)
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.
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
OK for trunk and for gcc-7-branch?
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.
---
gcc/c/c-decl.c | 2 ++
gcc/testsuite/gcc.dg/spellcheck-pr83056.c | 11 +++++++++++
2 files changed, 13 insertions(+)
create mode 100644 gcc/testsuite/gcc.dg/spellcheck-pr83056.c
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index e0a4dd1..9c3beab 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -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)
diff --git a/gcc/testsuite/gcc.dg/spellcheck-pr83056.c b/gcc/testsuite/gcc.dg/spellcheck-pr83056.c
new file mode 100644
index 0000000..8b90887
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/spellcheck-pr83056.c
@@ -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'" } */
+}
--
1.8.5.3
next reply other threads:[~2017-11-21 15:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-21 15:51 David Malcolm [this message]
2017-11-21 15:56 ` Marek Polacek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1511279156-23452-1-git-send-email-dmalcolm@redhat.com \
--to=dmalcolm@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).