From patchwork Thu Sep 1 19:12:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 905 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp390946wro; Thu, 1 Sep 2022 12:12:59 -0700 (PDT) X-Google-Smtp-Source: AA6agR4Qm7LT1uHcYb36d0BCEqLsGVTfpax7VQRnt05LDvn9+7Q2AaqPLhXaicncCVfQlD/ITrEq X-Received: by 2002:a17:906:8cb0:b0:730:d6f3:279e with SMTP id qr48-20020a1709068cb000b00730d6f3279emr26258206ejc.25.1662059578907; Thu, 01 Sep 2022 12:12:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662059578; cv=none; d=google.com; s=arc-20160816; b=M6bxH+YG2TT5rJn9gSQ9VjBumKOiCPPVR3/Q1E6LrCmIQ7+VkFUDDj+cxx/AgpQdQt UJKxQcVg2NPdh9CK7/juh1aJ5CNeScw66gk+bF1gZuJoekClnrvSTLElbKa07GcPdWl1 +8VviHwJVKr7l5Vfl3A1bDet2mxvw49M3VbrhERkf32m3fMBo0BsDYUY+QVWEp7BgPj0 d7ouB5eRaH6QU9uU6nirEeDGtWEXm2YbdNZw50bjnNTKbJlEaJ0wR7P1M4c3OCI4BYic g/8XEWhSCPvCK1N6qyL+0cldZe2uioFxOUo/0kWbfwV6/U9yN5sVro4XYtMlZY1m1Foo Eyjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :message-id:subject:to:from:date:ironport-sdr:dmarc-filter :delivered-to; bh=7tUWy/sm0R8Z1jm9e3IKh3K+/V2Ur2BHSLODuqIYboI=; b=NaugzgGhkyfgFJuXaAP2vBrQZD5Nwxd4zz+WYMKr+e63AHKOdQ8UNYL4gDgXto/NaS G9wLaidsUgnMBH+MxJB8x9cR+OzVM87l53d1Bfa67Gr78vswXMsTBiGM8p1EokrEYpVn cFCbucUyxjDu0QhFHLrGKolln+XcXu8A0zi1QNKOSlgreEMcioPh7u4FQcocgAG0Zsm/ 1az5k7ZWpGVRZ3oOCJftdiOhcTESX/Iob9gAS4mlQOi/Y0S17Xk1sc9+vxJQQLga6xl0 giCtpGps0Vabdil8b2GSo4f4FBtVhq59g8jb7OpihpC3q+caFjvC4Yolf5gQxKMXmLL+ WxaA== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id eb13-20020a0564020d0d00b004487e66b7d3si2746234edb.175.2022.09.01.12.12.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 12:12:58 -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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 35BFE3858297 for ; Thu, 1 Sep 2022 19:12:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 302433858D3C for ; Thu, 1 Sep 2022 19:12:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 302433858D3C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.93,281,1654588800"; d="scan'208";a="82199134" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa3.mentor.iphmx.com with ESMTP; 01 Sep 2022 11:12:25 -0800 IronPort-SDR: S4g7AK09q9U/v4/8lbkJhJjVz4D+XsehVck/FQtx7uDMgGoHe8fRe/Nl5Nlfhp8gNIBHudQMaF krd2p3Fje2VCNx/33BKZjJxSs1xuM00xaEpoV3bEGO4/32RWWQAiAtRJcpmmE1t08Fo9yeEhyK EXQXh/UBoErGSaZ0+61p56ei8PvVG1mj6fgHyLsQEWZ4JwiLLd1K7HeMvhEKWhu2P3uYZHhlPE od6YwCoFkbg6JUb+Osxt59ONKxZGmgeLHvRiDfkqAR3+YKzhjJzPtc9lZn8BAaxWfEhQfKGe9f SOs= Date: Thu, 1 Sep 2022 19:12:19 +0000 From: Joseph Myers X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: [committed] c: C2x removal of unprototyped functions Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-15.mgc.mentorg.com (139.181.222.15) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-3117.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, 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: , 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?1742795785127744227?= X-GMAIL-MSGID: =?utf-8?q?1742795785127744227?= C2x has completely removed unprototyped functions, so that () now means the same as (void) in both function declarations and definitions, where previously that change had been made for definitions only. Implement this accordingly. This is a change where GNU/Linux distribution builders might wish to try builds with a -std=gnu2x default to start early on getting old code fixed that still has () declarations for functions taking arguments, in advance of GCC moving to -std=gnu2x as default maybe in GCC 14 or 15; I don't know how much such code is likely to be in current use. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc/c/ * c-decl.cc (grokparms): Handle () in a function declaration the same as (void) for C2X. gcc/testsuite/ * gcc.dg/c11-unproto-3.c, gcc.dg/c2x-unproto-3.c, gcc.dg/c2x-unproto-4.c: New tests. * gcc.dg/c2x-old-style-definition-6.c, gcc.dg/c2x-unproto-1.c, gcc.dg/c2x-unproto-2.c: Update for removal of unprototyped functions. diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 804314dd0f2..34f8feda897 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -7868,7 +7868,7 @@ grokparms (struct c_arg_info *arg_info, bool funcdef_flag) error ("%<[*]%> not allowed in other than function prototype scope"); } - if (arg_types == NULL_TREE && !funcdef_flag + if (arg_types == NULL_TREE && !funcdef_flag && !flag_isoc2x && !in_system_header_at (input_location)) warning (OPT_Wstrict_prototypes, "function declaration isn%'t a prototype"); @@ -7896,9 +7896,8 @@ grokparms (struct c_arg_info *arg_info, bool funcdef_flag) tree parm, type, typelt; unsigned int parmno; - /* In C2X, convert () in a function definition to (void). */ + /* In C2X, convert () to (void). */ if (flag_isoc2x - && funcdef_flag && !arg_types && !arg_info->parms) arg_types = arg_info->types = void_list_node; diff --git a/gcc/testsuite/gcc.dg/c11-unproto-3.c b/gcc/testsuite/gcc.dg/c11-unproto-3.c new file mode 100644 index 00000000000..b0e4bf3d5b1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c11-unproto-3.c @@ -0,0 +1,19 @@ +/* Test function declarations without prototypes for C11. */ +/* { dg-do compile } */ +/* { dg-options "-std=c11 -pedantic-errors" } */ + +void f1 (); +void +f1a (void) +{ + f1 (1, 2); +} + +void f2 (); +void f2 (int); + +void f3 (); + +_Static_assert (_Generic (f3, + void (*) (int) : 1, + default : 3) == 1, "unprototyped test"); diff --git a/gcc/testsuite/gcc.dg/c2x-old-style-definition-6.c b/gcc/testsuite/gcc.dg/c2x-old-style-definition-6.c index fc0e778446d..72bfd56f00a 100644 --- a/gcc/testsuite/gcc.dg/c2x-old-style-definition-6.c +++ b/gcc/testsuite/gcc.dg/c2x-old-style-definition-6.c @@ -1,16 +1,16 @@ -/* Test old-style function definitions not in C2x: () does not give - type with a prototype except for function definitions. */ +/* Test old-style function definitions not in C2x: () gives a type with + a prototype for all declarations. */ /* { dg-do compile } */ /* { dg-options "-std=c2x" } */ -void f1 (); +void f1 (); /* { dg-message "declared here" } */ -/* Prototyped function returning a pointer to unprototyped function. */ +/* Prototyped function returning a pointer to a function with no arguments. */ void (*f2 (void))() { return f1; } void g (void) { - f1 (1); - f2 () (1); + f1 (1); /* { dg-error "too many arguments" } */ + f2 () (1); /* { dg-error "too many arguments" } */ } diff --git a/gcc/testsuite/gcc.dg/c2x-unproto-1.c b/gcc/testsuite/gcc.dg/c2x-unproto-1.c index aa87d78610e..d21c6a712fb 100644 --- a/gcc/testsuite/gcc.dg/c2x-unproto-1.c +++ b/gcc/testsuite/gcc.dg/c2x-unproto-1.c @@ -1,25 +1,21 @@ -/* Test compatibility of unprototyped and prototyped function types (C2x made - the case of types affected by default argument promotions compatible, before - removing unprototyped functions completely). Test affected usages are not - accepted for C2x. */ +/* Test compatibility of prototyped function types with and without arguments + (C2x made the case of types affected by default argument promotions + compatible, before removing unprototyped functions completely). Test + affected usages are not accepted for C2x. */ /* { dg-do compile } */ /* { dg-options "-std=c2x -pedantic-errors" } */ void f1 (); /* { dg-message "previous declaration" } */ void f1 (float); /* { dg-error "conflicting types" } */ -/* { dg-message "default promotion" "" { target *-*-* } .-1 } */ void f2 (float); /* { dg-message "previous declaration" } */ void f2 (); /* { dg-error "conflicting types" } */ -/* { dg-message "default promotion" "" { target *-*-* } .-1 } */ void f3 (); /* { dg-message "previous declaration" } */ void f3 (char); /* { dg-error "conflicting types" } */ -/* { dg-message "default promotion" "" { target *-*-* } .-1 } */ void f4 (char); /* { dg-message "previous declaration" } */ void f4 (); /* { dg-error "conflicting types" } */ -/* { dg-message "default promotion" "" { target *-*-* } .-1 } */ /* Built-in function case. */ float sqrtf (); /* { dg-warning "conflicting types for built-in function" } */ diff --git a/gcc/testsuite/gcc.dg/c2x-unproto-2.c b/gcc/testsuite/gcc.dg/c2x-unproto-2.c index 3d5ae9d8460..533fb743b4e 100644 --- a/gcc/testsuite/gcc.dg/c2x-unproto-2.c +++ b/gcc/testsuite/gcc.dg/c2x-unproto-2.c @@ -1,22 +1,18 @@ -/* Test compatibility of unprototyped and prototyped function types (C2x made - the case of types affected by default argument promotions compatible, before - removing unprototyped functions completely). Test always-invalid-in-C2x - usages, in C2X mode. */ +/* Test compatibility of prototyped function types without arguments and with + variable arguments (C2x made the case of types affected by default argument + promotions compatible, before removing unprototyped functions completely). + Test always-invalid-in-C2x usages, in C2X mode. */ /* { dg-do compile } */ /* { dg-options "-std=c2x -pedantic-errors" } */ void f1 (); /* { dg-message "previous declaration" } */ void f1 (int, ...); /* { dg-error "conflicting types" } */ -/* { dg-message "ellipsis" "" { target *-*-* } .-1 } */ void f2 (int, ...); /* { dg-message "previous declaration" } */ void f2 (); /* { dg-error "conflicting types" } */ -/* { dg-message "ellipsis" "" { target *-*-* } .-1 } */ void f3 (); /* { dg-message "previous declaration" } */ void f3 (char, ...); /* { dg-error "conflicting types" } */ -/* { dg-message "ellipsis" "" { target *-*-* } .-1 } */ void f4 (char, ...); /* { dg-message "previous declaration" } */ void f4 (); /* { dg-error "conflicting types" } */ -/* { dg-message "ellipsis" "" { target *-*-* } .-1 } */ diff --git a/gcc/testsuite/gcc.dg/c2x-unproto-3.c b/gcc/testsuite/gcc.dg/c2x-unproto-3.c new file mode 100644 index 00000000000..762f8b21034 --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-unproto-3.c @@ -0,0 +1,20 @@ +/* Test that declaring a function with () is the same as (void) in C2X. Valid + use cases. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic-errors -Wstrict-prototypes" } */ + +void f1 (); +void f1 (void); + +void f2 (void); +void f2 (); + +typedef void T1 (); +typedef void T1 (void); + +void f3 (); + +_Static_assert (_Generic (f3, + void (*) (int) : 1, + void (*) (void) : 2, + default : 3) == 2); diff --git a/gcc/testsuite/gcc.dg/c2x-unproto-4.c b/gcc/testsuite/gcc.dg/c2x-unproto-4.c new file mode 100644 index 00000000000..fceff22b1af --- /dev/null +++ b/gcc/testsuite/gcc.dg/c2x-unproto-4.c @@ -0,0 +1,15 @@ +/* Test that declaring a function with () is the same as (void) in C2X. + Invalid use cases. */ +/* { dg-do compile } */ +/* { dg-options "-std=c2x -pedantic-errors" } */ + +void f1 (); /* { dg-message "previous declaration" } */ +void f1 (int); /* { dg-error "conflicting types" } */ + +void f2 (); /* { dg-message "declared here" } */ + +void +f3 (void) +{ + f2 (1); /* { dg-error "too many arguments" } */ +}