[1/2,middle-end/102276] Don't emit switch-unreachable warnings for -ftrivial-auto-var-init (PR102276)
Message ID | 4BFFFF31-FDD2-4145-BC6F-B7CBB925B1DB@oracle.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> 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 F20063851C23 for <patchwork@sourceware.org>; Sat, 19 Feb 2022 16:23:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F20063851C23 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1645287799; bh=HrBBhYf6VjsDCBqrKpOwzFh30BvqaxpeVcznT+EL48Y=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=K+ZmRUHiTM5z4+gNaGaxEAG4bCOSu0qNBRe9aRr/H8EmTozEk7EfS1wYH0nEavWoN wWLrH9SX/0HvDial8H3v29K4uSi2eBTLIeRP1yAOEb72v5D9a8orQX/MA3XzpADeU7 fXkYCxHhWZi+5BrUb4oi3e9C5OUM3qG+UCju1h/s= 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 633973858D1E for <gcc-patches@gcc.gnu.org>; Sat, 19 Feb 2022 16:22:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 633973858D1E 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 21J9ivE0024949; Sat, 19 Feb 2022 16:22:47 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3eaqb38uma-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 19 Feb 2022 16:22:47 +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 21JGBbmH072933; Sat, 19 Feb 2022 16:22:46 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2171.outbound.protection.outlook.com [104.47.58.171]) by userp3030.oracle.com with ESMTP id 3eannrunat-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 19 Feb 2022 16:22:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cvoyXH4RqWIfOeId5dXCJ6T/qSDMG2hyyjCbVnPWhFBtpMfUdYhKNYw72Mzf43D8U6r0VR1pmeI4X/A+DhYv+X5stDuvfDeoiT861k6lsjNU6ZfWojGb5kgGdvJhAaEWCluwL2SImKbaGMbW3Ws281kjuh561RAVaygYdr69MvoElcFXidcDXcvUL5vFZ9oYyVSmGmLu7EQYadYhQKVhIOQnbBTCBYN6Sq1sma77HnRtUb58Q3lwEbqhfvwsAEVoj4uCGFUjon9L+KAcM7Bsrs4iqEph1QdVDWeNhSXwKfmMYsqWv6JCIhi8PyjgopuztkCJqoMBt1Vnd+WCYvJEtA== 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=HrBBhYf6VjsDCBqrKpOwzFh30BvqaxpeVcznT+EL48Y=; b=aGx4xSjNSYp5C2oPR7Y6zmD43hSEPCeRgK6HN5IRrSL7AyqgWesABf29TrZVGOrMsd1xrM76Re6KC+G4wY4yZpwOIdD4Cvve4zlGWKa6mMRtxocjR4TbnJXnJCOnqQzkDnI6XmYGu91RlJvCJ63uqsCZ6gzaHpWsUaXbXUhqTPt0wJveLIWkPClWzao2WZkeIHVWFMuMDjrLV9k8mfQFqpLt6Tx1P1Y9jyf5fvXfEdK1JS/2w142Piu0ScbyfAiiRWTvDvJHNA9cTrG4gBOc4hPcvur97N7QvlxiPrAePCOuM8F3RYa/OOd30KKC0G6fMLGbNGbsaIL/s2SKl78n7Q== 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 Received: from CH2PR10MB4344.namprd10.prod.outlook.com (2603:10b6:610:af::19) by DM6PR10MB3611.namprd10.prod.outlook.com (2603:10b6:5:179::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4995.16; Sat, 19 Feb 2022 16:22:44 +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.4995.025; Sat, 19 Feb 2022 16:22:43 +0000 To: richard Biener <rguenther@suse.de>, jakub Jelinek <jakub@redhat.com> Subject: [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: AQHYJazsS8SepyJ5MESNJ94p60ClyQ== Date: Sat, 19 Feb 2022 16:22:43 +0000 Message-ID: <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: 4b57a6ed-b658-4b3d-a766-08d9f3c40ed8 x-ms-traffictypediagnostic: DM6PR10MB3611:EE_ x-microsoft-antispam-prvs: <DM6PR10MB3611790BEE7BC3504E4FA34180389@DM6PR10MB3611.namprd10.prod.outlook.com> x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: g41kau4UF15Q8oACTBxCnc+affIpw1WbxYI6khggfMTNulfl4AT55XMe86GEdYES5JcCuomsV6w0DQc2JnZXeeVuBPRatagLcWhHjuRnbBdNozmHNewixmCNjDkDl0ckd+XLa7sfu+hlpQDZLiEV2mfWEPMWpt9BHAxDfgsijWbrjkttl+SHJ3MaJvMjGRc4gK4X2UuVcN57PzhCwvpqv7y+0i+qcAFq+Ctt3cYRsTj8swBl6EOst1W8tl6ZrmkDXm2bU2qbdIwS/2PCHIeOcsaUbSdEdIr4UiTPvf+JYOlXX6qJoALLXOv8v/orwEvPLVgA9E0N3d4Qe5/NlVfda0sGcSMbPtlx+DZJUqUW9DnYhvMHxudzi8VNkfZ3CG8CKg6wVfIVnS0sPppefzkpoR7HANXHOS6QfhmR5QOS5fWxH5eCxz813H9g/GnRrmeCkYksPfUKnVoxr42ZjUNM9c0xa/v+2rcmqfYTUm5UhIiCwrJVihXLfRJ7+XbpkyAwT4PlZTRx7BSjIJd6uAus/ZMFUJxWANtFmeEuMaMUVDlXNG+Zlt9eMPeKOWSlZPoMBOuOKatruuSb4PEbXOabIT50efm38hoE9r6UbzywteoTym84CBIY08GgBRAunj1vi7thH+SEDkvRs6Qyx0PPQI19433rzblKSp3ZLe02zVxMfy0zBq7Q+j7vXU5eTgmVVloev0EQiTevu8cEg+K6goLIXXQA0Wz2QRAQZZnNwTCdk6eHDzx8u/V3PhgBXKyiBa6I4X+ZHdHMleAXwBoKat8eIzWeu91W5AeD1k//nuzox9xyOom1GM3yRjzcUJKCDfa53ZDAjp7jjvZ5gj2BCTjdfnom5Fq3gHtxIo4JBfk= 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)(84970400001)(33656002)(86362001)(38100700002)(5660300002)(122000001)(38070700005)(316002)(54906003)(110136005)(6486002)(508600001)(76116006)(66946007)(66556008)(2906002)(91956017)(66476007)(966005)(66446008)(4326008)(64756008)(8676002)(83380400001)(53546011)(6512007)(6506007)(2616005)(71200400001)(186003)(8936002)(36756003)(44832011)(45980500001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: r9ZSpsD6CgfNc8y6ShiMQ7t4vbHg8Fc4qEBuUl9MFC9rF9v+7C7kucIae8WCH6GgQzm49TNcZizzErSduv/hfPWb1Ms+kplaSZbsbmlIwnOuhxHx5u7DgsT1CFYNbiQghXIsDu2Q7PbBRweGSZxX424AcTShRhT8mukk4IX0tx+ANCXJyKYpfmbG8pkBaiA3I69EDTAQGBcw2s3lARikPdxJ89R6SvMvxUhG6OTcVzcjycQlSOM84B+gvH5ArSLnCHqTNoti4jAgr7ZYN4bzzPMP3EJtveA5EYlzvzdnhoBCYc4IK6GKceHAD8hzQz7Z3PpW2vMEob0sDz+06gbwjlWeSqc6aelioxUt+8znRCrvKyqV/AzT8V8PsXvDgJ3fL6j/JAdj9kDwe0c3jKnjJkCNaLUhnuG/DNG20WzkpniPbxJjkmKbYB3ZMhOJZixrQYxZ9QqebShYhAjyIZ92p3nI2RsvzGG+fnH1fbZ4kolbyGqENCc86NjE4CDAaJPwT3IYaojTsf1RDZ8RCMfmtoWdmavALFwEz64YkHW3BEa9UK4+HnabVBbW0As5MOqs6DHSPlh1YzlSYh00faUsfwPQpsuCHr6zMMuhNT4SChB/c6EgR7xMW90vwg080fLzI2TmBUl3Fd5OeW4MCbbTzibkb90hBlLq5y4kjupV8L/RlzKoeaKqjHZgzD+kQeZZnK5JhBrHqK4F8wYGTD5dS/0w0fQYxX+vKACt6k8KLUV3tqPkbnz+78sPRkZCT3Qgn4y9oFHGzkKEHErt4PahM2wn/meE42f3I0Htk9GM6s8cNFh3esT7SnaE64eCaY42zVNVxCdQW8R3/A0i+j/eivi39MJgjQbUExL9RsjxXdhibncSgHa+H8fSSzSIZZX0QSFKAv7BcskK4L8M5RARqfC2Hz6fdHpK2fN8DPiN1HgtjvdkCeRUzHExr+Eg9NsDnUZOYJNE06Jd5yEJAlZC2OHhGsUzPoxwM/ubt0ScHGzBkbb/r32DEn1t6yc3yfYeQ9BBWnFHUgnp76ezIhUQh1qlh+t9BdT24Egm14D3QXqQkVNH8QG+QuXG4I1zfArAPGCuD2PAuSFZTP+EMxPOjacxF85kYnwXFbY/awkvilj0Z2nPmdjus1yGNx/lhJyLer/ibsBJkAKY9LS4XHYqgdaAsHyW5W3DLwODl5VEa2blDdbtouiVKeUeNPxqNW0J+o70mvUVgfCEuspjf19qshjYyTwiiyzosDE9THSQrjJ/6+WMOGtSZwfffa4ZoK1N4YITzFsu2uC3zmh+1XTPVek3xdSfwTRyKV31NsAuQkHUNALGEZR1laa8i4Se5PPwiSoSKvBZKjMFzfwdLkAR+p9j9gVoaAo/6B0G8nmnYCqBSRgiTd+EtIkOqUHWaeUwfuuH9qGfskAIgih2FI3cewABJfp/5893kPRVSBQf7CMiqBcjhAHwxGVZWOz7qNhbWeraZJaMgOmMYvy4X+RLUFIHwi/DFEqbYQBtg6cZZ+lZX1vStbwWdqPKQYvgMImDLhrErcDwoAtozt4QE+JGXhOJ/D3NNRCRLWh9I/Y31P9nsKok1Q4mRUWrbcUReb+6jmiJ00CU8LapkS+qR+Klrwsak+Rcf603WZZYj5yTqoEyHtmOkHS41Y94a/EWhe1W0fQ0ql5fki1AXL5A68IouQ== Content-Type: text/plain; charset="us-ascii" Content-ID: <93C13A96D9BD80479653A58257415D78@namprd10.prod.outlook.com> Content-Transfer-Encoding: quoted-printable 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: 4b57a6ed-b658-4b3d-a766-08d9f3c40ed8 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Feb 2022 16:22:43.7073 (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: eGlLjiUJT6VgQAGxuVKzXyYJvm9WcWgWHmD27VY88ZmmowKUbtLJvRdOc/Ln5EA5n48Q8riXtRcRDaqWgiw10w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR10MB3611 X-Proofpoint-Virus-Version: vendor=nai engine=6300 definitions=10263 signatures=677614 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-2202190106 X-Proofpoint-ORIG-GUID: lK41lTI6Xp0heicxsBTiXwNeyZxNN8pJ X-Proofpoint-GUID: lK41lTI6Xp0heicxsBTiXwNeyZxNN8pJ X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Qing Zhao via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Qing Zhao <qing.zhao@oracle.com> Cc: gcc-patches Paul A Clarke via <gcc-patches@gcc.gnu.org>, kees Cook <keescook@chromium.org> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[1/2,middle-end/102276] Don't emit switch-unreachable warnings for -ftrivial-auto-var-init (PR102276)
|
|
Commit Message
Qing Zhao
Feb. 19, 2022, 4:22 p.m. UTC
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 <qing.zhao@oracle.com>
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 <qing.zhao@oracle.com>
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
Comments
On Sat, 19 Feb 2022, Qing Zhao wrote: > 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 <qing.zhao@oracle.com> > 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 <qing.zhao@oracle.com> > 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 > > 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. */ > + ; I think you want to instead skip these in warn_switch_unreachable_r since otherwise a .DEFERRED_INIT can silence the warning for a real stmt following it that is not reachable. Richard. > 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" } */ > + } > +} > + >
> On Feb 24, 2022, at 4:10 AM, Richard Biener <rguenther@suse.de> wrote: > > On Sat, 19 Feb 2022, Qing Zhao wrote: > >> 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 <qing.zhao@oracle.com> >> 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 <qing.zhao@oracle.com> >> 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 >> >> 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. */ >> + ; > > I think you want to instead skip these in warn_switch_unreachable_r > since otherwise a .DEFERRED_INIT can silence the warning for a real > stmt following it that is not reachable. Oh, yeah, you are right. Will fix this. Thanks. Qing
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" } */ + } +} +