From patchwork Thu Feb 24 04:20:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 51362 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F004A3857C5D for ; Thu, 24 Feb 2022 04:20:42 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 6C09F385841F for ; Thu, 24 Feb 2022 04:20:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6C09F385841F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21NNx3ZA022538; Thu, 24 Feb 2022 04:20:24 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : references : content-type : mime-version; s=corp-2021-07-09; bh=cB81y+jA/3FGLVWHPsewP4r/Pe04zvsMR7vOM8/HfRs=; b=0QKvLDO3mKDTUCqI9RlPXH5U8hJFi0rlwBt53vu5kidsltBCyGJqtADC/8kCSsWa50+q iHW+UIr5TYJyKMSbQevzpDKLeOCVSRK07Rx6XFocK07vFoDETGn1lTayTAIqHj4v3/1y g6IUo9QldVZDs508CbXXK7yibiJ1gPg+0dJN2JpXbaNZJRNSdmcvN1nDTJAm8BVVPAiP y22NAYRwfFc4wdilJ6u2C31csOuYw9zy+aQ1+NARPDMvsWt75lU7vwEJzti6R+5j1Gtd yZbgMIdhX+x/OCH5uT9hlmUMMrqwy170AYT1y8OptfVk94VL3PIKUdzrRwt0ZpN9nO2R SQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by mx0b-00069f02.pphosted.com with ESMTP id 3ecv6ex2vk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Feb 2022 04:20:23 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 21O41211169040; Thu, 24 Feb 2022 04:20:22 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2169.outbound.protection.outlook.com [104.47.57.169]) by userp3020.oracle.com with ESMTP id 3eat0qaf07-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Feb 2022 04:20:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P3+FZ0AogWs0TCUsE/DJPWK3InrlmafjlBGDac+cF3XJn8QMDXx5VeiJ5bBOJdCj82TqyInvXZd03PSpXALpQeSyKHRiNtCjxovc539ApMHdME38amvbET8FL1cfCYZqpA38FxgDK+z6UjxPiuLCu5Sz4eersGNsHlH6kleXdC5UMD5vFhNW6NQiNldvoPmrbFeiN2mJVVPJ3gZte5Tnkktgy5sobDtG19mDTzLx2OEEJj60JS+nw9GOFgqiFzMCnbHLSNZWtJbxHviXXzy4Y+kk6dGFAWzNvtvSMSEticZ8/X46JBBaDewzmPUWvmFdYEPYkgRpl6krxRsddBr4iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cB81y+jA/3FGLVWHPsewP4r/Pe04zvsMR7vOM8/HfRs=; b=Ea39uhNgrxuHUZoBo/DoZONjZFTv8AHJ9fP0aTf06shd6ZCMNbZvjtqdDoo/OKNpEeBeSrdRhuWFf336IhzY5eb7NI+pTaAUa+Liz1RhpSoi3dj50F5LeFuyMzJq1CcCCGFIylN/1JHJEDB/w+a+89kN1aFNBGKdBUVU1TtEM245exCtoo4ZLg0T3uqwcc9W0wUzct6jjxn1d03SO7obGj9WbZvsC0BPG2Onqif2nVEjDqPf64O9/gKJk9xdrmMhMosJR7qDzyV0afrZMfhVdklNxEF9wdof/0qG20SYr/ABIKg3S3u6mgXd2z2pB9PVma10XgXMYuLaIW0HjOlVRQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cB81y+jA/3FGLVWHPsewP4r/Pe04zvsMR7vOM8/HfRs=; b=I0nyzfl5PVX+r4O1m4CSBUdMSWlpQld1uS19dmriqZSLA62yfzqMBnnfkQP9tJHfZGOxu4zr/yMZuiDQYtvqSGlc6z62Af+aU6cGf2Ebh+R7VakUJnXd034ItTWcxdUDru1swRmm1SSrCcLO0Rvw77GE8NmayOBVTGcZwTICk3o= Received: from CH2PR10MB4344.namprd10.prod.outlook.com (2603:10b6:610:af::19) by BN6PR1001MB2084.namprd10.prod.outlook.com (2603:10b6:405:2d::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.26; Thu, 24 Feb 2022 04:20:19 +0000 Received: from CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::50e0:10b6:4c07:3728]) by CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::50e0:10b6:4c07:3728%8]) with mapi id 15.20.5017.021; Thu, 24 Feb 2022 04:20:19 +0000 From: Qing Zhao To: Richard Biener , Jakub Jelinek Subject: Fwd: [PATCH 1/2][middle-end/102276] Don't emit switch-unreachable warnings for -ftrivial-auto-var-init (PR102276) Thread-Topic: [PATCH 1/2][middle-end/102276] Don't emit switch-unreachable warnings for -ftrivial-auto-var-init (PR102276) Thread-Index: AQHYJazsBkeXMVtZnUe06Nzu137Xcg== Date: Thu, 24 Feb 2022 04:20:19 +0000 Message-ID: References: <4BFFFF31-FDD2-4145-BC6F-B7CBB925B1DB@oracle.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3608.120.23.2.7) x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 6f43a162-de17-435f-a64f-08d9f74cf7a9 x-ms-traffictypediagnostic: BN6PR1001MB2084:EE_ x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 5JMgmPTHrcKWZ4Irj1KodK/xmD2Q82rZvAf+K93aa2gdrbde+w+u8qh/ye0Uy1kuivnXgV+rcErFxOQv9iITy4nXgNNAGzR912eZyn3/qVwd8ktZJfm1AMrlpS8LnHp/mV7jOCcRN98i5U2gtrikGprXnOzKU733VY3WaCGNCqnsqKX+2Eu2ed6AGby+Ht4QqBL+vOZ/0tx4HFjgiJdzC6BrGzsUB31m8WEb38Y0oFBXrjjiEYmo8htrY1kV7cI01qDwTLJPcJo/oQM0jG9+DJCnncF9Wj5L5SI+47psT9iyb7TknNFneNXzg4VI3EZlWhcB62eRi2XJFyBv5hBUWmFzIiCt13nCbw4u7A8RzqyB77UXpmrzhZoTxnrGnb0u6XOaHv6/667CTutPH/ISITZk0WN5jbbkgggKbLkSxoewZjSEAVAvF9JKoJUD1JrQBbGVZivZMJiaWX5Oot5B81fl9JUNPH1vbKN+ksmjCaD3DSe5PmvlMYwjsebnQ8BZ83pMgANGYMo4W1BzK3CcAN27N8mLI7/QBwDexbvwTSqIrlDtfTN1ZKixpDl/N7F2eVcdlYtwlvBz1OYXHucp5fv+qM0tQqMPdi5OYZJHyZUhYiwlNRYBN7IzBko3LbD9YoZ5eEW+vIm/UBtvgyO/2rmTY21jZGnxdaTfiBhrgbbARDlP0qIL62ZUSsg3Y26idpBj3edsdCCcvOF5Q+OjLDdC3iUzFBgCTCmuJeM3v7PST6mDF+kqEJk2tqYU9K5I/MOSkB0uYrEOGo02yxc0LYgZb8haTdLg3dniTWXfjgntr2hQbYhvjmcF4Takt4HvgTgW8ztm6wf11afHDa2DQxSuisk0PYFIrATHx8GvODY= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4344.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(316002)(110136005)(8936002)(4326008)(508600001)(83380400001)(86362001)(33656002)(966005)(186003)(5660300002)(38070700005)(36756003)(44832011)(6486002)(6512007)(2616005)(91956017)(166002)(2906002)(8676002)(66476007)(66446008)(64756008)(66946007)(76116006)(53546011)(66556008)(122000001)(84970400001)(6506007)(38100700002)(71200400001)(45980500001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: R2uYxyjj43fNbmNr7X/405PkVh+Ib06b04r6ZXNRCNcYdZeMzYotfvajXIfjautYgr0vfZ+jOZ7swYBeVyR6U7i7xrj/Q+OcxUxi9CQFFQAYpnYT2mSqcaS/KjgC8M1cHRmtBrV6cnmXcTK0ZOwS8kvgS2X05cN/vy1E8/ZkAsr0de2b9SVx5nW2X192Om2pkEhXNDkKJwRXWACMgec5MpG6pe48eVKsDdpIcVvOgE2MekeG6pkio+X70YUD8rUxeSiDftgtrMXuoyDrcLsP1EFNZW/I2EWEP4MfXOFJn5D9CXmlqeMNJ8GaVjdh4eRwjK6RnkTlO6xLNJ5DKhrXSziRavuWgUEhhy0NTSvIpcdqg9jwEWo68zEM+xKgAJS71kEcBSHNd6BT/iuAWz9Zsu2D4fJ9vtmpoUdWcmE/MPZ/TTiliDGrhtAAcP7/83nBFr64DHKVsTG8Tq/A5hsFiJrd7aEIgeKSEyUPgACiCLxsQ4HgNp9c01Oo9GlwvjwxPvIeqs+6ydymZLAgc+pWEmqgZL5BgdTHasJfxReQTcnaVz3vzcp0IONFixm2wRPhm488WdRK/J4bGapJ9cpP+DIx2BV3jK4nTHkaTd3Ur+35hAqmOuJbjFgdYRAdbAKKtJTldMNdr+DYA2e1kJrg8PsxO4ouRBcE6uK6gejIkiTfJsxKTj3hCTOhvmpoK0/NDGmkXcjdWkZkhwpue38URv5h7Bu3zG7OxEzkDCuncuj/NA8Tj22s4oH/HlLMZsuMhq142NZhsofaV7f5xIYxsPb6I1S5DAuSoanda/2IGC46vwEjIQUbQXsEyxq8726toYtHruwnBU6cZ/vIlOtB7HpgtjASh0dMSRoZ7ncsCFaSoM1cWYteNJEU7OJW/w9XnJ8Bdg+pkDJWUuxPAieX4aspMCuWk1ACi+1/TBghrqxbB11mhO1rLmZlPDbk31L5Ig6LxYtPUS594tAM615PmieJneijRFYGxGdD19qpjz/VQ8XxJpOAaqMQ52W63sMMI7YVBYI9nRpG9ZvcGGgkgj75JjtN/g3uqz/veJAMLnWtJy5UNogT6sa6W1vxUFIfHosInYRS0uxj6hiTeSX+PH3ObrDCWuxp8faIKk7toqDhGs3axwiPRRe+WukWYv1bhNQqcWXtRcnGdfjJCoHH2cMbAf1/wzI+J21lz/4TEwyf+uY9TO922oYN8MFwVlodwah31P4g8utFJPS6cxb/cxR7k/aDZjfYdgBLqcbdHZ4SntFz3QZYfjH1AfSgXy/CHWNpBxBCvhHG73yBTNmptKwdKpk1EGgxXEh6Cwtef0rju2QjfuZtSr2QJ42fYxkKudRQOBbPvIyiq9/swoDywuUtoJ9NK16BJ39i1oUIBGcxa4C6u0e4XatQ4+9mSlGfif5b8OakDImZzgvcbg7ClXZFKtEw6Y29ISTc4utDkNMyr73rYmQf6RvBmpnZSVcyMknJleylmsyKcdiZdKupWAATlr3m/2yQmHHg8FkkOLwKZbNOadXRW8TmADromoT8vSn4BGreywFZIAg8jjrbARexLAoxb5GUKvu1rKij4cyPehMRGTg/Ylxh0VtwmgVyEUwzHwNKEakd9HvJakTnzANY+U8sNBNz47YWZ7E9rdytKKNjTKxr3Q1R8z+geOPkuNk4YmYve17fwrUxsegQlA== MIME-Version: 1.0 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4344.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6f43a162-de17-435f-a64f-08d9f74cf7a9 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Feb 2022 04:20:19.3519 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: oNm1aJdVXCE7QeCMXe5BpQhhW3nUNZdNVHJNJ8t0rfPJkDkyk1x5nIk9+zrYbqAfSp0H9UBt+g2nIwMEjJ3mnw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1001MB2084 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10267 signatures=681306 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 adultscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202240021 X-Proofpoint-GUID: bvG2niRwf2jTO592ycjlzp0E1YfjbPnb X-Proofpoint-ORIG-GUID: bvG2niRwf2jTO592ycjlzp0E1YfjbPnb X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, KAM_SHORT, RCVD_IN_DNSWL_LOW, 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: , Cc: gcc-patches Paul A Clarke via Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Ping. Qing Begin forwarded message: From: Qing Zhao via Gcc-patches > Subject: [PATCH 1/2][middle-end/102276] Don't emit switch-unreachable warnings for -ftrivial-auto-var-init (PR102276) Date: February 19, 2022 at 10:22:43 AM CST To: richard Biener >, jakub Jelinek > Cc: gcc-patches Paul A Clarke via >, kees Cook > Reply-To: Qing Zhao > Hi, Per our discussion in the bug report https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102276 We decided to go with the following solution: 1. avoid emitting switch-unreachable warnings for -ftrivial-auto-var-init; 2. adding a new option -Wtrivial-auto-var-init to emit warnings for the switch-unreadable cases to suggest the user modify the source code; 3. update documentation of -ftrivial-auto-var-init for the limitation on switch-unreachable cases and introduce the new option -Wtrivial-auto-var-init with the above 1, we can resolve the current immediate issue of spurious warnings of using -ftrivial-auto-var-init to make kernel build succeed; with the above 2, we provide the user a way to know that -ftrivial-auto-var-init has limitation on the switch-unreachable cases, and user should modify the source code to avoid this problem; with the above 3, we will provide the user a clear documentation of the -ftrivial-auto-var-init and also provide suggestions how to resolve this issue. There are two patches included for this bug. This is the first one. The patches has been bootstrapped and regression tested on both x86 and aarch64. Okay for commit? Thanks. Qing. =========================== From 65bc9607ff35ad49e5501ec5c392293c5b6358d0 Mon Sep 17 00:00:00 2001 From: Qing Zhao > Date: Fri, 18 Feb 2022 15:35:53 +0000 Subject: [PATCH 1/2] Don't emit switch-unreachable warnings for -ftrivial-auto-var-init (PR102276) for the following testing case: 1 int g(int *); 2 int f1() 3 { 4 switch (0) { 5 int x; 6 default: 7 return g(&x); 8 } 9 } compiling with -O -ftrivial-auto-var-init causes spurious warning: warning: statement will never be executed [-Wswitch-unreachable] 5 | int x; | ^ This is due to the compiler-generated initialization at the point of the declaration. We could avoid the warning by adjusting the routine "maybe_warn_switch_unreachable" to exclude the following cases: when flag_auto_var_init > AUTO_INIT_UNINITIALIZED And call to .DEFERRED_INIT 2022-02-18 Qing Zhao > gcc/ChangeLog: * gimplify.cc (maybe_warn_switch_unreachable): Don't warn for compiler -generated initializations for -ftrivial-auto-var-init. gcc/testsuite/ChangeLog: * gcc.dg/auto-init-pr102276-1.c: New test. * gcc.dg/auto-init-pr102276-2.c: New test. --- gcc/gimplify.cc | 8 ++++- gcc/testsuite/gcc.dg/auto-init-pr102276-1.c | 38 +++++++++++++++++++++ gcc/testsuite/gcc.dg/auto-init-pr102276-2.c | 38 +++++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/auto-init-pr102276-1.c create mode 100644 gcc/testsuite/gcc.dg/auto-init-pr102276-2.c -- 2.27.0 diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index f570daa015a..4e3bbf5314d 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -2103,7 +2103,13 @@ maybe_warn_switch_unreachable (gimple_seq seq) && TREE_CODE (gimple_goto_dest (stmt)) == LABEL_DECL && DECL_ARTIFICIAL (gimple_goto_dest (stmt))) /* Don't warn for compiler-generated gotos. These occur - in Duff's devices, for example. */; + in Duff's devices, for example. */ + ; + else if ((flag_auto_var_init > AUTO_INIT_UNINITIALIZED) + && (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))) + /* Don't warn for compiler-generated initializations for + -ftrivial-auto-var-init. */ + ; else warning_at (gimple_location (stmt), OPT_Wswitch_unreachable, "statement will never be executed"); diff --git a/gcc/testsuite/gcc.dg/auto-init-pr102276-1.c b/gcc/testsuite/gcc.dg/auto-init-pr102276-1.c new file mode 100644 index 00000000000..d574926e0c8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/auto-init-pr102276-1.c @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wall -ftrivial-auto-var-init=zero" } */ + +int g(int *); +int f() +{ + switch (0) { + int x; /* { dg-bogus "statement will never be executed" } */ + default: + return g(&x); + } +} + +int g1(int); +int f1() +{ + switch (0) { + int x; /* { dg-bogus "statement will never be executed" } */ + default: + return g1(x); /* { dg-warning "is used uninitialized" } */ + } +} + +struct S +{ + char a; + int b; +}; +int g2(int); +int f2(int input) +{ + switch (0) { + struct S x; /* { dg-bogus "statement will never be executed" } */ + default: + return g2(input) + x.b; /* { dg-warning "is used uninitialized" } */ + } +} + diff --git a/gcc/testsuite/gcc.dg/auto-init-pr102276-2.c b/gcc/testsuite/gcc.dg/auto-init-pr102276-2.c new file mode 100644 index 00000000000..779d3ec3882 --- /dev/null +++ b/gcc/testsuite/gcc.dg/auto-init-pr102276-2.c @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wall -ftrivial-auto-var-init=pattern" } */ + +int g(int *); +int f() +{ + switch (0) { + int x; /* { dg-bogus "statement will never be executed" } */ + default: + return g(&x); + } +} + +int g1(int); +int f1() +{ + switch (0) { + int x; /* { dg-bogus "statement will never be executed" } */ + default: + return g1(x); /* { dg-warning "is used uninitialized" } */ + } +} + +struct S +{ + char a; + int b; +}; +int g2(int); +int f2(int input) +{ + switch (0) { + struct S x; /* { dg-bogus "statement will never be executed" } */ + default: + return g2(input) + x.b; /* { dg-warning "is used uninitialized" } */ + } +} + From patchwork Thu Feb 24 04:20:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 51363 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4578B3857C43 for ; Thu, 24 Feb 2022 04:21:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id C1355385800E for ; Thu, 24 Feb 2022 04:20:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C1355385800E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21NNwpON017788; Thu, 24 Feb 2022 04:20:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : references : content-type : mime-version; s=corp-2021-07-09; bh=dB3mcn9uFgfgZOsKMVNw2LR+9uUznykZq8zJDr52hDU=; b=DpbiQSh+cUmog5+mssxudtQjFiA8qZkkiqROcWJCdEn0P8bUO1T4xLgkkHWe0BWkt5Oa nBR8bwvZP2gkmvFIFvmO0G1af8OKOBimGaW8HE59I/u3tLbQ9BzfSxXbS+MK34Sp3qRk dEf6YYyMWUt4jqQyH/zj3iU+oxUod7rK0ni5iXHxt4AmtRdqQbEuc2oXlwbGlIC5CeIv M9txANoqjt1g/gT3GNB9n6P8Op4iJibxiZiotaff1UQS5nJteCobs+IVM+2JwmuC1B+J HpA4wJdvJV8tYNXLucU63a2whsZmOeKIuogTXq8juujSZaJFmDY8+5J8pNdnole2ECLT rQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3ectsx68pk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Feb 2022 04:20:58 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.1.2/8.16.1.2) with SMTP id 21O41eJ6083130; Thu, 24 Feb 2022 04:20:57 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2174.outbound.protection.outlook.com [104.47.55.174]) by userp3030.oracle.com with ESMTP id 3eannwtntg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 24 Feb 2022 04:20:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LB0+VqNM4+eL/Ocndm84LZWKy2R9hZLex2P/H5HXLHeNcJVnnNm40ICldPdh5qy4NKPhX9pRAw3qKwVrqtL7AE48ml+i659TpnBM3xKylYFlSiIt2Xwqom8cCVXtjW3ri7eOWPk/YH9C83g+80JvBv3S6cey1Olb30z5P7egUS3M8yJoRPhGBeJmMMUBrJKVLtDOL1Pdlo/0CvEDJvtrh+XRmJ7Roy+kvBrfJG2EOgRqg1gY+jBcciPPGqU69SAezPpJKzvhWr+Kx4Qi7ijQjULjLXu9we2cb86KZlGG3QN1KLFMNSl2D7DVq3kuxe8LYp+D2oQpBLVGK78x1LOXKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dB3mcn9uFgfgZOsKMVNw2LR+9uUznykZq8zJDr52hDU=; b=VfIJy3MteIajA5hHJMhsvFoKRHKYLU5VmWHXWrvmvy1C5YXavbCtEzN4ZBcsHzm9uEpFtxmNC84Pig+oftQBmVJUqaABp7QY+zAj8pbUAlHVdKFXs1nkEqWprJ7s0vWgtY9omMnxvaSELjxJAdHLLDK3F+u93cqx750a86KZeyd1p1tsa+orl6wtgi6wV3Lt6a0q4WS8qDUAqlHDZuqqEZ/QabZN5Q68wlL4oMe3cD5GTCb94nnjKNysiAeJv0nNXayXiHVh/lLpkbRmqbWRIJvn3ZrXNaULmaC5dZ1OTYOZp9tmZ50+Brf3InoR4RvDMY8/WXjJNacBS3BeOKZW3w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dB3mcn9uFgfgZOsKMVNw2LR+9uUznykZq8zJDr52hDU=; b=n5vu+AD77MpSAy7bPJJfFtDTg1jQ6BWjJaFXKBBhYAoe4yvVpMME/s5XcJs2/5AVqQU1g9O10atUB6vry2KptK3u8cup2B+pJDpXieIzstOgdp8yW6i5PTGz3CLsx0XvM5bVe2tZ/wjRKE365LXxFIBnNMWhXr+OGmBJvVLghzk= Received: from CH2PR10MB4344.namprd10.prod.outlook.com (2603:10b6:610:af::19) by CY4PR10MB1719.namprd10.prod.outlook.com (2603:10b6:910:f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Thu, 24 Feb 2022 04:20:54 +0000 Received: from CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::50e0:10b6:4c07:3728]) by CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::50e0:10b6:4c07:3728%8]) with mapi id 15.20.5017.021; Thu, 24 Feb 2022 04:20:54 +0000 From: Qing Zhao To: richard Biener , Jakub Jelinek Subject: Fwd: [PATCH 2/2][middle-end/102276] Adding -Wtrivial-auto-var-init and update documentation. Thread-Topic: [PATCH 2/2][middle-end/102276] Adding -Wtrivial-auto-var-init and update documentation. Thread-Index: AQHYJa0f/qmFIJJY40SSaqrd2EbMKQ== Date: Thu, 24 Feb 2022 04:20:54 +0000 Message-ID: <4810BE44-7491-4030-9B0A-DB68CE83D4BE@oracle.com> References: <8884571B-837F-40B0-8308-F6F2D26587C9@oracle.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3608.120.23.2.7) x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ce0af76b-6c26-492e-2aeb-08d9f74d0c76 x-ms-traffictypediagnostic: CY4PR10MB1719:EE_ x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 0JB0KvIDspsb2g8/OiVzRr2uCvoyWRJWKWwHu5DYwi/RRhmBQIgZGf+5KlSEcWVrXxlKbq1/3zNTvI/7OioFmjRm59ImdbDqX7yuJMAYjRCJt0HRfHHfGl6QWY40LHq/u7BTp2jue6xo5MM3Gj7PcrD4UMVoRh6DPBv5CSITnVFVmtn5OoJU1k5TcqzulmkxhoOX2r+jRXevPLM7rJI0yNGEC/e0Ci7DpJgeA9dGjnrTlaN7FgcUagQTb2dUyM8VkVjOM9u2nIb+ZKp17gaZAUc8CZuAz83Eg6rOBGs7+NbpdZl3/mIDwIJbC8tfqzQsMrO3JXWKJ7wzeKDT+PeGqIy25mxUb1tmvunOi1m+vrZN6d731PSi2SjGn5jhKWukjofQUYl/c+zzJWnm4OZ/UIQ8c6RiDeuQqaZym40Gsx4KWZwr2xVb5vyWjN0MS9g/FE9gp6skf5T0i64o8nJaTGeqUi03HDbqG+jddtqe5pbA29aaNIp5+0KjmFv3aLjk9Y1cWf1uqr4GKONqEApBU8YrubJmJMTJ+p4Dv+m500h/YRQfHYKRMDDT/j0Ds2oP7IZ8UhpiBVyiekOAc5v8i15V7YayUHhPQpvvbMCCcevpsS6ovFT4rAuzdZeQExcpNWVAnf8wtWLi+PKEWfUfqte5OeJao2ytV1M8/hzJ5zSKCIz6ewerxA/vd1PV0W6C6gDuiO0dcS8N40OtfYUi50RUYM/m4owyZYZgw8qoLwN6uCa+c12CxZW447AD+3ToNhHJGLyje1fhkV+IvVpDOApqJDXOG8DrwfFgyL3a3dlLjv9jDOO0U55qOcg2bICGsTUfiRGC0GiLyNFih62y7hE50QEdFOUNIMtQhh6FvsC6QPzDYNecD1HUoY1nGgBr x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CH2PR10MB4344.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(209900001)(30864003)(6506007)(186003)(316002)(38100700002)(44832011)(6512007)(53546011)(33656002)(84970400001)(38070700005)(2616005)(71200400001)(122000001)(4326008)(66946007)(8676002)(91956017)(110136005)(86362001)(15650500001)(66556008)(8936002)(2906002)(166002)(5660300002)(6486002)(83380400001)(66476007)(508600001)(66446008)(76116006)(64756008)(36756003)(45980500001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: yH+EWNy4hhnuD/DGahvSGf7JBeEQibQ4zofoC0gQxmPciTpmbRgYrkmhU+QYVKP4HZeRZL6jvaZQaKkKUMhrVTCEV0xe1XBdcggKYvCG1UM5hBCiqUU46HH55DPs6JNqZHCzByYOw5k48qhdvR6yStkVoU/SLnGE4/WxaxrytgdnmZy7GJjAjLEOcMYPQ0Nsp3GOY7uhd2MwhT1GqPfsCvNzyarynp49aDdRFVlYnzNXCOTjSfgYQqBpRK95jFbQUvKAiUxqaAT1UbQZM5PpkD1lDf4Tc7htG1wcR+Ca4rkc7G4+Vxpcd7LZVBpC/xDM6V2+/YIE23ft9O18WYs34Ajmy6u5zgw7pcZesEyhRuARlVSlotRywVqP2RXExu8CEdUdoWUKhsV81N/jTf8Kua86uzw/edcK9McF+5t3Fk8/IjSE7T1Rq1jQqzhERll2i+PFs2NymOWVsy+Gibu/bQKWzxL5FhCdKvvN7/N3UQZZni8n0kAryYlDfWBi4g/1+eWcrC5ae/F8w4HgFwXJDMMCa/q7FmdmFtGoI0412p/4/Sea7hFUYcPgCpvZbLcPbGz4LLTK0UQLdNzlY8ycwbzJFar3RBTW6U/YioHSsXxxFlhZ/lp85zT2KwSrJ4fAUxYAySpQufYo+AmXNxQMCtfUHGPJjZnjeR4yWB4fWiye6UorlzHcpAD6ROsiH8nGk1Ns4/JemZw/6IWSUV8fsrg+YeywVFTBkD7KXPySWWdGt0OvP1DH8i9RzE7sashldqKdgfsRDIOu8eHEb62T2fbUeTPiixNOwmIIeOIuMtJyMSzGGNQh2m3qxB5abXWhJBXaLoJbXcbu9dKovu80X1wALzoaGgpWCstnAv2uls+wD19eBucH6L5jVGCU0XW0kOXu9zJ7ul8cnCsdHrwMaqUpBJH3yCtsGREwJTNRqqRyvywoUXgHiO/wjD5nDm21ZTIZHziLm3mIBH7fI9RH+hforhqlhlFepv39CM44LSyyFEw0CGyZHY6zAUzPq0MOR+DhC8fFe4qpJNMnmDU6gp3tldFe9oOrZnr+n8jKQzgYw/UcfDfLnNnX/2pH9P6xr7GQxplbcPqf5aXVDiUiDY8f1nr/ymbCkiRTN2/FfqGyZehoLpZ/MDQfIUXy0g+uBVFqruOUnXGkP1o7zX51V1iknReq561Cu4V3FX4mNBS4FqPgv4eg+SjkMZYRCTaPn1FQxuwf/2/zUaW5SGHLQ514RC5AQV5rUi/afi/K6FnVVdu7koKVRMBYy4ZfFyFqut0Sg8H+QFCTC4HjSTKBUDD7D2S7RzVo+k4khdhBBuEZgT9tgqJaHhtGNEsRTiheKUl/YIOT0KQGnPgCkBhSg1mBLDd33qGm/JdtD2HHMZqVRFC0a47RC+BeDHv7CfB4F6PFfDn3G3M4hKw/fIDkiRKNoaAnQ2QKnz54as3IJRaKD0RiEbGWI8EgdBBcKg+0xDCrgpITOhAE9FujpL522mCbatOQl1+0rVmSl2BKXkup+ThXJe1EKjPRt31+frsc7pyZfsuODEfTYHPoWPbDoBdSIZ7ZpnEWDsYs/gKMKbDC6E+zuDGROZFq1vQziwbsEDbPllTcROcgcI4YO3IFw0IK1oGmC8ViehPK90/YqlKnXoIDwS05eU1wpDQMQ159FuEP92mDtj8zWn2Gd7qkwg== MIME-Version: 1.0 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CH2PR10MB4344.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce0af76b-6c26-492e-2aeb-08d9f74d0c76 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Feb 2022 04:20:54.2624 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: WEh7qns/5VoSc+PcWYdjZs0xWB08PypHNfGwbUtB0CDppt9nhFkvZTWeHzQOOGORTT7HyWL4RN/OTI8JbeAlug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR10MB1719 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10267 signatures=681306 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 adultscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202240021 X-Proofpoint-ORIG-GUID: i6Foqkqqb2AxXmOiHjLyaI-x3ef9QSPK X-Proofpoint-GUID: i6Foqkqqb2AxXmOiHjLyaI-x3ef9QSPK X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HTML_MESSAGE, KAM_INFOUSMEBIZ, RCVD_IN_DNSWL_LOW, 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-Content-Filtered-By: Mailman/MimeDel 2.1.29 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: , Cc: gcc-patches Paul A Clarke via Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Ping... Qing Begin forwarded message: From: Qing Zhao via Gcc-patches > Subject: [PATCH 2/2][middle-end/102276] Adding -Wtrivial-auto-var-init and update documentation. Date: February 19, 2022 at 10:24:09 AM CST To: richard Biener >, Jakub Jelinek > Cc: gcc-patches Paul A Clarke via >, kees Cook > Reply-To: Qing Zhao > Hi, This is the 2nd patch for fixing pr102276. Adding -Wtrivial-auto-var-init and update documentation. Adding a new warning option -Wtrivial-auto-var-init to report cases when -ftrivial-auto-var-init cannot initialize the auto variable. At the same time, update documentation for -ftrivial-auto-var-init to connect it with the new warning option -Wtrivial-auto-var-init, and add documentation for -Wtrivial-auto-var-init. Bootstraped and regression tested on both x86 and aarch64. Okay for committing? thanks. Qing. ============================== From 4346890b8f4258489c4841f1992ba3ce816d7689 Mon Sep 17 00:00:00 2001 From: Qing Zhao > Date: Fri, 18 Feb 2022 15:53:15 +0000 Subject: [PATCH 2/2] Adding -Wtrivial-auto-var-init and update documentation. Adding a new warning option -Wtrivial-auto-var-init to report cases when -ftrivial-auto-var-init cannot initialize the auto variable. At the same time, update documentation for -ftrivial-auto-var-init to connect it with the new warning option -Wtrivial-auto-var-init, and add documentation for -Wtrivial-auto-var-init. 2022-02-18 Qing Zhao > gcc/ChangeLog: * common.opt (-Wtrivial-auto-var-init): New option. * doc/invoke.texi (-Wtrivial-auto-var-init): Document new option. (-ftrivial-auto-var-init): Update option; * gimplify.cc (maybe_warn_switch_unreachable): Rename... (maybe_warn_switch_unreachable_and_auto_init): ...to this. (gimplify_switch_expr): Call new function. gcc/testsuite/ChangeLog: * gcc.dg/auto-init-pr102276-3.c: New test. * gcc.dg/auto-init-pr102276-4.c: New test. --- gcc/common.opt | 4 + gcc/doc/invoke.texi | 14 ++- gcc/gimplify.cc | 100 +++++++++++++++----- gcc/testsuite/gcc.dg/auto-init-pr102276-3.c | 40 ++++++++ gcc/testsuite/gcc.dg/auto-init-pr102276-4.c | 40 ++++++++ 5 files changed, 175 insertions(+), 23 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/auto-init-pr102276-3.c create mode 100644 gcc/testsuite/gcc.dg/auto-init-pr102276-4.c -- 2.27.0 diff --git a/gcc/common.opt b/gcc/common.opt index c21e5273ae3..22c95dbfa49 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -801,6 +801,10 @@ Wtrampolines Common Var(warn_trampolines) Warning Warn whenever a trampoline is generated. +Wtrivial-auto-var-init +Common Var(warn_trivial_auto_var_init) Warning Init(0) +Warn about where -ftrivial-auto-var-init cannot initialize the auto variable. + Wtype-limits Common Var(warn_type_limits) Warning EnabledBy(Wextra) Warn if a comparison is always true or always false due to the limited range of the data type. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index e1a00c80307..c61a5b4b4a5 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -399,7 +399,7 @@ Objective-C and Objective-C++ Dialects}. -Wswitch -Wno-switch-bool -Wswitch-default -Wswitch-enum @gol -Wno-switch-outside-range -Wno-switch-unreachable -Wsync-nand @gol -Wsystem-headers -Wtautological-compare -Wtrampolines -Wtrigraphs @gol --Wtsan -Wtype-limits -Wundef @gol +-Wtrivial-auto-var-init -Wtsan -Wtype-limits -Wundef @gol -Wuninitialized -Wunknown-pragmas @gol -Wunsuffixed-float-constants -Wunused @gol -Wunused-but-set-parameter -Wunused-but-set-variable @gol @@ -6953,6 +6953,14 @@ This warning is enabled by default for C and C++ programs. Warn when @code{__sync_fetch_and_nand} and @code{__sync_nand_and_fetch} built-in functions are used. These functions changed semantics in GCC 4.4. +@item -Wtrivial-auto-var-init +@opindex Wtrivial-auto-var-init +@opindex Wno-trivial-auto-var-init +Warn when @code{-ftrivial-auto-var-init} cannot initialize the automatic +variable. A common situation is an automatic variable that is declared +between the controlling expression and the first case lable of a @code{switch} +statement. + @item -Wunused-but-set-parameter @opindex Wunused-but-set-parameter @opindex Wno-unused-but-set-parameter @@ -12314,6 +12322,10 @@ initializer as uninitialized, @option{-Wuninitialized} and warning messages on such automatic variables. With this option, GCC will also initialize any padding of automatic variables that have structure or union types to zeroes. +However, the current implementation cannot initialize automatic variables that +are declared between the controlling expression and the first case of a +@code{switch} statement. Using @option{-Wtrivial-auto-var-init} to report all +such cases. The three values of @var{choice} are: diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 4e3bbf5314d..7e52794691f 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -2079,13 +2079,59 @@ warn_switch_unreachable_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p, return NULL_TREE; } +/* Callback for walk_gimple_seq. */ + +static tree +warn_switch_unreachable_auto_init_r (gimple_stmt_iterator *gsi_p, + bool *handled_ops_p, + struct walk_stmt_info *) +{ + gimple *stmt = gsi_stmt (*gsi_p); + + *handled_ops_p = true; + switch (gimple_code (stmt)) + { + case GIMPLE_TRY: + case GIMPLE_BIND: + case GIMPLE_CATCH: + case GIMPLE_EH_FILTER: + case GIMPLE_TRANSACTION: + /* Walk the sub-statements. */ + *handled_ops_p = false; + break; + case GIMPLE_CALL: + if (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT) + && flag_auto_var_init > AUTO_INIT_UNINITIALIZED) + { + /* Get the variable name from the 3rd argument of call. */ + tree var_name = gimple_call_arg (stmt, 2); + var_name = TREE_OPERAND (TREE_OPERAND (var_name, 0), 0); + const char *var_name_str = TREE_STRING_POINTER (var_name); + + warning_at (gimple_location (stmt), OPT_Wtrivial_auto_var_init, + "%qs cannot be initialized with" + "%<-ftrivial-auto-var_init%>", + var_name_str); + } + break; + case GIMPLE_LABEL: + /* Stop till the first Label. */ + return integer_zero_node; + default: + break; + } + return NULL_TREE; +} + /* Possibly warn about unreachable statements between switch's controlling - expression and the first case. SEQ is the body of a switch expression. */ + expression and the first case. Also warn about -ftrivial-auto-var-init + cannot initialize the auto variable under such situation. + SEQ is the body of a switch expression. */ static void -maybe_warn_switch_unreachable (gimple_seq seq) +maybe_warn_switch_unreachable_and_auto_init (gimple_seq seq) { - if (!warn_switch_unreachable + if ((!warn_switch_unreachable && !warn_trivial_auto_var_init) /* This warning doesn't play well with Fortran when optimizations are on. */ || lang_GNU_Fortran () @@ -2093,26 +2139,36 @@ maybe_warn_switch_unreachable (gimple_seq seq) return; struct walk_stmt_info wi; - memset (&wi, 0, sizeof (wi)); - walk_gimple_seq (seq, warn_switch_unreachable_r, NULL, &wi); - gimple *stmt = (gimple *) wi.info; - if (stmt && gimple_code (stmt) != GIMPLE_LABEL) + if (warn_switch_unreachable) { - if (gimple_code (stmt) == GIMPLE_GOTO - && TREE_CODE (gimple_goto_dest (stmt)) == LABEL_DECL - && DECL_ARTIFICIAL (gimple_goto_dest (stmt))) - /* Don't warn for compiler-generated gotos. These occur - in Duff's devices, for example. */ - ; - else if ((flag_auto_var_init > AUTO_INIT_UNINITIALIZED) - && (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))) - /* Don't warn for compiler-generated initializations for - -ftrivial-auto-var-init. */ - ; - else - warning_at (gimple_location (stmt), OPT_Wswitch_unreachable, - "statement will never be executed"); + memset (&wi, 0, sizeof (wi)); + walk_gimple_seq (seq, warn_switch_unreachable_r, NULL, &wi); + gimple *stmt = (gimple *) wi.info; + + if (stmt && gimple_code (stmt) != GIMPLE_LABEL) + { + if (gimple_code (stmt) == GIMPLE_GOTO + && TREE_CODE (gimple_goto_dest (stmt)) == LABEL_DECL + && DECL_ARTIFICIAL (gimple_goto_dest (stmt))) + /* Don't warn for compiler-generated gotos. These occur + in Duff's devices, for example. */ + ; + else if ((flag_auto_var_init > AUTO_INIT_UNINITIALIZED) + && (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))) + /* Don't warn for compiler-generated initializations for + -ftrivial-auto-var-init. */ + ; + else + warning_at (gimple_location (stmt), OPT_Wswitch_unreachable, + "statement will never be executed"); + } + } + + if (warn_trivial_auto_var_init) + { + memset (&wi, 0, sizeof (wi)); + walk_gimple_seq (seq, warn_switch_unreachable_auto_init_r, NULL, &wi); } } @@ -2646,7 +2702,7 @@ gimplify_switch_expr (tree *expr_p, gimple_seq *pre_p) gimplify_stmt (&SWITCH_BODY (switch_expr), &switch_body_seq); gimplify_ctxp->in_switch_expr = old_in_switch_expr; - maybe_warn_switch_unreachable (switch_body_seq); + maybe_warn_switch_unreachable_and_auto_init (switch_body_seq); maybe_warn_implicit_fallthrough (switch_body_seq); /* Only do this for the outermost GIMPLE_SWITCH. */ if (!gimplify_ctxp->in_switch_expr) diff --git a/gcc/testsuite/gcc.dg/auto-init-pr102276-3.c b/gcc/testsuite/gcc.dg/auto-init-pr102276-3.c new file mode 100644 index 00000000000..f113f46e29d --- /dev/null +++ b/gcc/testsuite/gcc.dg/auto-init-pr102276-3.c @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wtrivial-auto-var-init -ftrivial-auto-var-init=zero" } */ + +int g(int *, int *); +int f() +{ + switch (0) { + int x; /* { dg-warning "cannot be initialized with" } */ + int y; /* { dg-warning "cannot be initialized with" } */ + default: + return g(&x, &y); + } +} + +int g1(int, int); +int f1() +{ + switch (0) { + int x; /* { dg-warning "cannot be initialized with" } */ + int y; /* { dg-warning "cannot be initialized with" } */ + default: + return g1(x, y); + } +} + +struct S +{ + char a; + int b; +}; +int g2(int); +int f2(int input) +{ + switch (0) { + struct S x; /* { dg-warning "cannot be initialized with" } */ + struct S y; /* { dg-warning "cannot be initialized with" } */ + default: + return g2(input) + x.b + y.b; + } +} diff --git a/gcc/testsuite/gcc.dg/auto-init-pr102276-4.c b/gcc/testsuite/gcc.dg/auto-init-pr102276-4.c new file mode 100644 index 00000000000..662e0d1182e --- /dev/null +++ b/gcc/testsuite/gcc.dg/auto-init-pr102276-4.c @@ -0,0 +1,40 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wtrivial-auto-var-init -ftrivial-auto-var-init=pattern" } */ + +int g(int *, int *); +int f() +{ + switch (0) { + int x; /* { dg-warning "cannot be initialized with" } */ + int y; /* { dg-warning "cannot be initialized with" } */ + default: + return g(&x, &y); + } +} + +int g1(int, int); +int f1() +{ + switch (0) { + int x; /* { dg-warning "cannot be initialized with" } */ + int y; /* { dg-warning "cannot be initialized with" } */ + default: + return g1(x, y); + } +} + +struct S +{ + char a; + int b; +}; +int g2(int); +int f2(int input) +{ + switch (0) { + struct S x; /* { dg-warning "cannot be initialized with" } */ + struct S y; /* { dg-warning "cannot be initialized with" } */ + default: + return g2(input) + x.b + y.b; + } +}