From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 010F53858C60 for ; Thu, 2 Feb 2023 14:38:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 010F53858C60 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 (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 312DwgBl031634; Thu, 2 Feb 2023 14:38:10 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=2G/alyiB0uKzNSJPytXV73vKt7PfSxyNH8EIIifAStk=; b=zcqrh+zA/yY6Rd3POgoj4LBdayp25hTmC7j5zsWGrd7SloetRUGueIFfx/M/fwbfklsQ PeydYgoUhVLMw2kXJ3N8PGVKIQYrfRcdKqPuyaToL7lhoVWY2fdouPBLTK+AJnepdSQF xHFKXAiJZkNvwwcjc6sPo400JZ8mZUhScgSWJWsaLe0srj0Jd3Hn4OJObYgEy6JBaTZz LubquPyskwh36+WNNKVxwksxtbBUKydgqeiLAwdSbknUs8EfGN35tX0B3iV2r3ABSbRE GRIjvWun3JD6gOQufgio5l1XMfUQ66TuA4ukgWkeOwwcKyjsWOjpLoOwV4AJ9noOspyJ UQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nfpywjybr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 Feb 2023 14:38:09 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 312EVwih005988; Thu, 2 Feb 2023 14:38:09 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3nct5944hx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 Feb 2023 14:38:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BjKp8gw2jgecvt+QqP8CA0pcvIYEnm5SVGwnC6W+32yM0GBSpPvEQ4jubxg80GtuC0kxDMcSROPBc8SLZAQNmqCqBs5Sr9zjr0/vPWFSiRWqai7agEFkKv3cIZcypSmyt6YbJ6V1gmNOM7VEb/OSSwHZOVzxhXaRRLC72r7SsYSP7lDW5rdm8ex6GLBFCbG/TpOLxMU2bjgMlvyftSQ8mDyeIxw8lPcC/XrcQ8tYU9ek33r1TkDlV3OB8zCOopMtlKpo4anTMJqXTev7LUMo9lokv9x5DRkGE+uTU1/Ac1x0DTp8lcpdtYlUp1mU1DurVUYbTHGoLTjJ6hN/t0gsPg== 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=2G/alyiB0uKzNSJPytXV73vKt7PfSxyNH8EIIifAStk=; b=H8gTjD9jCLO0LKg031p4+Ql51ZvvkY5DyknTRWbLWmt1NwGweQxWLX/rBCY3DtT9hkArj62kL2N0Kn/kMWsg0aB1aY8b3U4xczHkwPf8y+Md/SV8N3p6Nrb1SMggf8K9uYXjKsQWGZxhjRV9oYWTrO2dxXxQR9Bsvyov1pvIWvyMrxIkT0Wc7+pRmh2G1udY54IFh1bTWaInn3vOPbw3Sz+HyFA2cvoj1w3iRqYvZBIPIj/ZxQqd5KDUR2SFh7xSko5KZocinUjopUv4Y1plwXpGa1gQz5Fz28L1M75w8lEpGnqBgO4UtKvLCbLof9b8lR7oqhhD4G0loPf5EHHZVQ== 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=2G/alyiB0uKzNSJPytXV73vKt7PfSxyNH8EIIifAStk=; b=RItpMQFj776hZwCmiRh0+7edZ/sbmGLq6ilxxWy5sIX+L8EuLy97HHXlOp+7jdx1IVO2b9cq9gzaT3MdcJznJlhiuqEZo87ng2tvUX2ZzlcFWzZBXkRFKOkTLjDhTLvIrYd62oUolfeK4rouYzzPVjotcVJk6p0LuZeQn3Kn3m4= Received: from CH2PR10MB4344.namprd10.prod.outlook.com (2603:10b6:610:af::19) by BLAPR10MB5361.namprd10.prod.outlook.com (2603:10b6:208:325::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.22; Thu, 2 Feb 2023 14:38:05 +0000 Received: from CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::c96c:cb50:dea2:2cd2]) by CH2PR10MB4344.namprd10.prod.outlook.com ([fe80::c96c:cb50:dea2:2cd2%5]) with mapi id 15.20.6086.007; Thu, 2 Feb 2023 14:38:05 +0000 From: Qing Zhao To: Richard Biener CC: "gcc-patches@gcc.gnu.org" , "siddhesh@gotplt.org" , "keescook@chromium.org" Subject: Re: [PATCH 1/2] Handle component_ref to a structre/union field including flexible array member [PR101832] Thread-Topic: [PATCH 1/2] Handle component_ref to a structre/union field including flexible array member [PR101832] Thread-Index: AQHZNX31Ed6QQ1+7j0WzPTRpR3Dia665+UIAgAAsBICAASqFgIAAYHEAgAAAkICAAAwiAA== Date: Thu, 2 Feb 2023 14:38:05 +0000 Message-ID: <3B30CFBF-5004-41A4-940D-1F23C010403B@oracle.com> References: <20230131141140.3610133-1-qing.zhao@oracle.com> <20230131141140.3610133-2-qing.zhao@oracle.com> <812910BC-870E-4432-870D-538024F1A510@oracle.com> In-Reply-To: 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_|BLAPR10MB5361:EE_ x-ms-office365-filtering-correlation-id: 5fae9dd1-8fd7-4b2e-e2fc-08db052b183d x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: /Hr/4xJtJw2V0TIcIYzqwtLHcywRORrs6p2tpO/q4bU8PBhXYgWcoZdvZqYDsiNIEpyWUcSw7LpM6yKX/G9cJDgVB+Kb3t7JooI6EWS43EJ/6LqOwOAr0cHxhpY2UsKdk5/0k6UDg3HJ29vxdD7qTn5h1UhZJ+oniX5yRae9WyNlkPRpp7mALeVuelR73sOYP/Yzy7OmDuN++tD3HYTuWgq4sKM5iGzolCmaEl5pEqu+zGR8Ud16vWTovhLkABehIgMOdoubHlNVEXga5UFZ8pOQFMq2qNLZWLv0YwTXDOcEwE92kS4J88MTuusJ4Q549yam4NJpEA5TbLqr11wrY7u9zx64Pbcu2OPBDi+G7UYpmZqQSFUl75tnhaLdRzDLhVZ8XqL26gkFWNuZI+Nds2miaUSto1aJnLe0DklldJC383upsYjnzI5jbZ5tz6ZarEqZRo/yohmM9wDVlpake88Yp6RjPg7j65RMjvvQE7hakY4TH6RKTvs7xWPhvDOwwHnbXfVIyLg+JaggiVHujYNiHIZavM6J9qR64q0ljWPpZhe78TUIdKzFAYB6AEorVjxU3D+yp5MwCdliWPQcUN6ZZEJ282zCcxFyTOWkVcBX+XdvXXdAfboQ5zTsb+Vx521fv0BjI9oiA/7k2DAngH71OVs69lzYScXsZtSS5XW8yKz+a0/mcQd9APUIbNQ+CQWWbdPxgBx9l4f5VULTuExqYHh1vB79qULzU1ZCTIFTE+j2zIv+ejtifQ078/0tG+wiuDEkbln7w3Enn9neOw== 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:(13230025)(39860400002)(396003)(136003)(366004)(376002)(346002)(451199018)(84970400001)(478600001)(36756003)(83380400001)(316002)(54906003)(38070700005)(2616005)(33656002)(5660300002)(66446008)(66556008)(86362001)(38100700002)(30864003)(26005)(186003)(4326008)(66946007)(6916009)(91956017)(71200400001)(122000001)(76116006)(53546011)(64756008)(6486002)(66476007)(2906002)(8936002)(44832011)(8676002)(6506007)(6512007)(41300700001)(45980500001)(559001)(579004);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?At7M9IHDOnkf6nsPXI+rUHgnn0hc1Ob/ydD9bjyyXjd1qKNJcjoealFyNCU3?= =?us-ascii?Q?Ic66qKYNm0UaZf0jCf0uX7lymQ7KMAQ/jtBU7Abby0/h7VBLs8M+bVwlAzyd?= =?us-ascii?Q?vi2BmQoXHbUFB6LYgi0hTs5ZLr0dl490x6W3AEEXodIUoy5mtuKUcxN0UTKz?= =?us-ascii?Q?G2jaBYu6+HsD7+IWJcYTV8ODV7kWyl4WQtFqOq6JgWY9j+h8aPMw0R40YjKs?= =?us-ascii?Q?XeFrm4xNFy0Mwjd5KLdOryZ7J/Z3pvCc/JG0qCEvh2HmMH+Y6yP01hg8mhI0?= =?us-ascii?Q?HyfIByClohPw2ITnv/Zjq8ALvtYtobTnFYxyo0m+PT/3URhYB13ZoxJVT7xG?= =?us-ascii?Q?Yt1OU+UoNG0ajiIxSsu3C6gkN8sFr6gxYIXjCQXqSHQH+rUrCnhZHO0o3u4V?= =?us-ascii?Q?e0H2f7ARwfHFU34k8RsDZmai7vu4LOxm8aDwDPbmIn/38d7MgLn7z/2jtIcR?= =?us-ascii?Q?Lv9Kn7GzneZ8LfJaLBzMvaBNk+y4DLDTCruUn/nQJ0ou9A/+n389QQOq/Ym6?= =?us-ascii?Q?MWcmNcAYsCrKuiYJcBZCE7Qyb4IrDm4VvruKfNWqxL/zBHkqCEmXeAzPUgSK?= =?us-ascii?Q?QDJkP+saVL4Ls8Vuv5W6Nuaa89FXBTVCMnBX3u12yUcglJuvKoNaf669H8uJ?= =?us-ascii?Q?P8WTNuMmEndk8te/lcEyjdSrv4QIlWOd4arbaOe1VB8D7BnUqZXrjwU/HZbD?= =?us-ascii?Q?H6gp0ng3z+CjOL3BUHakXhRjR1deA1W5CH4yXUyuCyjPJaBWwEwV6YIJChmK?= =?us-ascii?Q?IPQxhYNUyOXdRLu1nSnMoL3aVjSFfiHU9iesc8jZvuqYGEKfo0BRy3DNMROw?= =?us-ascii?Q?GaHa1HurYUWOxHyPfqd5y0wdtUqQCRMlef0anBR2JUt3oE7+hNiJa9yiBgsK?= =?us-ascii?Q?gi/OsJnKWKReeml9ajyVzW5oRPZeO+PpIOpF38S3YYurKSzaU2JsQZHVRQMO?= =?us-ascii?Q?LSgTYbm4S8M4N2e0H5vnB1tBbaWTSEslqMffo9xLLLeqyRM4rfNF6/fibSH3?= =?us-ascii?Q?JdyQgAyiEF0O5+by+m1Imrst/uFvjOEp2KCxIWYQ9lpREJXIaDJJqM8GExXL?= =?us-ascii?Q?GwZxyAmXc06CJTMHjfgOsWWqGPSTvfKJXDjx3Xc2b0dM40fq3odZgyhGkBxq?= =?us-ascii?Q?E+t7vayivefw6tssPDKIzyukoDL16cHsZf5XNOZilTvcpTlZ4Gi0em1p5Fg6?= =?us-ascii?Q?SZFLY4w8hOy8Yr1SsfX/vD7RGfINOpYAb3jANmAsJ5mJ0ia5ST4RoIXU6a1W?= =?us-ascii?Q?uhcduozI37bLxgTrh3e9cKp3T237z+nZkOREBDtCetcx32YveOcZnHk8kI8T?= =?us-ascii?Q?MsSWMFuLf6OejTJTAR/yBX2nl2SlJk/MddLOkyQ+H/qEG0q+8T9wZi75uKvt?= =?us-ascii?Q?PyN9PLCYdpMazZSW7U5EQ/OgEKpS4YrwoKQVxkm56Bqu9FWGCYDdJt2yQw65?= =?us-ascii?Q?xkR64nrKt400gftGhfhv9ouwcOjBs5A4akoSp+XtrojpQ2slSKU8fl/kToZk?= =?us-ascii?Q?NW0g00Hi6FWhMYMQVZA3YZy3EHaXuKsKkNKqT+XL2N6q2aCQsTrLKqZ7P4Kt?= =?us-ascii?Q?sQHjaiR2QSr2GI5JLp+Hn6EhHCmcRTsXtymGaRTGFVygyYVm6xFRt6YLhN73?= =?us-ascii?Q?aw=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-ID: <01F3891DAD6558489BDB90A8CB76DC1B@namprd10.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: bDOF841881e7u72DwCn0ac91ep/NHcVcDgin+TTVzWsKcOPAV7gHvcA/fqVsICDhLNWnEa+flQLjkDkT9hDEMATsGV2PnU6cz7phUJ6UfWT6fe5mEYFxgLJ7dE4dcZAK1/kbeFlzRM183CyLu0i56HNPx7En1/qCOSzyDNyNRdel3Kjp92Y7Z2Dpu6XX82d+rCRkHwyG0Qv9Lj1UKDA0PCgyTOQNMZ2bbU7ULXi8pZbsUB9j0gCJhjzG/BSjNHhW2qzSBGnvo19IpDbjkZAMdri7z0eO88Y4soDtvEB1JK9vnsH/8NKZerjhaL86I2NbioYILSxg2oAI5poYwuWQCKWvzM0q05PJqwsWpAtAOlplZ4hXby+O/JCjIPZaijCl+8CqQ7bS4YOgF6zOVb+HCSyDP3WV/V/xvo3/E+VYwzGbD8o5cIDchxJFmvo2fk9WoNT5hYqzaRqLQMySXutIo+hepbkcTvetOHxkuLwL95oGDiGvsdjRjUYu3lxMEVrGzK/cf95f1D7KvuJy1KrAHgBtGA9qtp4UniecXED7+5glEDASIlfvWnbaLC234qOFMZA1xBZ3YzM2jt7EGAfTESH08Hx9hALmu/mtTWN5NhVf0jcmJjU4mcoq+vYI7dIQnFWUp0Hg1m9FyDJRHoTzoWORwp8g6YUlfsU9+bx0dainL0Yw3ICRc4WSyK1AxTBn4J+uIgx7u686KDJY9Q8loYbs1HhpNCbGKhy3C4hiNFHDTkM36LU+q0EtgYz1CO9mLVfTxejXk2s8tN2QzP4TD+2F7CK4gvz9xsgZS29n/hEWm0mQDFmq06qNA6YTvjIwCYFAid4wCnVWOkvvZzlRjw== 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: 5fae9dd1-8fd7-4b2e-e2fc-08db052b183d X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Feb 2023 14:38:05.1186 (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: rt2nEoKLQhnngwJ3CoiEltOt0fuXYwyNv2Pmsuc5AxxqgdJTKR5lA2geqYPYIShGHqxVCUmWVcq5OyPziBG8SA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB5361 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.930,Hydra:6.0.562,FMLib:17.11.122.1 definitions=2023-02-02_04,2023-02-02_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 mlxscore=0 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302020132 X-Proofpoint-GUID: NyyAPHlLLlhZzs2nZQiWyF6RkQnmqg1k X-Proofpoint-ORIG-GUID: NyyAPHlLLlhZzs2nZQiWyF6RkQnmqg1k X-Spam-Status: No, score=-11.5 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: > On Feb 2, 2023, at 8:54 AM, Richard Biener wrote: >=20 > On Thu, 2 Feb 2023, Qing Zhao wrote: >=20 >>=20 >>=20 >>> On Feb 2, 2023, at 3:07 AM, Richard Biener wrote: >>>=20 >>> On Wed, 1 Feb 2023, Qing Zhao wrote: >>>=20 >>>>=20 >>>>=20 >>>>> On Feb 1, 2023, at 6:41 AM, Richard Biener wrote: >>>>>=20 >>>>> On Tue, 31 Jan 2023, Qing Zhao wrote: >>>>>=20 >>>>>> GCC extension accepts the case when a struct with a flexible array m= ember >>>>>> is embedded into another struct (possibly recursively). >>>>>> __builtin_object_size should treat such struct as flexible size per >>>>>> -fstrict-flex-arrays. >>>>>>=20 >>>>>> PR tree-optimization/101832 >>>>>>=20 >>>>>> gcc/ChangeLog: >>>>>>=20 >>>>>> PR tree-optimization/101832 >>>>>> * tree-object-size.cc (flexible_size_type_p): New function. >>>>>> (addr_object_size): Handle structure/union type when it has >>>>>> flexible size. >>>>>>=20 >>>>>> gcc/testsuite/ChangeLog: >>>>>>=20 >>>>>> PR tree-optimization/101832 >>>>>> * gcc.dg/builtin-object-size-pr101832-2.c: New test. >>>>>> * gcc.dg/builtin-object-size-pr101832-3.c: New test. >>>>>> * gcc.dg/builtin-object-size-pr101832-4.c: New test. >>>>>> * gcc.dg/builtin-object-size-pr101832.c: New test. >>>>>> --- >>>>>> .../gcc.dg/builtin-object-size-pr101832-2.c | 135 ++++++++++++++++= ++ >>>>>> .../gcc.dg/builtin-object-size-pr101832-3.c | 135 ++++++++++++++++= ++ >>>>>> .../gcc.dg/builtin-object-size-pr101832-4.c | 135 ++++++++++++++++= ++ >>>>>> .../gcc.dg/builtin-object-size-pr101832.c | 119 +++++++++++++++ >>>>>> gcc/tree-object-size.cc | 115 +++++++++++---- >>>>>> 5 files changed, 611 insertions(+), 28 deletions(-) >>>>>> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-pr101832= -2.c >>>>>> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-pr101832= -3.c >>>>>> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-pr101832= -4.c >>>>>> create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-pr101832= .c >>>>>>=20 >>>>>> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-pr101832-2.c b= /gcc/testsuite/gcc.dg/builtin-object-size-pr101832-2.c >>>>>> new file mode 100644 >>>>>> index 00000000000..f38babc5415 >>>>>> --- /dev/null >>>>>> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-pr101832-2.c >>>>>> @@ -0,0 +1,135 @@ >>>>>> +/* PR 101832:=20 >>>>>> + GCC extension accepts the case when a struct with a flexible arr= ay member >>>>>> + is embedded into another struct (possibly recursively). >>>>>> + __builtin_object_size will treat such struct as flexible size pe= r >>>>>> + -fstrict-flex-arrays. */=20 >>>>>> +/* { dg-do run } */ >>>>>> +/* { dg-options "-O2 -fstrict-flex-arrays=3D1" } */ >>>>>> + >>>>>> +#include >>>>>> + >>>>>> +unsigned n_fails =3D 0; >>>>>> + >>>>>> +#define expect(p, _v) do { \ >>>>>> + size_t v =3D _v; \ >>>>>> + if (p =3D=3D v) \ >>>>>> + printf("ok: %s =3D=3D %zd\n", #p, p); \ >>>>>> + else {\ >>>>>> + printf("WAT: %s =3D=3D %zd (expected %zd)\n", #p, p, v); \ >>>>>> + n_fails++; \ >>>>>> + } \ >>>>>> +} while (0); >>>>>> + >>>>>> +struct A { >>>>>> + int n; >>>>>> + char data[];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct B { >>>>>> + int m; >>>>>> + struct A a; >>>>>> +}; >>>>>> + >>>>>> +struct C { >>>>>> + int q; >>>>>> + struct B b; >>>>>> +}; >>>>>> + >>>>>> +struct A0 { >>>>>> + int n; >>>>>> + char data[0];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct B0 { >>>>>> + int m; >>>>>> + struct A0 a; >>>>>> +}; >>>>>> + >>>>>> +struct C0 { >>>>>> + int q; >>>>>> + struct B0 b; >>>>>> +}; >>>>>> + >>>>>> +struct A1 { >>>>>> + int n; >>>>>> + char data[1];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct B1 { >>>>>> + int m; >>>>>> + struct A1 a; >>>>>> +}; >>>>>> + >>>>>> +struct C1 { >>>>>> + int q; >>>>>> + struct B1 b; >>>>>> +}; >>>>>> + >>>>>> +struct An { >>>>>> + int n; >>>>>> + char data[8];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct Bn { >>>>>> + int m; >>>>>> + struct An a; >>>>>> +}; >>>>>> + >>>>>> +struct Cn { >>>>>> + int q; >>>>>> + struct Bn b; >>>>>> +}; >>>>>> + >>>>>> +volatile void *magic1, *magic2; >>>>>> + >>>>>> +int main(int argc, char *argv[]) >>>>>> +{ >>>>>> + struct B *outer; >>>>>> + struct C *outest; >>>>>> + >>>>>> + /* Make sure optimization can't find some other object size. */ >>>>>> + outer =3D (void *)magic1; >>>>>> + outest =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outer->a, 1), -1); >>>>>> + expect(__builtin_object_size(&outest->b, 1), -1); >>>>>> + expect(__builtin_object_size(&outest->b.a, 1), -1); >>>>>> + >>>>>> + struct B0 *outer0; >>>>>> + struct C0 *outest0; >>>>>> + >>>>>> + /* Make sure optimization can't find some other object size. */ >>>>>> + outer0 =3D (void *)magic1; >>>>>> + outest0 =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outer0->a, 1), -1); >>>>>> + expect(__builtin_object_size(&outest0->b, 1), -1); >>>>>> + expect(__builtin_object_size(&outest0->b.a, 1), -1); >>>>>> + >>>>>> + struct B1 *outer1; >>>>>> + struct C1 *outest1; >>>>>> + >>>>>> + /* Make sure optimization can't find some other object size. */ >>>>>> + outer1 =3D (void *)magic1; >>>>>> + outest1 =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outer1->a, 1), -1); >>>>>> + expect(__builtin_object_size(&outest1->b, 1), -1); >>>>>> + expect(__builtin_object_size(&outest1->b.a, 1), -1); >>>>>> + >>>>>> + struct Bn *outern; >>>>>> + struct Cn *outestn; >>>>>> + >>>>>> + /* Make sure optimization can't find some other object size. */ >>>>>> + outern =3D (void *)magic1; >>>>>> + outestn =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outern->a, 1), sizeof(outern->a))= ; >>>>>> + expect(__builtin_object_size(&outestn->b, 1), sizeof(outestn->b= )); >>>>>> + expect(__builtin_object_size(&outestn->b.a, 1), sizeof(outestn-= >b.a)); >>>>>> + >>>>>> + if (n_fails > 0) >>>>>> + __builtin_abort (); >>>>>> + >>>>>> + return 0; >>>>>> +} >>>>>> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-pr101832-3.c b= /gcc/testsuite/gcc.dg/builtin-object-size-pr101832-3.c >>>>>> new file mode 100644 >>>>>> index 00000000000..aaae99b8d67 >>>>>> --- /dev/null >>>>>> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-pr101832-3.c >>>>>> @@ -0,0 +1,135 @@ >>>>>> +/* PR 101832:=20 >>>>>> + GCC extension accepts the case when a struct with a flexible arr= ay member >>>>>> + is embedded into another struct (possibly recursively). >>>>>> + __builtin_object_size will treat such struct as flexible size pe= r >>>>>> + -fstrict-flex-arrays. */ >>>>>> +/* { dg-do run } */ >>>>>> +/* { dg-options "-O2 -fstrict-flex-arrays=3D2" } */ >>>>>> + >>>>>> +#include >>>>>> + >>>>>> +unsigned n_fails =3D 0; >>>>>> + >>>>>> +#define expect(p, _v) do { \ >>>>>> + size_t v =3D _v; \ >>>>>> + if (p =3D=3D v) \ >>>>>> + printf("ok: %s =3D=3D %zd\n", #p, p); \ >>>>>> + else {\ >>>>>> + printf("WAT: %s =3D=3D %zd (expected %zd)\n", #p, p, v); \ >>>>>> + n_fails++; \ >>>>>> + } \ >>>>>> +} while (0); >>>>>> + >>>>>> +struct A { >>>>>> + int n; >>>>>> + char data[];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct B { >>>>>> + int m; >>>>>> + struct A a; >>>>>> +}; >>>>>> + >>>>>> +struct C { >>>>>> + int q; >>>>>> + struct B b; >>>>>> +}; >>>>>> + >>>>>> +struct A0 { >>>>>> + int n; >>>>>> + char data[0];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct B0 { >>>>>> + int m; >>>>>> + struct A0 a; >>>>>> +}; >>>>>> + >>>>>> +struct C0 { >>>>>> + int q; >>>>>> + struct B0 b; >>>>>> +}; >>>>>> + >>>>>> +struct A1 { >>>>>> + int n; >>>>>> + char data[1];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct B1 { >>>>>> + int m; >>>>>> + struct A1 a; >>>>>> +}; >>>>>> + >>>>>> +struct C1 { >>>>>> + int q; >>>>>> + struct B1 b; >>>>>> +}; >>>>>> + >>>>>> +struct An { >>>>>> + int n; >>>>>> + char data[8];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct Bn { >>>>>> + int m; >>>>>> + struct An a; >>>>>> +}; >>>>>> + >>>>>> +struct Cn { >>>>>> + int q; >>>>>> + struct Bn b; >>>>>> +}; >>>>>> + >>>>>> +volatile void *magic1, *magic2; >>>>>> + >>>>>> +int main(int argc, char *argv[]) >>>>>> +{ >>>>>> + struct B *outer; >>>>>> + struct C *outest; >>>>>> + >>>>>> + /* Make sure optimization can't find some other object size. */ >>>>>> + outer =3D (void *)magic1; >>>>>> + outest =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outer->a, 1), -1); >>>>>> + expect(__builtin_object_size(&outest->b, 1), -1); >>>>>> + expect(__builtin_object_size(&outest->b.a, 1), -1); >>>>>> + >>>>>> + struct B0 *outer0; >>>>>> + struct C0 *outest0; >>>>>> + >>>>>> + /* Make sure optimization can't find some other object size. */ >>>>>> + outer0 =3D (void *)magic1; >>>>>> + outest0 =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outer0->a, 1), -1); >>>>>> + expect(__builtin_object_size(&outest0->b, 1), -1); >>>>>> + expect(__builtin_object_size(&outest0->b.a, 1), -1); >>>>>> + >>>>>> + struct B1 *outer1; >>>>>> + struct C1 *outest1; >>>>>> + >>>>>> + /* Make sure optimization can't find some other object size. */ >>>>>> + outer1 =3D (void *)magic1; >>>>>> + outest1 =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outer1->a, 1), sizeof(outer1->a))= ; >>>>>> + expect(__builtin_object_size(&outest1->b, 1), sizeof(outest1->b= )); >>>>>> + expect(__builtin_object_size(&outest1->b.a, 1), sizeof(outest1-= >b.a)); >>>>>> + >>>>>> + struct Bn *outern; >>>>>> + struct Cn *outestn; >>>>>> + >>>>>> + /* Make sure optimization can't find some other object size. */ >>>>>> + outern =3D (void *)magic1; >>>>>> + outestn =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outern->a, 1), sizeof(outern->a))= ; >>>>>> + expect(__builtin_object_size(&outestn->b, 1), sizeof(outestn->b= )); >>>>>> + expect(__builtin_object_size(&outestn->b.a, 1), sizeof(outestn-= >b.a)); >>>>>> + >>>>>> + if (n_fails > 0) >>>>>> + __builtin_abort (); >>>>>> + >>>>>> + return 0; >>>>>> +} >>>>>> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-pr101832-4.c b= /gcc/testsuite/gcc.dg/builtin-object-size-pr101832-4.c >>>>>> new file mode 100644 >>>>>> index 00000000000..424264e2acd >>>>>> --- /dev/null >>>>>> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-pr101832-4.c >>>>>> @@ -0,0 +1,135 @@ >>>>>> +/* PR 101832:=20 >>>>>> + GCC extension accepts the case when a struct with a flexible arr= ay member >>>>>> + is embedded into another struct (possibly recursively). >>>>>> + __builtin_object_size will treat such struct as flexible size pe= r >>>>>> + -fstrict-flex-arrays. */ >>>>>> +/* { dg-do run } */ >>>>>> +/* { dg-options "-O2 -fstrict-flex-arrays=3D3" } */ >>>>>> + >>>>>> +#include >>>>>> + >>>>>> +unsigned n_fails =3D 0; >>>>>> + >>>>>> +#define expect(p, _v) do { \ >>>>>> + size_t v =3D _v; \ >>>>>> + if (p =3D=3D v) \ >>>>>> + printf("ok: %s =3D=3D %zd\n", #p, p); \ >>>>>> + else {\ >>>>>> + printf("WAT: %s =3D=3D %zd (expected %zd)\n", #p, p, v); \ >>>>>> + n_fails++; \ >>>>>> + } \ >>>>>> +} while (0); >>>>>> + >>>>>> +struct A { >>>>>> + int n; >>>>>> + char data[];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct B { >>>>>> + int m; >>>>>> + struct A a; >>>>>> +}; >>>>>> + >>>>>> +struct C { >>>>>> + int q; >>>>>> + struct B b; >>>>>> +}; >>>>>> + >>>>>> +struct A0 { >>>>>> + int n; >>>>>> + char data[0];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct B0 { >>>>>> + int m; >>>>>> + struct A0 a; >>>>>> +}; >>>>>> + >>>>>> +struct C0 { >>>>>> + int q; >>>>>> + struct B0 b; >>>>>> +}; >>>>>> + >>>>>> +struct A1 { >>>>>> + int n; >>>>>> + char data[1];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct B1 { >>>>>> + int m; >>>>>> + struct A1 a; >>>>>> +}; >>>>>> + >>>>>> +struct C1 { >>>>>> + int q; >>>>>> + struct B1 b; >>>>>> +}; >>>>>> + >>>>>> +struct An { >>>>>> + int n; >>>>>> + char data[8];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct Bn { >>>>>> + int m; >>>>>> + struct An a; >>>>>> +}; >>>>>> + >>>>>> +struct Cn { >>>>>> + int q; >>>>>> + struct Bn b; >>>>>> +}; >>>>>> + >>>>>> +volatile void *magic1, *magic2; >>>>>> + >>>>>> +int main(int argc, char *argv[]) >>>>>> +{ >>>>>> + struct B *outer; >>>>>> + struct C *outest; >>>>>> + >>>>>> + /* Make sure optimization can't find some other object size. */ >>>>>> + outer =3D (void *)magic1; >>>>>> + outest =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outer->a, 1), -1); >>>>>> + expect(__builtin_object_size(&outest->b, 1), -1); >>>>>> + expect(__builtin_object_size(&outest->b.a, 1), -1); >>>>>> + >>>>>> + struct B0 *outer0; >>>>>> + struct C0 *outest0; >>>>>> + >>>>>> + /* Make sure optimization can't find some other object size. */ >>>>>> + outer0 =3D (void *)magic1; >>>>>> + outest0 =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outer0->a, 1), sizeof(outer0->a))= ; >>>>>> + expect(__builtin_object_size(&outest0->b, 1), sizeof(outest0->b= )); >>>>>> + expect(__builtin_object_size(&outest0->b.a, 1), sizeof(outest0-= >b.a)); >>>>>> + >>>>>> + struct B1 *outer1; >>>>>> + struct C1 *outest1; >>>>>> + >>>>>> + /* Make sure optimization can't find some other object size. */ >>>>>> + outer1 =3D (void *)magic1; >>>>>> + outest1 =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outer1->a, 1), sizeof(outer1->a))= ; >>>>>> + expect(__builtin_object_size(&outest1->b, 1), sizeof(outest1->b= )); >>>>>> + expect(__builtin_object_size(&outest1->b.a, 1), sizeof(outest1-= >b.a)); >>>>>> + >>>>>> + struct Bn *outern; >>>>>> + struct Cn *outestn; >>>>>> + >>>>>> + /* Make sure optimization can't find some other object size. */ >>>>>> + outern =3D (void *)magic1; >>>>>> + outestn =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outern->a, 1), sizeof(outern->a))= ; >>>>>> + expect(__builtin_object_size(&outestn->b, 1), sizeof(outestn->b= )); >>>>>> + expect(__builtin_object_size(&outestn->b.a, 1), sizeof(outestn-= >b.a)); >>>>>> + >>>>>> + if (n_fails > 0) >>>>>> + __builtin_abort (); >>>>>> + >>>>>> + return 0; >>>>>> +} >>>>>> diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-pr101832.c b/g= cc/testsuite/gcc.dg/builtin-object-size-pr101832.c >>>>>> new file mode 100644 >>>>>> index 00000000000..8ed6980edf0 >>>>>> --- /dev/null >>>>>> +++ b/gcc/testsuite/gcc.dg/builtin-object-size-pr101832.c >>>>>> @@ -0,0 +1,119 @@ >>>>>> +/* PR 101832:=20 >>>>>> + GCC extension accepts the case when a struct with a flexible arr= ay member >>>>>> + is embedded into another struct (possibly recursively). >>>>>> + __builtin_object_size will treat such struct as flexible size pe= r >>>>>> + -fstrict-flex-arrays. */ >>>>>> +/* { dg-do run } */ >>>>>> +/* { dg-options "-O2" } */ >>>>>> + >>>>>> +#include >>>>>> + >>>>>> +unsigned n_fails =3D 0; >>>>>> + >>>>>> +#define expect(p, _v) do { \ >>>>>> + size_t v =3D _v; \ >>>>>> + if (p =3D=3D v) \ >>>>>> + printf("ok: %s =3D=3D %zd\n", #p, p); \ >>>>>> + else {\ >>>>>> + printf("WAT: %s =3D=3D %zd (expected %zd)\n", #p, p, v); \ >>>>>> + n_fails++; \ >>>>>> + } \ >>>>>> +} while (0); >>>>>> + >>>>>> +struct A { >>>>>> + int n; >>>>>> + char data[];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct B { >>>>>> + int m; >>>>>> + struct A a; >>>>>> +}; >>>>>> + >>>>>> +struct C { >>>>>> + int q; >>>>>> + struct B b; >>>>>> +}; >>>>>> + >>>>>> +struct A0 { >>>>>> + int n; >>>>>> + char data[0];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct B0 { >>>>>> + int m; >>>>>> + struct A0 a; >>>>>> +}; >>>>>> + >>>>>> +struct C0 { >>>>>> + int q; >>>>>> + struct B0 b; >>>>>> +}; >>>>>> + >>>>>> +struct A1 { >>>>>> + int n; >>>>>> + char data[1];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct B1 { >>>>>> + int m; >>>>>> + struct A1 a; >>>>>> +}; >>>>>> + >>>>>> +struct C1 { >>>>>> + int q; >>>>>> + struct B1 b; >>>>>> +}; >>>>>> + >>>>>> +struct An { >>>>>> + int n; >>>>>> + char data[8];/* Content following header */ >>>>>> +}; >>>>>> + >>>>>> +struct Bn { >>>>>> + int m; >>>>>> + struct An a; >>>>>> +}; >>>>>> + >>>>>> +struct Cn { >>>>>> + int q; >>>>>> + struct Bn b; >>>>>> +}; >>>>>> + >>>>>> +volatile void *magic1, *magic2; >>>>>> + >>>>>> +int main(int argc, char *argv[]) >>>>>> +{ >>>>>> + struct B *outer =3D (void *)magic1; >>>>>> + struct C *outest =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outer->a, 1), -1); >>>>>> + expect(__builtin_object_size(&outest->b, 1), -1); >>>>>> + expect(__builtin_object_size(&outest->b.a, 1), -1); >>>>>> + >>>>>> + struct B0 *outer0 =3D (void *)magic1; >>>>>> + struct C0 *outest0 =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outer0->a, 1), -1); >>>>>> + expect(__builtin_object_size(&outest0->b, 1), -1); >>>>>> + expect(__builtin_object_size(&outest0->b.a, 1), -1); >>>>>> + >>>>>> + struct B1 *outer1 =3D (void *)magic1; >>>>>> + struct C1 *outest1 =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outer1->a, 1), -1); >>>>>> + expect(__builtin_object_size(&outest1->b, 1), -1); >>>>>> + expect(__builtin_object_size(&outest1->b.a, 1), -1); >>>>>> + >>>>>> + struct Bn *outern =3D (void *)magic1; >>>>>> + struct Cn *outestn =3D (void *)magic2; >>>>>> + >>>>>> + expect(__builtin_object_size(&outern->a, 1), -1); >>>>>> + expect(__builtin_object_size(&outestn->b, 1), -1); >>>>>> + expect(__builtin_object_size(&outestn->b.a, 1), -1); >>>>>> + >>>>>> + if (n_fails > 0) >>>>>> + __builtin_abort (); >>>>>> + >>>>>> + return 0; >>>>>> +} >>>>>> diff --git a/gcc/tree-object-size.cc b/gcc/tree-object-size.cc >>>>>> index 9a936a91983..56b78ca2a8c 100644 >>>>>> --- a/gcc/tree-object-size.cc >>>>>> +++ b/gcc/tree-object-size.cc >>>>>> @@ -500,6 +500,42 @@ decl_init_size (tree decl, bool min) >>>>>> return size; >>>>>> } >>>>>>=20 >>>>>> +/* Determine whether TYPE is a structure with a flexible array memb= er >>>>>> + per -fstrict-flex-array or a union containing such a structure >>>>>> + (possibly recursively). */ >>>>>> +static bool >>>>>> +flexible_size_type_p (const_tree type) >>>>>> +{ >>>>>> + tree x =3D NULL_TREE; >>>>>> + tree last =3D NULL_TREE; >>>>>> + switch (TREE_CODE (type)) >>>>>> + { >>>>>> + case RECORD_TYPE: >>>>>> + for (x =3D TYPE_FIELDS (type); x !=3D NULL_TREE; x =3D DECL_C= HAIN (x)) >>>>>> + if (TREE_CODE (x) =3D=3D FIELD_DECL) >>>>>> + last =3D x; >>>>>> + if (last =3D=3D NULL_TREE) >>>>>> + return false; >>>>>> + if (TREE_CODE (TREE_TYPE (last)) =3D=3D ARRAY_TYPE >>>>>> + && !DECL_NOT_FLEXARRAY (last)) >>>>>> + return true; >>>>>> + else if (TREE_CODE (TREE_TYPE (last)) =3D=3D RECORD_TYPE >>>>>> + || TREE_CODE (TREE_TYPE (last)) =3D=3D UNION_TYPE) >>>>>> + return flexible_size_type_p (TREE_TYPE (last)); >>>>>=20 >>>>> For types with many members this can become quite slow (IIRC we had >>>>> bugs about similar walks of all fields in types), and this function >>>>> looks like it's invoked multiple times on the same type per TU. >>>>>=20 >>>>> In principle the property is fixed at the time we lay out a record >>>>> type, so we might want to compute it at that time and record the >>>>> result. >>>>=20 >>>> You mean in FE?=20 >>>=20 >>> Yes, either in the frontend or in the middle-ends layout_type. >>>=20 >>>> Yes, that?s better and cleaner. >>>>=20 >>>> I will add one more field in the TYPE structure to record this informa= tion and check this field during middle end. >>>>=20 >>>> I had the same thought in the beginning, but not sure whether adding a= =20 >>>> new field in IR is necessary or not, other places in middle end might= =20 >>>> not use this new field. >>>=20 >>> It might be interesting to search for other code walking all fields of >>> a type to determine this or similar info. >>=20 >> There is one which is defined in tree.cc but only is referenced in c/c-d= ecl.cc: >>=20 >> /* Determine whether TYPE is a structure with a flexible array member, >> or a union containing such a structure (possibly recursively). */ >> flexible_array_type_p >>=20 >> However, this routine is a little different than the one I tried to add: >>=20 >> In the current routine ?flexible_array_type_p?, only one level nesting = in the structure is accepted, multiple nesting in structure is not permitte= d. >>=20 >> So, my question is: shall we accept multiple nesting in structure? i.e. >=20 > If we don't reject the testcase with an error, then yes. Gcc currently accepts the multiple nesting in structure without error. So,= we will continue to accept such extension as long as the flex array is at = the end of the structure. At the same time, for the case the flex array is in the middle of the struc= ture, issue additional warnings now to discourage such usage, and deprecate= this case in a future release.=20 Does this sound reasonable?=20 Qing >=20 >> struct A { >> int n; >> char data[];/* Content following header */ >> }; >>=20 >> struct B { >> int m; >> struct A a; >> }; >>=20 >> struct C { >> int q; >> struct B b; >> }; >>=20 >> Qing >>>=20 >>>> thanks. >>>>=20 >>>> Qing >>>>=20 >>>>>=20 >>>>>> + return false; >>>>>> + case UNION_TYPE: >>>>>> + for (x =3D TYPE_FIELDS (type); x !=3D NULL_TREE; x =3D DECL_C= HAIN (x)) >>>>>> + { >>>>>> + if (TREE_CODE (x) =3D=3D FIELD_DECL >>>>>> + && flexible_array_type_p (TREE_TYPE (x))) >>>>>> + return true; >>>>>> + } >>>>>> + return false; >>>>>> + default: >>>>>> + return false; >>>>>> + } >>>>>> +} >>>>>> + >>>>>> /* Compute __builtin_object_size for PTR, which is a ADDR_EXPR. >>>>>> OBJECT_SIZE_TYPE is the second argument from __builtin_object_size. >>>>>> If unknown, return size_unknown (object_size_type). */ >>>>>> @@ -633,45 +669,68 @@ addr_object_size (struct object_size_info *osi= , const_tree ptr, >>>>>> v =3D NULL_TREE; >>>>>> break; >>>>>> case COMPONENT_REF: >>>>>> - if (TREE_CODE (TREE_TYPE (v)) !=3D ARRAY_TYPE) >>>>>> + /* When the ref is not to an array, a record or a union, it >>>>>> + will not have flexible size, compute the object size >>>>>> + directly. */ >>>>>> + if ((TREE_CODE (TREE_TYPE (v)) !=3D ARRAY_TYPE) >>>>>> + && (TREE_CODE (TREE_TYPE (v)) !=3D RECORD_TYPE) >>>>>> + && (TREE_CODE (TREE_TYPE (v)) !=3D UNION_TYPE)) >>>>>> { >>>>>> v =3D NULL_TREE; >>>>>> break; >>>>>> } >>>>>> - is_flexible_array_mem_ref =3D array_ref_flexible_size_p (v); >>>>>> - while (v !=3D pt_var && TREE_CODE (v) =3D=3D COMPONENT_REF) >>>>>> - if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0))) >>>>>> - !=3D UNION_TYPE >>>>>> - && TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0))) >>>>>> - !=3D QUAL_UNION_TYPE) >>>>>> - break; >>>>>> - else >>>>>> - v =3D TREE_OPERAND (v, 0); >>>>>> - if (TREE_CODE (v) =3D=3D COMPONENT_REF >>>>>> - && TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0))) >>>>>> - =3D=3D RECORD_TYPE) >>>>>> + /* if the record or union does not have flexible size >>>>>> + compute the object size directly. */ >>>>>> + if (TREE_CODE (TREE_TYPE (v)) =3D=3D RECORD_TYPE >>>>>> + || TREE_CODE (TREE_TYPE (v)) =3D=3D UNION_TYPE) >>>>>> { >>>>>> - /* compute object size only if v is not a >>>>>> - flexible array member. */ >>>>>> - if (!is_flexible_array_mem_ref) >>>>>> + if (!flexible_size_type_p (TREE_TYPE (v))) >>>>>> { >>>>>> v =3D NULL_TREE; >>>>>> break; >>>>>> } >>>>>> - v =3D TREE_OPERAND (v, 0); >>>>>> + else >>>>>> + v =3D TREE_OPERAND (v, 0); >>>>>> } >>>>>> - while (v !=3D pt_var && TREE_CODE (v) =3D=3D COMPONENT_REF) >>>>>> - if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0))) >>>>>> - !=3D UNION_TYPE >>>>>> - && TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0))) >>>>>> - !=3D QUAL_UNION_TYPE) >>>>>> - break; >>>>>> - else >>>>>> - v =3D TREE_OPERAND (v, 0); >>>>>> - if (v !=3D pt_var) >>>>>> - v =3D NULL_TREE; >>>>>> else >>>>>> - v =3D pt_var; >>>>>> + { >>>>>> + /* Now the ref is to an array type. */ >>>>>> + is_flexible_array_mem_ref >>>>>> + =3D array_ref_flexible_size_p (v); >>>>>> + while (v !=3D pt_var && TREE_CODE (v) =3D=3D COMPONENT_REF) >>>>>> + if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0))) >>>>>> + !=3D UNION_TYPE >>>>>> + && TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0))) >>>>>> + !=3D QUAL_UNION_TYPE) >>>>>> + break; >>>>>> + else >>>>>> + v =3D TREE_OPERAND (v, 0); >>>>>> + if (TREE_CODE (v) =3D=3D COMPONENT_REF >>>>>> + && TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0))) >>>>>> + =3D=3D RECORD_TYPE) >>>>>> + { >>>>>> + /* compute object size only if v is not a >>>>>> + flexible array member. */ >>>>>> + if (!is_flexible_array_mem_ref) >>>>>> + { >>>>>> + v =3D NULL_TREE; >>>>>> + break; >>>>>> + } >>>>>> + v =3D TREE_OPERAND (v, 0); >>>>>> + } >>>>>> + while (v !=3D pt_var && TREE_CODE (v) =3D=3D COMPONENT_REF) >>>>>> + if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0))) >>>>>> + !=3D UNION_TYPE >>>>>> + && TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0))) >>>>>> + !=3D QUAL_UNION_TYPE) >>>>>> + break; >>>>>> + else >>>>>> + v =3D TREE_OPERAND (v, 0); >>>>>> + if (v !=3D pt_var) >>>>>> + v =3D NULL_TREE; >>>>>> + else >>>>>> + v =3D pt_var; >>>>>> + } >>>>>> break; >>>>>> default: >>>>>> v =3D pt_var; >>>>>>=20 >>>>>=20 >>>>> --=20 >>>>> Richard Biener >>>>> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuern= berg, >>>>> Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerma= n; >>>>> HRB 36809 (AG Nuernberg) >>>>=20 >>>>=20 >>>=20 >>> --=20 >>> Richard Biener >>> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernbe= rg, >>> Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; >>> HRB 36809 (AG Nuernberg) >>=20 >>=20 >=20 > --=20 > Richard Biener > SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg= , > Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; > HRB 36809 (AG Nuernberg)