This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] C: don't suggest names that came from earlier failures (PR c/83056)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]