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/I2EWEP4MfXOFJn5D9CXmlqeMNJ8GaVjdh4eRwjK6RnkTlO6xLNJ5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ImZzgvcbg7ClXZFKtEw6Y29ISTc4utDkNMyr73rYmQf6RvBmpnZSVcyMknJleylmsyKcdiZdKupWAATlr3m/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" } */ + } +} +