From patchwork Mon Jun 14 12:17:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1491649 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=a4WvSWfg; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G3VpP5xflz9sRN for ; Mon, 14 Jun 2021 22:18:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 12D0C383F40F for ; Mon, 14 Jun 2021 12:18:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12D0C383F40F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1623673080; bh=ONm915vAxE/bZsibyMooaiTDEbdUJkRuOEd8Y5kG8Ko=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=a4WvSWfg72LDsBVHua/52odxHAUIWK5O2yXiIeddTUdm0FEJ7axmwbPqzSmsZstjJ stzpxAX/uxH1jXE2G3rjfbdVzXnlFQzwNaMVjrfNDKJXx5Es5yDSNAO+/6y+zgcl1+ JyNhiyZT66SwOO5ksnqcT/J6izuVNS/ahlaBqfdY= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 4AB3B3857027 for ; Mon, 14 Jun 2021 12:17:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4AB3B3857027 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-103-l4q-DvJ-OuWXLtzDStK3dg-1; Mon, 14 Jun 2021 08:17:12 -0400 X-MC-Unique: l4q-DvJ-OuWXLtzDStK3dg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1B73F3625B for ; Mon, 14 Jun 2021 12:17:12 +0000 (UTC) Received: from localhost (unknown [10.33.36.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD36560C4A; Mon, 14 Jun 2021 12:17:11 +0000 (UTC) Date: Mon, 14 Jun 2021 13:17:10 +0100 To: gcc-patches@gcc.gnu.org Subject: [PATCH] c-family: Add fix-it suggestions for names [PR101052] Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-13.9 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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" PR c++/101052 gcc/c-family/ChangeLog: * known-headers.cc (get_stdlib_header_for_name): Add known headers for EXIT_FAILURE, EXIT_SUCCESS, abort, atexit, calloc, exit, and getenv. gcc/testsuite/ChangeLog: * g++.dg/spellcheck-stdlib.C: Add checks for names. * gcc.dg/spellcheck-stdlib.c: Likewise. There are no C tests for the functions because the C front-end doesn't give fix-it hints for them, it complains about mismatched implicit declarations. I assume this is why there were no existing tests for malloc, free, etc. Tested powerpc64le-linux. OK for trunk? commit 8f211596b34662f4b9a041fdf8634f69cf8efe4c Author: Jonathan Wakely Date: Mon Jun 14 11:38:11 2021 c-family: Add fix-it suggestions for names [PR101052] PR c++/101052 gcc/c-family/ChangeLog: * known-headers.cc (get_stdlib_header_for_name): Add known headers for EXIT_FAILURE, EXIT_SUCCESS, abort, atexit, calloc, exit, and getenv. gcc/testsuite/ChangeLog: * g++.dg/spellcheck-stdlib.C: Add checks for names. * gcc.dg/spellcheck-stdlib.c: Likewise. diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc index 85924718c8b..a3912468a8d 100644 --- a/gcc/c-family/known-headers.cc +++ b/gcc/c-family/known-headers.cc @@ -162,7 +162,14 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib) {"stdout", {"", ""} }, /* and . */ + {"EXIT_FAILURE", {"", ""} }, + {"EXIT_SUCCESS", {"", ""} }, + {"abort", {"", ""} }, + {"atexit", {"", ""} }, + {"calloc", {"", ""} }, + {"exit", {"", ""} }, {"free", {"", ""} }, + {"getenv", {"", ""} }, {"malloc", {"", ""} }, {"realloc", {"", ""} }, diff --git a/gcc/testsuite/g++.dg/spellcheck-stdlib.C b/gcc/testsuite/g++.dg/spellcheck-stdlib.C index 31e91fe8d1b..87736b25e54 100644 --- a/gcc/testsuite/g++.dg/spellcheck-stdlib.C +++ b/gcc/testsuite/g++.dg/spellcheck-stdlib.C @@ -138,6 +138,24 @@ void test_cstdlib (void *q) // { dg-message "'#include '" "" { target *-*-* } .-1 } q = realloc (q, 1024); // { dg-error "was not declared" } // { dg-message "'#include '" "" { target *-*-* } .-1 } + q = calloc (8, 8); // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + + void callback (); + atexit (callback); // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + int i; + i = EXIT_SUCCESS; // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + i = EXIT_FAILURE; // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + exit (i); // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + abort (); // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } + + getenv ("foo"); // { dg-error "was not declared" } + // { dg-message "'#include '" "" { target *-*-* } .-1 } } /* Verify that we don't offer suggestions to stdlib globals names when diff --git a/gcc/testsuite/gcc.dg/spellcheck-stdlib.c b/gcc/testsuite/gcc.dg/spellcheck-stdlib.c index 1ae3b5e33ab..7297a92368f 100644 --- a/gcc/testsuite/gcc.dg/spellcheck-stdlib.c +++ b/gcc/testsuite/gcc.dg/spellcheck-stdlib.c @@ -38,6 +38,16 @@ void test_stdio_h (void) /* { dg-message "'EOF' is defined in header ''; did you forget to '#include '?" "" { target *-*-* } .-1 } */ } +/* Missing . */ + +void test_stdlib (int i) +{ + i = EXIT_SUCCESS; /* { dg-error "'EXIT_SUCCESS' undeclared" } */ + /* { dg-message "'EXIT_SUCCESS' is defined in header ''; did you forget to '#include '?" "" { target *-*-* } .-1 } */ + i = EXIT_FAILURE; /* { dg-error "'EXIT_FAILURE' undeclared" } */ + /* { dg-message "'EXIT_FAILURE' is defined in header ''; did you forget to '#include '?" "" { target *-*-* } .-1 } */ +} + /* Missing . */ int test_errno_h (void)