From patchwork Fri Jun 16 01:01:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 108774 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1012863vqr; Thu, 15 Jun 2023 18:02:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7aDP0lTAjjCg6H5Nr+Gr8KRCbBgtEG1kt5I0mcaUF2+dXVWu5qQ1Aj2yZgWEquYxnZ2XW6 X-Received: by 2002:a17:907:2be3:b0:96f:7b4a:2909 with SMTP id gv35-20020a1709072be300b0096f7b4a2909mr456796ejc.26.1686877349806; Thu, 15 Jun 2023 18:02:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686877349; cv=none; d=google.com; s=arc-20160816; b=uWggxFB5/hNhm87cNXao2A2Tm5xrCSOHzvgYpMgrqeK0EFW+bJI9J2aIRsSt2d4Oxu pNx+XLUkboJtKhDLH1D74Ccfqat/z8XAA9Fv9BdgzxhdlmMrS//xtRl+GHf7L3udm9uu QotVFuZM7dyciUo0oJ1QBWtkg/oth5n34LWqxSDsHuLPhvrfGlTgoEb8whD5P8u9ZsIF 9dqG8vb6M9vHj305wokP6d6ZnYMExX40oIOjXTvggNB4yHiRQuZxddbWBBOYMhGzEQKj kzL4YghQbiu6mkK31wanl5zM2Odq4soSjqVHTtOE73Md0sksEJokqEHcZ8cwLn9TbS7q hQZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=xZUqttf9R4FmIDbUc+CndK5hiVX1ChKLNw+iXjUHfZI=; b=WjWjm0EgCsqje6ngA4v9muzJ9uoaFmcoaWcmkvzmrX0OLtWkZctX/htN+g2viGUanL /vjHTf52baeQ3/kjBrvKYk0dGcm0G0133nKON85tNcSosN9JstnyKes6TM/yymjQIUpQ LSVZqW/+Io/NngRlZLirgniZ6gnscfc/oHEfno84V6L1fPtaf3+AxOImr/9dhD1sawSK vFexOzeMta5UL/g8W/ghnfhVuSz4vU8UtmSgZ3BxRt4USnqEb96aAx8WHNlRcqTNifdZ 54v+BEvpRYFt9A5wtmzsfORIh3QlCzQ1NTIl37VMceEh6TP/7WBcJzfYutWE8BvbEneN Jn/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=a5XXkvxT; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i22-20020a17090685d600b0098314b13e50si507755ejy.466.2023.06.15.18.02.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jun 2023 18:02:29 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=a5XXkvxT; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7C71838555A4 for ; Fri, 16 Jun 2023 01:02:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7C71838555A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686877348; bh=xZUqttf9R4FmIDbUc+CndK5hiVX1ChKLNw+iXjUHfZI=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=a5XXkvxT3d79b/bViv/e/vOvYymthBXFxumre0E4WyRQtede6gVLniGJdP4KCqa4n diN69ExwB4L3jnaY0j6dNE5FkSTPZkQorM92xJ6TPDNvWqj/01INSxtgjVrfaAcBDj MdQjRHRTJGyVaxy/P9bpJHVe0nwYH1zsVmCKKrtk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 322E8385771A for ; Fri, 16 Jun 2023 01:01:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 322E8385771A Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-652-mOGDh8mlP-KhgJA3IBcDgg-1; Thu, 15 Jun 2023 21:01:39 -0400 X-MC-Unique: mOGDh8mlP-KhgJA3IBcDgg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B621101A58E for ; Fri, 16 Jun 2023 01:01:39 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.32.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65C5C48FB01; Fri, 16 Jun 2023 01:01:39 +0000 (UTC) To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] c: add name hints to c_parser_declspecs [PR107583] Date: Thu, 15 Jun 2023 21:01:38 -0400 Message-Id: <20230616010138.1047991-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: David Malcolm via Gcc-patches From: David Malcolm Reply-To: David Malcolm Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768819103798505508?= X-GMAIL-MSGID: =?utf-8?q?1768819103798505508?= PR c/107583 notes that we weren't issuing a hint for struct foo { time_t mytime; /* missing include should trigger fixit */ }; in the C frontend. The root cause is that one of the "unknown type name" diagnostics was missing logic to emit hints, which this patch fixes. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-1876-g57446d1bc9757e. gcc/c/ChangeLog: PR c/107583 * c-parser.cc (c_parser_declspecs): Add hints to "unknown type name" error. gcc/testsuite/ChangeLog: PR c/107583 * c-c++-common/spellcheck-pr107583.c: New test. --- gcc/c/c-parser.cc | 14 +++++++++++++- gcc/testsuite/c-c++-common/spellcheck-pr107583.c | 10 ++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/spellcheck-pr107583.c diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 5baa501dbee..f8b14e4c688 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -3182,7 +3182,19 @@ c_parser_declspecs (c_parser *parser, struct c_declspecs *specs, attrs_ok = true; if (kind == C_ID_ID) { - error_at (loc, "unknown type name %qE", value); + auto_diagnostic_group d; + name_hint hint = lookup_name_fuzzy (value, FUZZY_LOOKUP_TYPENAME, + loc); + if (const char *suggestion = hint.suggestion ()) + { + gcc_rich_location richloc (loc); + richloc.add_fixit_replace (suggestion); + error_at (&richloc, + "unknown type name %qE; did you mean %qs?", + value, suggestion); + } + else + error_at (loc, "unknown type name %qE", value); t.kind = ctsk_typedef; t.spec = error_mark_node; } diff --git a/gcc/testsuite/c-c++-common/spellcheck-pr107583.c b/gcc/testsuite/c-c++-common/spellcheck-pr107583.c new file mode 100644 index 00000000000..86a9e7dbcb6 --- /dev/null +++ b/gcc/testsuite/c-c++-common/spellcheck-pr107583.c @@ -0,0 +1,10 @@ +struct s1 { + time_t mytime; /* { dg-error "unknown type name 'time_t'" "c error" { target c } } */ + /* { dg-error "'time_t' does not name a type" "c++ error" { target c++ } .-1 } */ + /* { dg-message "'time_t' is defined in header" "hint" { target *-*-* } .-2 } */ +}; + +struct s2 { + unsinged i; /* { dg-error "unknown type name 'unsinged'; did you mean 'unsigned'." "c error" { target c } } */ + /* { dg-error "'unsinged' does not name a type; did you mean 'unsigned'." "c++ error" { target c++ } .-1 } */ +};