From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 63386 invoked by alias); 1 Dec 2017 21:56:52 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 63374 invoked by uid 89); 1 Dec 2017 21:56:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.7 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KB_WAM_FROM_NAME_SINGLEWORD,SPF_HELO_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:3414, 20PM, 20pm X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 01 Dec 2017 21:56:50 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93CE937E74 for ; Fri, 1 Dec 2017 21:56:49 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-77.ams2.redhat.com [10.36.116.77]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3C97563B81; Fri, 1 Dec 2017 21:56:49 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id vB1LukbN018414; Fri, 1 Dec 2017 22:56:47 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id vB1LujGr018393; Fri, 1 Dec 2017 22:56:45 +0100 Date: Fri, 01 Dec 2017 21:56:00 -0000 From: Jakub Jelinek To: David Malcolm Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH] C/C++: don't suggest implementation names as spelling fixes (PR c/83236) Message-ID: <20171201215645.GZ2353@tucnak> Reply-To: Jakub Jelinek References: <1512164900-14249-1-git-send-email-dmalcolm@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1512164900-14249-1-git-send-email-dmalcolm@redhat.com> User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes X-SW-Source: 2017-12/txt/msg00067.txt.bz2 On Fri, Dec 01, 2017 at 04:48:20PM -0500, David Malcolm wrote: > PR c/83236 reports an issue where the C FE unhelpfully suggests the use > of glibc's private "__ino_t" type when it fails to recognize "ino_t": > > $ cat > test.c < #include > ino_t inode; > EOF > $ gcc -std=c89 -fsyntax-only test.c > test.c:2:1: error: unknown type name 'ino_t'; did you mean '__ino_t'? > ino_t inode; > ^~~~~ > __ino_t > > This patch updates the C/C++ FEs suggestions for unrecognized identifiers > so that they don't suggest names that are reserved for use by the > implementation i.e. those that begin with an underscore and either an > uppercase letter or another underscore. > > However, it allows built-in macros that match this pattern to be > suggested, since it's useful to be able to suggest __FILE__, __LINE__ > etc. Other macros *are* filtered. > > One wart with the patch: the existing macro-handling spellcheck code > is in spellcheck-tree.c, and needs to call the the new function > "name_reserved_for_implementation_p", however the latter relates to > the C family of FEs. > Perhaps I should move all of the the macro-handling stuff in > spellcheck-tree.h/c to e.g. a new c-family/c-spellcheck.h/c as a > first step? > > Successfully bootstrapped®rtested on x86_64-pc-linux-gnu. > > OK for trunk? > > gcc/c/ChangeLog: > PR c/83236 > * c-decl.c (lookup_name_fuzzy): Don't suggest names that are > reserved for use by the implementation. > > gcc/cp/ChangeLog: > PR c/83236 > * name-lookup.c (consider_binding_level): Don't suggest names that > are reserved for use by the implementation. > > gcc/ChangeLog: > PR c/83236 > * spellcheck-tree.c (name_reserved_for_implementation_p): New > function. > (should_suggest_as_macro_p): New function. > (find_closest_macro_cpp_cb): Move the check for NT_MACRO to > should_suggest_as_macro_p and call it. > (selftest::test_name_reserved_for_implementation_p): New function. > (selftest::spellcheck_tree_c_tests): Call it. > * spellcheck-tree.h (name_reserved_for_implementation_p): New > decl. > > gcc/testsuite/ChangeLog: > PR c/83236 > * c-c++-common/spellcheck-reserved.c: New test case. > --- > gcc/c/c-decl.c | 5 +++ > gcc/cp/name-lookup.c | 18 +++++++--- > gcc/spellcheck-tree.c | 46 +++++++++++++++++++++++- > gcc/spellcheck-tree.h | 2 ++ > gcc/testsuite/c-c++-common/spellcheck-reserved.c | 25 +++++++++++++ > 5 files changed, 91 insertions(+), 5 deletions(-) > create mode 100644 gcc/testsuite/c-c++-common/spellcheck-reserved.c > > diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c > index 56c63d8..dfd136d 100644 > --- a/gcc/c/c-decl.c > +++ b/gcc/c/c-decl.c > @@ -4041,6 +4041,11 @@ lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind, location_t loc) > if (TREE_CODE (binding->decl) == FUNCTION_DECL) > if (C_DECL_IMPLICIT (binding->decl)) > continue; > + /* Don't suggest names that are reserved for use by the > + implementation. */ > + if (name_reserved_for_implementation_p > + (IDENTIFIER_POINTER (binding->id))) Can't you use a temporary to avoid wrapping line between function name and ( ? More importantly, does this mean if I mistype __builtin_strtchr it won't suggest __builtin_strrchr? Would be nice if the filtering of the names reserved for implementation isn't done if the name being looked up is reserved for implementation. Jakub