From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 11EC3383A0E7; Tue, 13 Dec 2022 15:27:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 11EC3383A0E7 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 (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BDDwf0B008642; Tue, 13 Dec 2022 15:27:49 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=corp-2022-7-12; bh=sHbjjqEgwvkWGw67Qrs6wsYlDThdypn6vEm00bvetpA=; b=CP8stQ6ahwYO7W72d4cuoqA5c7i8sYpNBjZ+jpZPSGir9VLBlQUa+PHFVLqwJ/p1uJ7r Mu5drZNg0i6GbwE9XHc1YHZua5VxWKkoeCuTAOy08uX1vDarN0aJ39q9twN+hIUyzGMf jyU9xRjjM6FaV947z6PPc0T59lb/wDT1bM4yvLCDzp3hHuG16XJXyrsIWYCkn7wByzVy j5N/GSf+EnIIyTG12s7DnseNPRuTPlic7gi3E7LrAw6uhn6QvrjaROD7WibuAJMaq3qC qznz7Px1+VrPU+L00FIBzq09nfeqYLqfPQpxgbj1RIXoxRaZvHWldr9jGVO+rEnrEo1U Fw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3mcj5bwn0x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Dec 2022 15:27:48 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 2BDFCRdN009469; Tue, 13 Dec 2022 15:27:47 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2041.outbound.protection.outlook.com [104.47.56.41]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3mcgj5wffb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 13 Dec 2022 15:27:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ndzSKDZKY3a6GTIVs/jgxl/p4kX07xv2fGP1FrFuIJG6Al94QKvZRjtK73gvcwP9SFjkRxOTb4kYcg2L3tVoeqre10vxBrT70/RTnEzRH7Qe2J+6prSPywOd5G1G+NWl0BMGt0RR+DmINiuq8oNjqCmaNrdtLyTJ5O8TlrbEWqnMZ089E7NhcamfKtn2sBDYGHyUrUih2u/4qqceR2fxzn2fw/HPRmK3+8M2A+c3ljEQ9RjLqSGoJAvMWYpECwRWKpbW7BX3HYYV0hVfy2+Sy5NQEXgcfEF1OHGuMhoKH5J8jlCj8iQrN9RRhxb3hfgrSQq9JjIZlgLoE8nDXF8aWg== 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=sHbjjqEgwvkWGw67Qrs6wsYlDThdypn6vEm00bvetpA=; b=mg26C9HP8+VoJi88Fl59BnbKoSRqbFFeo1afuJy7unYeqSM23HSX/tF2X5YutkfqlnHLQ9/1DjoMhZ4BDB4tT764ub/U9Cgycz2yGDglWjqM9yO/7BH/9xaO8b+72cW57JYxyBYyRPoHZlTVJ+CQilvncaPqcK3Po52w//mt7guUGd0vXBjoiy21cN/wiMsd2P0XyUwvWrvVwno1fgQlUHn31eoOgfPl5Zyt0aty90c013GH43gRBuMqXUdO0LFE8+lcB4jyrCdh9fitPDiO4+dd9BvAa1JEW4ZQmKgl8MgOZu54nvJ3VAxIBgfpq74aI5LMcMAt3hH98+zpWdYQqA== 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=sHbjjqEgwvkWGw67Qrs6wsYlDThdypn6vEm00bvetpA=; b=Jesu0HzBINhfhrDQJD+IQeB+Z61CB62fQj3sPygu2oKhfyuAjVlhNBgSDiHiNXilMQsaeANRKzaH5d6S2zzz5tv7uf/qSUiJPDJYb61CrkLgxafndLgsdyYppuY/5/IWZREZ86XflJsYSm7svboOGSTfzVBeD8CylB9yVgPmPAg= Received: from CH2PR10MB4344.namprd10.prod.outlook.com (2603:10b6:610:af::19) by PH8PR10MB6314.namprd10.prod.outlook.com (2603:10b6:510:1cd::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.19; Tue, 13 Dec 2022 15:27:45 +0000 Received: from CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::9423:79b3:c0dc:1113]) by CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::9423:79b3:c0dc:1113%9]) with mapi id 15.20.5880.019; Tue, 13 Dec 2022 15:27:44 +0000 From: Qing Zhao To: Richard Biener , "joseph@codesourcery.com" CC: "gcc-patches@gcc.gnu.org" , "keescook@chromium.org" , "siddhesh@gcc.gnu.org" Subject: Ping---[V3][PATCH 2/2] Add a new warning option -Wstrict-flex-arrays. Thread-Topic: Ping---[V3][PATCH 2/2] Add a new warning option -Wstrict-flex-arrays. Thread-Index: AQHZCY5sSXlMD9UupU2COKrkmjhESK5r+8aA Date: Tue, 13 Dec 2022 15:27:44 +0000 Message-ID: References: <20221206161844.2397151-1-qing.zhao@oracle.com> In-Reply-To: <20221206161844.2397151-1-qing.zhao@oracle.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3696.120.41.1.1) x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CH2PR10MB4344:EE_|PH8PR10MB6314:EE_ x-ms-office365-filtering-correlation-id: 4f11949f-3494-4563-6615-08dadd1e9533 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: wZTCfPoOn5G1aV5ktWTFTk/j8bUQdIUf9niUOpA5tSWHyE9zD2UsuiMvv1M4p0Jt0Ss7pGf2qjjNnafmzucHoBhb410Gl8tKUGFlY4Ya8kl8SFrCJeYOoX3HzGtnvJVF33tHH9+2b8+5DFR8S8uqpgFyIl37Yq61umwGtYFn9LTdWXYOYmWTliXWTsg8PNtCBAFnUTULQI5dSVHxe24YlJv9KAWVaXs8joh8g0/oA28erQ1Ug0s90cCzea+IHn+xgXvKLwTJtEkm1KvdGP2If4OVUFGL+18+3KXaGAa051JR12CR5569ABgR0OGTBCP62AfWWztKB9N4FpDwXFPiVuvMdPThM2d7T2CsFrjh1T6kV2q9nfj90iaHRgtLQofq8DDhArGbxOcb3UJGSfyRzecBdUcMC+TfkFakq7OZRdOF/Ver5Tx3S/OR5UugiN2U+JO7kwzT4EplDaDWZe3Gz1wBIgGcc0Zg8e2M3p/2BJANHNA401TEF9APZYaurEhcgsdO6CTR9eiWiQ4uAeFcBhNl1Eb1+J+bhoOPh/mZqnrmardgi4UwlVwo4hq2Jow/V2Jqp3hzL/CpVzA/3MOQh8Ccd2v9P8oY5B02eboLd+XLYdtYiwd+3ZcPgGJQqlFIzEAytTUE3OLPjSoARvJFGCzK+ugfeQRiVhGaefyHuChJrJLxfPhNdXwUBIXsRnD1RUCPR94YBeQL8R8IZtSdoEyOLitjcRpHd4C/4kBdst8kdLRflPF49JvTlA9fIcArDgAqAzAIkjNbtdzf1KKuyAlYOZOvFBgcLqlqsmAmqbAZj22ZtwGmUHXpuGol9DBl 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:(13230022)(396003)(366004)(346002)(39860400002)(136003)(376002)(451199015)(38070700005)(122000001)(33656002)(316002)(54906003)(86362001)(38100700002)(4326008)(8676002)(91956017)(110136005)(76116006)(71200400001)(66556008)(478600001)(44832011)(64756008)(5660300002)(66476007)(41300700001)(8936002)(2906002)(66446008)(2616005)(30864003)(6486002)(83380400001)(186003)(6506007)(53546011)(66946007)(6512007)(36756003)(84970400001)(45980500001)(579004)(559001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?8RK05hwJtStHelorBLXw8mn/wkHe1hBNDoQ7ablugpLdOEkGtG8IrPo1nbQH?= =?us-ascii?Q?Um80y5T6pEBBs/De2zkn393octy175iyHcOLY5S4gVsvgI1Si1jOSmC67bsu?= =?us-ascii?Q?blPVC7lWxJSZ2kr22EZ64On5n5XGLDR6OLMHsDcacvQSnsa/NJG2AF303gpw?= =?us-ascii?Q?iitCcvSFJfOPX/4+T45izTRCwg0rIfbQkyw6WKWT1K+rhI0FKDfBQARl/C01?= =?us-ascii?Q?fSnTzOT4uOquPOrUzDF/BwPINfTgiy9sMrUxUPP0g58cDtGnWTSJ7B2OxGsK?= =?us-ascii?Q?lM9L+/wpkrIuCfLmWaCiRWnhvtktuZ9cJpkkDVHXUF7nciBIFT9QyXGTWRTh?= =?us-ascii?Q?vj/V9Emyo8LdcTlqmMIQhXpZPPN1ffVidTaV3KoZevZZ2k4iZjtSOFVm/qh2?= =?us-ascii?Q?/tF9dNX4BqMzPW4RhS0jcu61RsgiT+b/1FJ2nPA0eIaaXS59ZSQvRfM1P6WN?= =?us-ascii?Q?bzyQB/DNOLAgFF7ilPAPORvWPCp2DE+0akV4TcKvIeeKrlcZSejMZ9KWnXf4?= =?us-ascii?Q?GN5KJ5RmTqsM9+G+hhV92VXuQuBsajtNAu5zXTxhH9w7Uvcl2U4anbatY0s8?= =?us-ascii?Q?87zvNTx3KZNwpxT3lqdQSKcCJor2wLkRHCD/OmnSBHGdr5H7seOclUSsg+5h?= =?us-ascii?Q?r1xFzqiSXdWM3Sq0gQBzAjKgoWYWGGoyTui7kEE4/SeOApWs2wtdci4ne7E9?= =?us-ascii?Q?xDUwpwLAJ96n2DvwIouD3R1yjXRBPwyuGXeEhYAI+gdSMUkOHQX0eMbwq7yM?= =?us-ascii?Q?q+7ZIJA8riL+6SvLV4iXZVU1Vefkw8f2GtKe0Ih7QjyzvSxPmeKpXIxHIJ2m?= =?us-ascii?Q?cMLRjhAjnlLkNXbyrDiT7PhzFHdkLt5S6YjPRPn3mPirLAv6NyMuAsJFxr/Y?= =?us-ascii?Q?xGfrp/Ob2Z/ToeUafpA6gWS/0dq/bQJpkA0JAeEc9PBJQC1348rhtA2QLE/L?= =?us-ascii?Q?+g+DaFQ+Wa7fuW3dtDwMqoFgfmuYGvkgMEUQz4GTXzG3tCEDCVbdhARM4utJ?= =?us-ascii?Q?XHPE/Qgw/7lTUYOf+CnvadBaASqX1PIgaaOUHkHMFlWZbdZuSqR9m9H90aPz?= =?us-ascii?Q?1XT0sIKQpcIgZNz/YdBAg1imIWjFXV0ZanO3NJuellsU1lgJKOkVqEDJGkYE?= =?us-ascii?Q?Tk52sJ0ED5Wg6UVmwuU24QMPfIKp9AMwxEloPbG5W/J2iEJFObm5yDyQ64M3?= =?us-ascii?Q?D9QRpXnYPUukdIMdAhoz1Axv67qSlrICa4Ye+5Tup+WYkHbwthrh0PRLuRIi?= =?us-ascii?Q?z1UAGxmU5i7lOZj9rpvjtzIaMD+A4bklgPYEF6mOfU63E8TFvQHMPjZaZdr1?= =?us-ascii?Q?nQp8R+yPi5YPZMnnMkS7yhecZnmtnTjzkcegAV/PA55MDntpRhd3A+hG7ePN?= =?us-ascii?Q?KhL6G03bIgS6BL9DoFp8GP0THl5GrKw7EWrf3Wt3UfuY6Oyby90XNL7tZFXv?= =?us-ascii?Q?ODoB8N5mth1gP4KTqPKzu2rNcysgGm+cdNZRfYvSTFgtZVlMDIPPo7RRUGb3?= =?us-ascii?Q?9/a+SHcVuTLRyIqzNq56HGjGasbSqBqShIM102A1ICcHG4qL1ONRLISOMldk?= =?us-ascii?Q?vXXPbJ/5y6OJ+M6feKU6vpMOWthpJalutCmr1RVQY7Pg6Wl1NudJhd2Oi2by?= =?us-ascii?Q?tqi/tzeGBRsZkaShZioZebc=3D?= Content-Type: text/plain; charset="us-ascii" Content-ID: <0D9C26615751FF4A83DCDE6920880CB5@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: 4f11949f-3494-4563-6615-08dadd1e9533 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Dec 2022 15:27:44.7965 (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: cAZhUXUPd51uJjRSrUO/6nRlWnZHYCv2xXoEfZiFTG+O2etb/HGEw13qR3q/MEzovk/vZuRww5OfyLoXJ/bxcg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR10MB6314 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-13_03,2022-12-13_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212130136 X-Proofpoint-GUID: Z6zEqFFnImRrvgMH__EBD8uYFgxS876E X-Proofpoint-ORIG-GUID: Z6zEqFFnImRrvgMH__EBD8uYFgxS876E 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,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Richard,=20 Do you have any decision on this one?=20 Do we need this warning option For GCC?=20 thanks. Qing > On Dec 6, 2022, at 11:18 AM, Qing Zhao wrote: >=20 > '-Wstrict-flex-arrays' > Warn about inproper usages of flexible array members according to > the LEVEL of the 'strict_flex_array (LEVEL)' attribute attached to > the trailing array field of a structure if it's available, > otherwise according to the LEVEL of the option > '-fstrict-flex-arrays=3DLEVEL'. >=20 > This option is effective only when LEVEL is bigger than 0. > Otherwise, it will be ignored with a warning. >=20 > when LEVEL=3D1, warnings will be issued for a trailing array > reference of a structure that have 2 or more elements if the > trailing array is referenced as a flexible array member. >=20 > when LEVEL=3D2, in addition to LEVEL=3D1, additional warnings will be > issued for a trailing one-element array reference of a structure if > the array is referenced as a flexible array member. >=20 > when LEVEL=3D3, in addition to LEVEL=3D2, additional warnings will be > issued for a trailing zero-length array reference of a structure if > the array is referenced as a flexible array member. >=20 > gcc/ChangeLog: >=20 > * doc/invoke.texi: Document -Wstrict-flex-arrays option. > * gimple-array-bounds.cc (check_out_of_bounds_and_warn): Add two more > arguments. > (array_bounds_checker::check_array_ref): Issue warnings for > -Wstrict-flex-arrays. > * opts.cc (finish_options): Issue warning for unsupported combination > of -Wstrict_flex_arrays and -fstrict-flex-array. > * tree-vrp.cc (execute_ranger_vrp): Enable the pass when > warn_strict_flex_array is true. >=20 > gcc/c-family/ChangeLog: >=20 > * c.opt (Wstrict-flex-arrays): New option. >=20 > gcc/testsuite/ChangeLog: >=20 > * gcc.dg/Warray-bounds-flex-arrays-1.c: Update testing case with > -Wstrict-flex-arrays. > * gcc.dg/Warray-bounds-flex-arrays-2.c: Likewise. > * gcc.dg/Warray-bounds-flex-arrays-3.c: Likewise. > * gcc.dg/Warray-bounds-flex-arrays-4.c: Likewise. > * gcc.dg/Warray-bounds-flex-arrays-5.c: Likewise. > * gcc.dg/Warray-bounds-flex-arrays-6.c: Likewise. > * c-c++-common/Wstrict-flex-arrays.c: New test. > * gcc.dg/Wstrict-flex-arrays-2.c: New test. > * gcc.dg/Wstrict-flex-arrays-3.c: New test. > * gcc.dg/Wstrict-flex-arrays.c: New test. > --- > gcc/c-family/c.opt | 5 + > gcc/doc/invoke.texi | 27 ++++- > gcc/gimple-array-bounds.cc | 103 ++++++++++++++---- > gcc/opts.cc | 8 ++ > .../c-c++-common/Wstrict-flex-arrays.c | 9 ++ > .../gcc.dg/Warray-bounds-flex-arrays-1.c | 5 +- > .../gcc.dg/Warray-bounds-flex-arrays-2.c | 6 +- > .../gcc.dg/Warray-bounds-flex-arrays-3.c | 7 +- > .../gcc.dg/Warray-bounds-flex-arrays-4.c | 5 +- > .../gcc.dg/Warray-bounds-flex-arrays-5.c | 6 +- > .../gcc.dg/Warray-bounds-flex-arrays-6.c | 7 +- > gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c | 39 +++++++ > gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c | 39 +++++++ > gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c | 39 +++++++ > gcc/tree-vrp.cc | 2 +- > 15 files changed, 273 insertions(+), 34 deletions(-) > create mode 100644 gcc/testsuite/c-c++-common/Wstrict-flex-arrays.c > create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c > create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c > create mode 100644 gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c >=20 > diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt > index 0d0ad0a6374..33edeefd285 100644 > --- a/gcc/c-family/c.opt > +++ b/gcc/c-family/c.opt > @@ -976,6 +976,11 @@ Wstringop-truncation > C ObjC C++ LTO ObjC++ Var(warn_stringop_truncation) Warning Init (1) Lang= EnabledBy(C ObjC C++ LTO ObjC++, Wall) > Warn about truncation in string manipulation functions like strncat and s= trncpy. >=20 > +Wstrict-flex-arrays > +C C++ Var(warn_strict_flex_arrays) Warning > +Warn about inproper usages of flexible array members > +according to the level of -fstrict-flex-arrays. > + > Wsuggest-attribute=3Dformat > C ObjC C++ ObjC++ Var(warn_suggest_attribute_format) Warning > Warn about functions which might be candidates for format attributes. > diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi > index 726392409b6..4402b0427ef 100644 > --- a/gcc/doc/invoke.texi > +++ b/gcc/doc/invoke.texi > @@ -398,7 +398,7 @@ Objective-C and Objective-C++ Dialects}. > -Wstrict-aliasing=3Dn -Wstrict-overflow -Wstrict-overflow=3D@var{n} @go= l > -Wstring-compare @gol > -Wno-stringop-overflow -Wno-stringop-overread @gol > --Wno-stringop-truncation @gol > +-Wno-stringop-truncation -Wstrict-flex-arrays @gol > -Wsuggest-attribute=3D@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r{|}mal= loc@r{]} @gol > -Wswitch -Wno-switch-bool -Wswitch-default -Wswitch-enum @gol > -Wno-switch-outside-range -Wno-switch-unreachable -Wsync-nand @gol > @@ -7835,6 +7835,31 @@ however, are not suitable arguments to functions t= hat expect > such arrays GCC issues warnings unless it can prove that the use is > safe. @xref{Common Variable Attributes}. >=20 > +@item -Wstrict-flex-arrays > +@opindex Wstrict-flex-arrays > +@opindex Wno-strict-flex-arrays > +Warn about inproper usages of flexible array members > +according to the @var{level} of the @code{strict_flex_array (@var{level}= )} > +attribute attached to the trailing array field of a structure if it's > +available, otherwise according to the @var{level} of the option > +@option{-fstrict-flex-arrays=3D@var{level}}. > + > +This option is effective only when @var{level} is bigger than 0. Otherw= ise, > +it will be ignored with a warning. > + > +when @var{level}=3D1, warnings will be issued for a trailing array refer= ence > +of a structure that have 2 or more elements if the trailing array is ref= erenced > +as a flexible array member. > + > +when @var{level}=3D2, in addition to @var{level}=3D1, additional warning= s will be > +issued for a trailing one-element array reference of a structure > +if the array is referenced as a flexible array member. > + > +when @var{level}=3D3, in addition to @var{level}=3D2, additional warning= s will be > +issued for a trailing zero-length array reference of a structure > +if the array is referenced as a flexible array member. > + > + > @item -Wsuggest-attribute=3D@r{[}pure@r{|}const@r{|}noreturn@r{|}format@r= {|}cold@r{|}malloc@r{]} > @opindex Wsuggest-attribute=3D > @opindex Wno-suggest-attribute=3D > diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc > index db3459af325..825f11331b5 100644 > --- a/gcc/gimple-array-bounds.cc > +++ b/gcc/gimple-array-bounds.cc > @@ -252,25 +252,34 @@ get_up_bounds_for_array_ref (tree ref, tree *decl, >=20 > /* Given the LOW_SUB_ORG, LOW_SUB and UP_SUB, and the computed UP_BOUND > and UP_BOUND_P1, check whether the array reference REF is out of bound= . > - Issue warnings if out of bound, return TRUE if warnings are issued. = */=20 > + When out of bounds, set OUT_OF_BOUND to true. > + Issue warnings if FOR_ARRAY_BOUND is true. > + return TRUE if warnings are issued. */ > + >=20 > static bool > check_out_of_bounds_and_warn (location_t location, tree ref, > tree low_sub_org, tree low_sub, tree up_sub, > tree up_bound, tree up_bound_p1, > const value_range *vr, > - bool ignore_off_by_one) > + bool ignore_off_by_one, bool for_array_bound, > + bool *out_of_bound) > { > tree low_bound =3D array_ref_low_bound (ref); > tree artype =3D TREE_TYPE (TREE_OPERAND (ref, 0)); >=20 > bool warned =3D false; > + *out_of_bound =3D false; >=20 > /* Empty array. */ > if (up_bound && tree_int_cst_equal (low_bound, up_bound_p1)) > - warned =3D warning_at (location, OPT_Warray_bounds_, > - "array subscript %E is outside array bounds of %qT", > - low_sub_org, artype); > + { > + *out_of_bound =3D true; > + if (for_array_bound) > + warned =3D warning_at (location, OPT_Warray_bounds_, > + "array subscript %E is outside array" > + " bounds of %qT", low_sub_org, artype); > + } >=20 > if (warned) > ; /* Do nothing. */ > @@ -283,24 +292,33 @@ check_out_of_bounds_and_warn (location_t location, = tree ref, > : tree_int_cst_le (up_bound, up_sub)) > && TREE_CODE (low_sub) =3D=3D INTEGER_CST > && tree_int_cst_le (low_sub, low_bound)) > - warned =3D warning_at (location, OPT_Warray_bounds_, > - "array subscript [%E, %E] is outside " > - "array bounds of %qT", > - low_sub, up_sub, artype); > + { > + *out_of_bound =3D true; > + warned =3D warning_at (location, OPT_Warray_bounds_, > + "array subscript [%E, %E] is outside " > + "array bounds of %qT", > + low_sub, up_sub, artype); > + } > } > else if (up_bound > && TREE_CODE (up_sub) =3D=3D INTEGER_CST > && (ignore_off_by_one > ? !tree_int_cst_le (up_sub, up_bound_p1) > : !tree_int_cst_le (up_sub, up_bound))) > - warned =3D warning_at (location, OPT_Warray_bounds_, > - "array subscript %E is above array bounds of %qT", > - up_sub, artype); > + { > + *out_of_bound =3D true; > + warned =3D warning_at (location, OPT_Warray_bounds_, > + "array subscript %E is above array bounds of %qT", > + up_sub, artype); > + } > else if (TREE_CODE (low_sub) =3D=3D INTEGER_CST > && tree_int_cst_lt (low_sub, low_bound)) > - warned =3D warning_at (location, OPT_Warray_bounds_, > - "array subscript %E is below array bounds of %qT", > - low_sub, artype); > + { > + *out_of_bound =3D true; > + warned =3D warning_at (location, OPT_Warray_bounds_, > + "array subscript %E is below array bounds of %qT", > + low_sub, artype); > + } > return warned; > } >=20 > @@ -333,14 +351,21 @@ array_bounds_checker::check_array_ref (location_t l= ocation, tree ref, >=20 > tree arg =3D TREE_OPERAND (ref, 0); > const bool compref =3D TREE_CODE (arg) =3D=3D COMPONENT_REF; > + unsigned int strict_flex_array_level =3D flag_strict_flex_arrays; >=20 > if (compref) > - /* Try to determine special array member type for this COMPONENT_REF= . */ > - sam =3D component_ref_sam_type (arg); > + { > + /* Try to determine special array member type for this COMPONENT_R= EF. */ > + sam =3D component_ref_sam_type (arg); > + /* Get the level of strict_flex_array for this array field. */ > + tree afield_decl =3D TREE_OPERAND (arg, 1); > + strict_flex_array_level =3D strict_flex_array_level_of (afield_dec= l); > + } >=20 > get_up_bounds_for_array_ref (ref, &decl, &up_bound, &up_bound_p1); >=20 > bool warned =3D false; > + bool out_of_bound =3D false; >=20 > tree artype =3D TREE_TYPE (TREE_OPERAND (ref, 0)); > tree low_sub_org =3D TREE_OPERAND (ref, 1); > @@ -361,7 +386,8 @@ array_bounds_checker::check_array_ref (location_t loc= ation, tree ref, > warned =3D check_out_of_bounds_and_warn (location, ref, > low_sub_org, low_sub, up_sub, > up_bound, up_bound_p1, vr, > - ignore_off_by_one); > + ignore_off_by_one, warn_array_bounds, > + &out_of_bound); >=20 >=20 > if (!warned && sam =3D=3D special_array_member::int_0) > @@ -373,19 +399,56 @@ array_bounds_checker::check_array_ref (location_t l= ocation, tree ref, > "of an interior zero-length array %qT")), > low_sub, artype); >=20 > - if (warned) > + if (warned || out_of_bound) > { > - if (dump_file && (dump_flags & TDF_DETAILS)) > + if (warned && dump_file && (dump_flags & TDF_DETAILS)) > { > fprintf (dump_file, "Array bound warning for "); > dump_generic_expr (MSG_NOTE, TDF_SLIM, ref); > fprintf (dump_file, "\n"); > } >=20 > + /* issue warnings for -Wstrict-flex-arrays according to the level = of > + flag_strict_flex_arrays. */ > + if (out_of_bound && warn_strict_flex_arrays) > + switch (strict_flex_array_level) > + { > + case 3: > + /* Issue additional warnings for trailing arrays [0]. */ > + if (sam =3D=3D special_array_member::trail_0) > + warned =3D warning_at (location, OPT_Wstrict_flex_arrays, > + "trailing array %qT should not be used as " > + "a flexible array member for level 3", > + artype); > + /* FALLTHROUGH. */ > + case 2: > + /* Issue additional warnings for trailing arrays [1]. */ > + if (sam =3D=3D special_array_member::trail_1) > + warned =3D warning_at (location, OPT_Wstrict_flex_arrays, > + "trailing array %qT should not be used as " > + "a flexible array member for level 2 and " > + "above", artype); > + /* FALLTHROUGH. */ > + case 1: > + /* Issue warnings for trailing arrays [n]. */ > + if (sam =3D=3D special_array_member::trail_n) > + warned =3D warning_at (location, OPT_Wstrict_flex_arrays, > + "trailing array %qT should not be used as " > + "a flexible array member for level 1 and " > + "above", artype); > + break; > + case 0: > + /* Do nothing. */ > + break; > + default: > + gcc_unreachable (); > + } > + > /* Avoid more warnings when checking more significant subscripts > of the same expression. */ > ref =3D TREE_OPERAND (ref, 0); > suppress_warning (ref, OPT_Warray_bounds_); > + suppress_warning (ref, OPT_Wstrict_flex_arrays); >=20 > if (decl) > ref =3D decl; > diff --git a/gcc/opts.cc b/gcc/opts.cc > index 73fc97756e4..8db53ad6c77 100644 > --- a/gcc/opts.cc > +++ b/gcc/opts.cc > @@ -1411,6 +1411,14 @@ finish_options (struct gcc_options *opts, struct g= cc_options *opts_set, > opts->x_profile_flag =3D 0; > } >=20 > + if (opts->x_warn_strict_flex_arrays) > + if (opts->x_flag_strict_flex_arrays =3D=3D 0) > + { > + opts->x_warn_strict_flex_arrays =3D 0; > + warning_at (UNKNOWN_LOCATION, 0, > + "%<-Wstrict-flex-arrays%> is ignored when" > + " %<-fstrict-flex-arrays%> does not present"); > + } >=20 > diagnose_options (opts, opts_set, loc); > } > diff --git a/gcc/testsuite/c-c++-common/Wstrict-flex-arrays.c b/gcc/tests= uite/c-c++-common/Wstrict-flex-arrays.c > new file mode 100644 > index 00000000000..72b4b7c6406 > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/Wstrict-flex-arrays.c > @@ -0,0 +1,9 @@ > +/* Test the usage of option -Wstrict-flex-arrays. */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -Wstrict-flex-arrays" } */ > + > +int main(int argc, char *argv[]) > +{ > + return 0; > +} > +/* { dg-warning "is ignored when \'-fstrict-flex-arrays\' does not prese= nt" "" { target *-*-* } 0 } */ > diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-1.c b/gcc/tes= tsuite/gcc.dg/Warray-bounds-flex-arrays-1.c > index d36ba4d86cb..65c9fec43af 100644 > --- a/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-1.c > +++ b/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-1.c > @@ -1,6 +1,6 @@ > -/* Test -fstrict-flex-arrays + -Warray-bounds. */ > +/* Test -fstrict-flex-arrays + -Warray-bounds + -Wstrict-flex-arrays. *= / > /* { dg-do compile} */ > -/* { dg-options "-O2 -fstrict-flex-arrays=3D1 -Warray-bounds" } */ > +/* { dg-options "-O2 -Wstrict-flex-arrays -fstrict-flex-arrays=3D1 -Warr= ay-bounds" } */ >=20 > struct trailing_array_1 { > int a; > @@ -32,6 +32,7 @@ void __attribute__((__noinline__)) stuff( > struct trailing_array_4 *trailing_flex) > { > normal->c[5] =3D 5; /*{ dg-warning "array subscript 5 is above array= bounds of" } */ > + /*{ dg-warning "should not be used as a flexible array member for= level 1 and above" "" { target *-*-* } .-1 } */ > trailing_1->c[2] =3D 2; /* { dg-bogus "array subscript " } */ > trailing_0->c[1] =3D 1; /* { dg-bogus "array subscript " } */ > trailing_flex->c[10] =3D 10; /* { dg-bogus "array subscript " } */ > diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-2.c b/gcc/tes= tsuite/gcc.dg/Warray-bounds-flex-arrays-2.c > index f63206e1948..2b5a895c598 100644 > --- a/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-2.c > +++ b/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-2.c > @@ -1,6 +1,6 @@ > -/* Test -fstrict-flex-arrays + -Warray-bounds. */ > +/* Test -fstrict-flex-arrays + -Warray-bounds + -Wstrict-flex-arrays. *= / > /* { dg-do compile } */ > -/* { dg-options "-O2 -fstrict-flex-arrays=3D2 -Warray-bounds" } */ > +/* { dg-options "-O2 -Wstrict-flex-arrays -fstrict-flex-arrays=3D2 -Warr= ay-bounds" } */ >=20 > struct trailing_array_1 { > int a; > @@ -32,7 +32,9 @@ void __attribute__((__noinline__)) stuff( > struct trailing_array_4 *trailing_flex) > { > normal->c[5] =3D 5; /*{ dg-warning "array subscript 5 is above array= bounds of" } */ > + /*{ dg-warning "should not be used as a flexible array member for= level 1 and above" "" { target *-*-* } .-1 } */ > trailing_1->c[2] =3D 2; /* { dg-warning "array subscript 2 is above a= rray bounds of" } */ > + /* { dg-warning "should not be used as a flexible array member = for level 2 and above" "" { target *-*-* } .-1 } */ > trailing_0->c[1] =3D 1; /* { dg-bogus "array subscript " } */ > trailing_flex->c[10] =3D 10; /* { dg-bogus "array subscript " } */ >=20 > diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-3.c b/gcc/tes= tsuite/gcc.dg/Warray-bounds-flex-arrays-3.c > index e3273714e8b..25b903f2615 100644 > --- a/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-3.c > +++ b/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-3.c > @@ -1,6 +1,6 @@ > -/* Test -fstrict-flex-arrays + -Warray-bounds. */ > +/* Test -fstrict-flex-arrays + -Warray-bounds + -Wstrict-flex-arrays. *= / > /* { dg-do compile } */ > -/* { dg-options "-O2 -fstrict-flex-arrays=3D3 -Warray-bounds" } */ > +/* { dg-options "-O2 -Wstrict-flex-arrays -fstrict-flex-arrays=3D3 -Warr= ay-bounds" } */ >=20 > struct trailing_array_1 { > int a; > @@ -32,8 +32,11 @@ void __attribute__((__noinline__)) stuff( > struct trailing_array_4 *trailing_flex) > { > normal->c[5] =3D 5; /*{ dg-warning "array subscript 5 is above array= bounds of" } */=20 > + /*{ dg-warning "should not be used as a flexible array member for= level 1 and above" "" { target *-*-* } .-1 } */ > trailing_1->c[2] =3D 2; /*{ dg-warning "array subscript 2 is above ar= ray bounds of" } */=20 > + /* { dg-warning "should not be used as a flexible array member = for level 2 and above" "" { target *-*-* } .-1 } */ > trailing_0->c[1] =3D 1; /*{ dg-warning "array subscript 1 is outside = array bounds of" } */=20 > + /* { dg-warning "should not be used as a flexible array member = for level 3" "" { target *-*-* } .-1 } */ > trailing_flex->c[10] =3D 10; /* { dg-bogus "array subscript" } */ >=20 > } > diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-4.c b/gcc/tes= tsuite/gcc.dg/Warray-bounds-flex-arrays-4.c > index cabaea77dc2..5fc500a19ca 100644 > --- a/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-4.c > +++ b/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-4.c > @@ -1,6 +1,6 @@ > -/* Test -fstrict-flex-arrays + -Warray-bounds=3D2. */ > +/* Test -fstrict-flex-arrays + -Warray-bounds=3D2 + -Wstrict-flex-arrays= . */ > /* { dg-do compile } */ > -/* { dg-options "-O2 -fstrict-flex-arrays=3D1 -Warray-bounds=3D2" } */ > +/* { dg-options "-O2 -Wstrict-flex-arrays -fstrict-flex-arrays=3D1 -Warr= ay-bounds=3D2" } */ >=20 > struct trailing_array_1 { > int a; > @@ -32,6 +32,7 @@ void __attribute__((__noinline__)) stuff( > struct trailing_array_4 *trailing_flex) > { > normal->c[5] =3D 5; /*{ dg-warning "array subscript 5 is above array= bounds of" } */ > + /*{ dg-warning "should not be used as a flexible array member for= level 1 and above" "" { target *-*-* } .-1 } */ > trailing_1->c[2] =3D 2; /* { dg-bogus "array subscript " } */ > trailing_0->c[1] =3D 1; /* { dg-bogus "array subscript " } */ > trailing_flex->c[10] =3D 10; /* { dg-bogus "array subscript " } */ > diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-5.c b/gcc/tes= tsuite/gcc.dg/Warray-bounds-flex-arrays-5.c > index 8b7db6e4f39..30bb4ca8832 100644 > --- a/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-5.c > +++ b/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-5.c > @@ -1,6 +1,6 @@ > -/* Test -fstrict-flex-arrays + -Warray-bounds=3D2. */ > +/* Test -fstrict-flex-arrays + -Warray-bounds=3D2 + -Wstrict-flex-arrays= . */ > /* { dg-do compile } */ > -/* { dg-options "-O2 -fstrict-flex-arrays=3D2 -Warray-bounds=3D2" } */ > +/* { dg-options "-O2 -Wstrict-flex-arrays -fstrict-flex-arrays=3D2 -Warr= ay-bounds=3D2" } */ >=20 > struct trailing_array_1 { > int a; > @@ -32,7 +32,9 @@ void __attribute__((__noinline__)) stuff( > struct trailing_array_4 *trailing_flex) > { > normal->c[5] =3D 5; /*{ dg-warning "array subscript 5 is above arra= y bounds of" } */ > + /*{ dg-warning "should not be used as a flexible array member for= level 1 and above" "" { target *-*-* } .-1 } */ > trailing_1->c[2] =3D 2; /*{ dg-warning "array subscript 2 is above ar= ray bounds of" } */ > + /* { dg-warning "should not be used as a flexible array member = for level 2 and above" "" { target *-*-* } .-1 } */ > trailing_0->c[1] =3D 1; /* { dg-bogus "array subscript " } */ > trailing_flex->c[10] =3D 10; /* { dg-bogus "array subscript " } */ >=20 > diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-6.c b/gcc/tes= tsuite/gcc.dg/Warray-bounds-flex-arrays-6.c > index 035bf481396..e847a44516e 100644 > --- a/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-6.c > +++ b/gcc/testsuite/gcc.dg/Warray-bounds-flex-arrays-6.c > @@ -1,6 +1,6 @@ > -/* Test -fstrict-flex-arrays + -Warray-bounds=3D2. */ > +/* Test -fstrict-flex-arrays + -Warray-bounds=3D2 + -Wstrict-flex-arrays= . */ > /* { dg-do compile } */ > -/* { dg-options "-O2 -fstrict-flex-arrays=3D3 -Warray-bounds=3D2" } */ > +/* { dg-options "-O2 -Wstrict-flex-arrays -fstrict-flex-arrays=3D3 -Warr= ay-bounds=3D2" } */ >=20 > struct trailing_array_1 { > int a; > @@ -32,8 +32,11 @@ void __attribute__((__noinline__)) stuff( > struct trailing_array_4 *trailing_flex) > { > normal->c[5] =3D 5; /*{ dg-warning "array subscript 5 is above array= bounds of" } */=20 > + /*{ dg-warning "should not be used as a flexible array member for= level 1 and above" "" { target *-*-* } .-1 } */ > trailing_1->c[2] =3D 2; /*{ dg-warning "array subscript 2 is above ar= ray bounds of" } */ > + /* { dg-warning "should not be used as a flexible array member = for level 2 and above" "" { target *-*-* } .-1 } */ > trailing_0->c[1] =3D 1; /*{ dg-warning "array subscript 1 is outside = array bounds of" } */ > + /* { dg-warning "should not be used as a flexible array member = for level 3" "" { target *-*-* } .-1 } */ > trailing_flex->c[10] =3D 10; /* { dg-bogus "array subscript " } */ >=20 > } > diff --git a/gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c b/gcc/testsuite= /gcc.dg/Wstrict-flex-arrays-2.c > new file mode 100644 > index 00000000000..2e241f96208 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/Wstrict-flex-arrays-2.c > @@ -0,0 +1,39 @@ > +/* Test -Wstrict-flex-arrays. */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -Wstrict-flex-arrays -fstrict-flex-arrays=3D2" } */ > + > +struct trailing_array_1 { > + int a; > + int b; > + int c[4];=20 > +}; > + > +struct trailing_array_2 { > + int a; > + int b; > + int c[1];=20 > +}; > + > +struct trailing_array_3 { > + int a; > + int b; > + int c[0]; > +}; > +struct trailing_array_4 { > + int a; > + int b; > + int c[]; > +}; > + > +void __attribute__((__noinline__)) stuff( > + struct trailing_array_1 *normal, > + struct trailing_array_2 *trailing_1, > + struct trailing_array_3 *trailing_0, > + struct trailing_array_4 *trailing_flex) > +{ > + normal->c[5] =3D 5; /*{ dg-warning "should not be used as a flexibl= e array member for level 1 and above" } */ > + trailing_1->c[2] =3D 2; /* { dg-warning "should not be used as a fle= xible array member for level 2 and above" } */ > + trailing_0->c[1] =3D 1; /* { dg-bogus "should not be used as a flexi= ble array member for level 2 and above" } */ > + trailing_flex->c[10] =3D 10; /* { dg-bogus "should not be used as a = flexible array member for level 2 and above" } */ > + > +} > diff --git a/gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c b/gcc/testsuite= /gcc.dg/Wstrict-flex-arrays-3.c > new file mode 100644 > index 00000000000..97eb65ba0a9 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/Wstrict-flex-arrays-3.c > @@ -0,0 +1,39 @@ > +/* Test -Wstrict-flex-arrays. */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -Wstrict-flex-arrays -fstrict-flex-arrays=3D3" } */ > + > +struct trailing_array_1 { > + int a; > + int b; > + int c[4];=20 > +}; > + > +struct trailing_array_2 { > + int a; > + int b; > + int c[1];=20 > +}; > + > +struct trailing_array_3 { > + int a; > + int b; > + int c[0]; > +}; > +struct trailing_array_4 { > + int a; > + int b; > + int c[]; > +}; > + > +void __attribute__((__noinline__)) stuff( > + struct trailing_array_1 *normal, > + struct trailing_array_2 *trailing_1, > + struct trailing_array_3 *trailing_0, > + struct trailing_array_4 *trailing_flex) > +{ > + normal->c[5] =3D 5; /*{ dg-warning "should not be used as a flexibl= e array member for level 1 and above" } */ > + trailing_1->c[2] =3D 2; /* { dg-warning "should not be used as a fle= xible array member for level 2 and above" } */ > + trailing_0->c[1] =3D 1; /* { dg-warning "should not be used as a fle= xible array member for level 3" } */ > + trailing_flex->c[10] =3D 10; /* { dg-bogus "should not be used as a = flexible array member for level 3" } */ > + > +} > diff --git a/gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c b/gcc/testsuite/g= cc.dg/Wstrict-flex-arrays.c > new file mode 100644 > index 00000000000..110fdc72778 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/Wstrict-flex-arrays.c > @@ -0,0 +1,39 @@ > +/* Test -Wstrict-flex-arrays. */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -Wstrict-flex-arrays -fstrict-flex-arrays=3D1" } */ > + > +struct trailing_array_1 { > + int a; > + int b; > + int c[4];=20 > +}; > + > +struct trailing_array_2 { > + int a; > + int b; > + int c[1];=20 > +}; > + > +struct trailing_array_3 { > + int a; > + int b; > + int c[0]; > +}; > +struct trailing_array_4 { > + int a; > + int b; > + int c[]; > +}; > + > +void __attribute__((__noinline__)) stuff( > + struct trailing_array_1 *normal, > + struct trailing_array_2 *trailing_1, > + struct trailing_array_3 *trailing_0, > + struct trailing_array_4 *trailing_flex) > +{ > + normal->c[5] =3D 5; /*{ dg-warning "should not be used as a flexibl= e array member for level 1 and above" } */ > + trailing_1->c[2] =3D 2; /* { dg-bogus "should not be used as a flexi= ble array member for level 1 and above" } */ > + trailing_0->c[1] =3D 1; /* { dg-bogus "should not be used as a flexi= ble array member for level 1 and above" } */ > + trailing_flex->c[10] =3D 10; /* { dg-bogus "should not be used as a = flexible array member for level 1 and above" } */ > + > +} > diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc > index 3846dc1d849..e6c6c5a301d 100644 > --- a/gcc/tree-vrp.cc > +++ b/gcc/tree-vrp.cc > @@ -1087,7 +1087,7 @@ execute_ranger_vrp (struct function *fun, bool warn= _array_bounds_p, > if (dump_file && (dump_flags & TDF_DETAILS)) > ranger->dump (dump_file); >=20 > - if (warn_array_bounds && warn_array_bounds_p) > + if ((warn_array_bounds || warn_strict_flex_arrays) && warn_array_bound= s_p) > { > // Set all edges as executable, except those ranger says aren't. > int non_exec_flag =3D ranger->non_executable_edge_flag; > --=20 > 2.31.1 >=20