From patchwork Sat Feb 19 16:22:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 51239 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 F20063851C23 for ; 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 ; 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 , jakub Jelinek 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: 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-ID: <93C13A96D9BD80479653A58257415D78@namprd10.prod.outlook.com> 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Qing Zhao via Gcc-patches From: Qing Zhao Reply-To: Qing Zhao Cc: gcc-patches Paul A Clarke via , kees Cook Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 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 Sat Feb 19 16:24:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 51240 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 DB8463858006 for ; Sat, 19 Feb 2022 16:25:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB8463858006 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1645287957; bh=AmBf0IwuT80mVKcMsvw7kd4dWs9n1WS2GdpLDt75cvw=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=lcW67T5y3u7uNrlT5a69JUFia6l7QfAuQ8K7Mn3obbdSCU9ddyHr2gXgTzSZ0pb57 VNKJvbka7yOJIVLeHMDnvhmKkQq0zJuSqquix2d+QDneb86gxUHxEAScKBERIiPlQR nOlooThdY45/HUKIlE7dRnFnfuDwRM4nH1Vp9Tbg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 534DE3864C64 for ; Sat, 19 Feb 2022 16:24:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 534DE3864C64 Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21JCZbPl007199; Sat, 19 Feb 2022 16:24:13 GMT Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by mx0b-00069f02.pphosted.com with ESMTP id 3eas3v0q38-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 19 Feb 2022 16:24:13 +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 21JGBWwZ072878; Sat, 19 Feb 2022 16:24:11 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2176.outbound.protection.outlook.com [104.47.58.176]) by userp3030.oracle.com with ESMTP id 3eannrupep-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 19 Feb 2022 16:24:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=myKucMjugiHpzU+OSJT8/TnPyYjJKRyx+KDHX29PLEBP5KWBRoUDk4Z7YLtoFAvqdZIY07+gxLeVNYT6tGxts24bvfnw/pat0kb6SYe7I/nX3jCK/yXjeNoiniq+tHqL2ASFQ8FGPtd4015iF66GWJZknLWOONIYmeqIfrjjletNmTFs2VQkgIQG54ivJ4Iq92fjj3n2AxWafzVchl3Xv94EYg5Ryyp91x+/PXwDfZza5B7eUJPPH61f6y5QX4IRQOstmhJhlkoCp+gKsICLCwrektsb3hJ92bUx56TDqdRORGk3UZxdlJTZEt26yEL8I0UOYrC5F0yRQNvZG/rcTg== 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=AmBf0IwuT80mVKcMsvw7kd4dWs9n1WS2GdpLDt75cvw=; b=SoxNe0iFTYG+VTmfPVECb04EVLEyPI28D6m0hHlyxu4/hjNhe8uhI2xF29Xm+RSqCftgNsepjoEEub0uwe+4FrsgdWv3jpl9D9gVVcxJ3j6C6iVCeNxlHqSaR6K6okySfM4KVd+9YJHyiwHMjjgtn14b03Ruk9eEAnHtNp7K38K1FS7YTbOziEBn6socKwhRl33f3Co0k1/5df1fon0UMHCGdjs/KoOgR+rybQ6IHyz+iSTJBU5bpnjcWghkkWggg5e9O07ynpYZ53PbG1DAe+KjMKQEVJrLnQF4floS8jMRxRLNRVQ2pJgiFvmRwj+J7b/l5TfXxTwxZUJA0d4ydw== 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:24:09 +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:24:09 +0000 To: richard Biener , Jakub Jelinek Subject: [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: AQHYJa0f74Jbmopny0K50ybEQG+TZg== Date: Sat, 19 Feb 2022 16:24:09 +0000 Message-ID: <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: 80fda1c1-e9cc-4b7a-6185-08d9f3c441da x-ms-traffictypediagnostic: DM6PR10MB3611: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: 3vz/CnwUaPSTWBg9L4n4C0kWT1/xODJoWvo4uB/c3KqOk8tGOBLxbkd2IELvsEaLukR3d94+79wL0lKtcgPpykSChcF6C3R3ojUZy8/KaGl84Ljo8q2dlXd45yJGibZJJWFItHPIk54gQbuIMmSdqGq0Q7FomSNfedtOsNAGaR2QrbO0fZjoAE5ilAz9DhJqK/MvOjZFzClKHykZiHH7pBd8eJVuy+TYnQeKcZcXhUjEtKCscB2iF8PadGrDd/yU/OdqatJhTKaD2vtl5riOw2R/C3Raj3NivHBwm9JU0l+PyvqS164B90z1bx1Lo2CbjUATRkyhjc73AmkZ1j/SbNY7qE6VrjtONDHv/KCTIs3ta2YEUttCdoiiwOl9VLJy4gKV4H9ODQTNOr0R+lXsq8Xi4aC+n21iX88zrz6f5ezPDAU6b/va6INzWwcLhHEGE7SAk+hS6bPW/ewLpw8XsUGh3j39cXd/wmMnWMFwwDJyrbUzWp+vH/KKuq0NQnZ8dj1x6DbUvXNMQ8Kbn50cyNHr2iRNnWr56Wgd14w/LR4tRjI/5fhMoy10K+1ysm53peBlp765B9lzmGwivyb6kymP4WwV104FJjkxBu1qNdb/l5OQagWlgosn0taDpJpqNG8hbQ6QcUHfHTOYFBJSUC3N0AES6TclSuU3X9zq8THqlWzRTG2c13ujJ+zjFeFhyRnvN8MEZJiGadoV+63FT9AfSkMZqTrrbJOD20NGI1JuQ+FoPNB6pQcq5Zq4vnZ4wC08fkuf84VFvdl+ZKeepFgEWe2oqX/73UiMDzNTd/QN+Sbeoa4U9Ka2QKap+qnLCiISgl0BIeyCOhS36EsnmYaG9Ohiw1CHnjDifec0hbHWIa6IaNDmCIPH/3RmHt7j 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)(66446008)(4326008)(64756008)(8676002)(83380400001)(15650500001)(53546011)(6512007)(6506007)(2616005)(71200400001)(186003)(8936002)(30864003)(36756003)(44832011)(45980500001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: /p2ObDd38UrQhvM9ZAXlC//8sDMv1C8Vo0Mr1jhxzar7v2H+D5/xnBTqZwtp59oCDwMRcgc+V+fmkvzvlbzNsEFUySufeNYZ1jYOGt9q65HcfyWIpmGFilS5IwzHwdj80yakXA6wXsi8CaB7+t2y/sfxqXfltFY5lyWQ/W00hFo7qWM+KUx6QvJcqEIllqUeQL0YHgCTZbMxKKoJtIzD2FYxwsPnPq9qZhDfI+rOxowJpnyBZphOKpEh5jpmCR0WBounsZ0eT5gx6MvDAT/vxl/X2+qrWv2AzNeFTrUJRqmCHhmFbQKqzxDfz22MbKwJpN4sYQcZnydaf4My5s7oaBJjwVtPEPd2k/XXX9Buat6tLPj97WS4gXmUooJWTfnJl5pkn45z0Qjs+MjLxd7vBrLbYF74y4o/UquNnKNHEEl/IPvM/tb/A8QwKSYw71V2TyTPTwzK9PeGJ8iUpMojOdQhNzj95Yz16+AYt0y1QjpAFzsSma9CFjHmrxhAghS04PG9pXQNXbw+iVof7iIK80e0zBpyV13hLDzOXQc0yVUfpz0t8wtQ2763z9YhthX66+KCAhcE5rpLWclAM1EY8bcT61PaEwGWe96ZX83v0E64t13sSv6Pzm9IbOnxfsRfIMykrwRd0y/Hmm0SFEyCWm3fgXU7zPgAdRKfolXs4m20srOPVVI1+/tjiK9HF0Fgk4cQLD/+yiW655tG0SKHu6Xi4IXHToKcpT/bYhaOvX5zcp/4nfvkuGI2OgX+1jLo0ulPahDyjysTL79RkYdmISzknYjHIul+netGbn/bJIUPMF4x896CySf9KnorkMKHcMXLCRKkn+ZKEMXHZ/1vEtvHaRxSnHJF4IAQVYojwqRPw+80Jr7lY2pS15PXFP2Z7qMak4eIlRz+K/qt/thR3fb1oSrxjOosiYeZQo+8JXTwEtSA0JLTV/rohQymGThjbB2cRIeyEXPO+5ldmzsiy/S14M6RhbbxFxG16Xm8xosFuyqSPSiIcau0KR6avGZoQoun6j++eyrYoBxke3Real7TP8x5g81lmobe1EtQgidjdRp8ymvRcM4axypGEHjKJsZ4yh7oLFqT30aFX1wRXnd2HEuGSvZ06FcYcXc/HBqn15JyaNB09mtmOlVmyh5L+nQgcn5Ci/YrTiq/FsDNozKr8hKXa3Fb2J9HJwDrqX1lo7rxKPpjwiggkZNRe16KljZNoBapPDTVDiJkWlSjxN2BU3DJ64ZioSeQZR6gf2bLcm/13itQ9DMv3xgS41+jDNDQU/SL1fE1bIQ90SS0a++iBwkAwJNLgRgsmoR76eDyU22/rguD7SOP8ENjcmvTcHjB4sHqh1DOxixe/TnulBldA5tpN7MQ/alggt90Tcx9T7GoP4DAT0oJyrsDZlsfPyjsMqqxA2AtFfYCtXi8emnbVDRHdQW0Zwl2CI+K+W6xsPqmYErcJ21z4wMlBn7Jt8Olr2nO7fmKGRnCXTHHKHq/Q7AvW9AHLcBAB2mSYOuVohNeGMf+C6ut9PcDp760g8QBdlpLL4r2bPJo3HHB1LmdMJQLH7voHij3wqE4WLNORL8YEsB94kdUDa/GhS2YKxRNeYYmNB4dtQl59dLslBdIWmcL85UX8FeZPDhmeSGn0MFV7W8XOhG5BTIpYzBINv09sDQ5Z2sJp+ozAJL+YA== Content-ID: <8A5D88745993E945B72B15E55EFA2106@namprd10.prod.outlook.com> 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: 80fda1c1-e9cc-4b7a-6185-08d9f3c441da X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Feb 2022 16:24:09.2668 (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: aE98wwHW9UXICv4IZ/Do+Zw5Ez6DIsMhZCSUVU1b7AFfhvl4swwhNbpuuUK9yqqlsziz+sIfU59JrRD2bL5RBw== 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-GUID: wq_Hayk707E1oKkd6StGDymj1yZXTN8z X-Proofpoint-ORIG-GUID: wq_Hayk707E1oKkd6StGDymj1yZXTN8z 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, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Qing Zhao via Gcc-patches From: Qing Zhao Reply-To: Qing Zhao Cc: gcc-patches Paul A Clarke via , kees Cook Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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 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; + } +}