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 2EE493858C2F for ; Wed, 1 Feb 2023 18:20:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2EE493858C2F 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 (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 311HwpSO022380; Wed, 1 Feb 2023 18:20:13 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=RFyY+LXWG3H73a+pwOgUHXgob3Mtq5Y/1hglQ0qIrvA=; b=0QFBGsG4B52sYYh057fm/NiRyuQs/xJQUNbhPSW63T7jj540Ag4yeSrMqDla3h1UoIZ2 zcD99VWEZ1LGMDxq64Pt9bytKyilaf16HL3gH181pJXhqn6cNxO2WWzMhXALFHiZz8Jt dqT22uWO1aIX0jK9mSTOA1J6jwKeWDTIK8bqGZqF7xYFICpaUBeNeFUo0i/UNK9xtbuf CeCQpJWzryn68TnsUSK7xk8rYZEJUKzVtn7pwC37DU8UfVoctph4jlGiiZhLh3eDi+Mz Z5WzKNwykogYGhXZdx0Ekea9AQn5QTa74dwlN2ng/KR1GOv3a8wecs/4Yd84XzliXmsx fg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3nfkd1seq6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 Feb 2023 18:20:13 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 311IAHZs031592; Wed, 1 Feb 2023 18:20:11 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2177.outbound.protection.outlook.com [104.47.59.177]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3nct5ef56a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 Feb 2023 18:20:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mYvmae9eJDDr/LiviiL54qbD0B/MIS39OiwyJVHVPOq6afB2/KaeX3JbiibiUw+nUp1JKJgaSRA3BbSf9aRDBHoOoXczCjbX2OTxRDWVwzYWfI/W9fxaHlbWmyHI9A0aZAu9+HJ4ND7LdERacPp5N6QNxyn2dfCDCDjOQo93Ylvw2ue9UENVW/1jgc2WNjP+Ga65JEutj8tFY6DQL70jKSdlwFQv3ATnxoffXvumsNlnh4lng4is4DqzqcNxn07QaLcW3457piFxkx8QheBCP8mGvoxZPYQJjGUt5c2J/ZCj+KB+6nSeZcNk3ZazJurCWkrv7yPE0Khemdm1FGwWrA== 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=RFyY+LXWG3H73a+pwOgUHXgob3Mtq5Y/1hglQ0qIrvA=; b=gV/z8oJ0HUBl4d6AKBLkAcCquoSqHeIL8z2+auEOkV1A2FKgRXOck2aqsBk8Gw3nvsM+ZKR6cl0b2zgfCRwXRC0Rs4n3FLRi1RsPVX0lU8RS8NvX9KnrVQi+oAc+dqoq2ArBI1TRhFxA7kQ12HQGwtc/k4Q29LU5fjrm+MeOXVgdMUhKeFlfP82Ap66vIkiBzfvFG0kg8DxcdvskOxI8Xrjvv+7X5Nyr5FP/jWQgWl3WGmvADpcqgPJprve0Vu2HzatYL8LP9mmbvXNzXHSqFcY81Lzib0VaxCH7kv9OqWx09ijSLO4TEj0IBESfIHX2mRuPMOdp2LCCWUCVjB5JQA== 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=RFyY+LXWG3H73a+pwOgUHXgob3Mtq5Y/1hglQ0qIrvA=; b=OWoppIKl/TyrXYlXy/vETozAnLqy1TNkVqfBy4/8tErpCu4X85sMXb4zw96hFcvKf5tnw5xX18wfEOYectZtkvLC0lnd7FLF5wE5wS9LcSYdCswhy5ye9zzU+UN3FYNEjq0/lBz8WOwBDu2YlA5K9tfTZ1Eqh2nXzG6Rx3LaIRA= Received: from CH2PR10MB4344.namprd10.prod.outlook.com (2603:10b6:610:af::19) by CO1PR10MB4802.namprd10.prod.outlook.com (2603:10b6:303:94::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.25; Wed, 1 Feb 2023 18:20:09 +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.6064.021; Wed, 1 Feb 2023 18:20:09 +0000 From: Qing Zhao To: Siddhesh Poyarekar CC: "rguenther@suse.de" , "gcc-patches@gcc.gnu.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+7j0WzPTRpR3Dia666TxWAgAAZjwA= Date: Wed, 1 Feb 2023 18:20:08 +0000 Message-ID: <5B198BEC-C2F1-4465-BC50-4A6B5A7C7B24@oracle.com> References: <20230131141140.3610133-1-qing.zhao@oracle.com> <20230131141140.3610133-2-qing.zhao@oracle.com> <371928ba-f81e-c1ef-70d8-2a2e29abc69c@gotplt.org> In-Reply-To: <371928ba-f81e-c1ef-70d8-2a2e29abc69c@gotplt.org> 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_|CO1PR10MB4802:EE_ x-ms-office365-filtering-correlation-id: b9bf760a-e219-4a2f-6f9c-08db0480f37b x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: qrwTTXfbgLGIOn4x8q34t9fvlR9OMFjO9d1ecFkstQY7B+GnIwrvO/EJXJLFEKz9V//9zP2d36S9QKy8SL9chJNtISOepvfzT1uNhMuHOAR3sqsvBJEb+vQ3xGy8Q2CFxVf0TlMwyAuDzn7eVCG3ou2dlC7UaFhf0QFBAW3meePrSo6/sRTieF9JOex8wkacMlpstOwoEbPBWMl6fnkyLst7ijOZeN8/ZgIX63LRTW05JPRXZB308zMPbV+VzK1wcVTlD5Drs7cVXFkZujKAPy5738Uj3t3xxuuagXdi3RhljMQSPaij04wyyaAxYhQLehksIrm8fiU9FNk7mF6x103bFTJFmos9Cr2L+5QijDYNHW2+U92ThXzp6ByqxHxHg16IAlK79+kHYP9KKdJUxVBaf8p9IztKdKKdBFO2Xlmj65dH3L3pS4jWGnz16LcdH21XpKzuTqToH9skUsSRyOGx8K0bWZXoKkbFqnk7xYTBroHTGEU0JqmSj6fUjQQNktiEdXsZWvuEDKlFibfUOuogCNslpk4Pl1C/7V5RLYtmf40rg+yhK/oViCovBarWLW5Fdf+XP/2ToQOFmNAFtT3mwOFuB8KWqXCX2Oop4CciDoMBuYidIDeih+PNuLZJhkRzjcgimPFvMVtTD25ZfpKlId41L6yYOUwaoSaiI4XVJdcd/UKhOE87eCED20xZWq6OY6yq2NSQhyeZ/JhE8pCLEKkjhxSRzrt/qs7v/oOV3q1ZCEF7+Utku7C6Rge0 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)(346002)(39860400002)(396003)(376002)(366004)(136003)(451199018)(30864003)(44832011)(6512007)(6486002)(71200400001)(33656002)(41300700001)(478600001)(38100700002)(86362001)(316002)(76116006)(66446008)(66946007)(66556008)(66476007)(6916009)(4326008)(64756008)(91956017)(38070700005)(8676002)(54906003)(186003)(26005)(8936002)(36756003)(122000001)(53546011)(5660300002)(6506007)(83380400001)(2616005)(2906002)(84970400001)(45980500001)(579004);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?BgL3o1esX86mA+fxJ4fGBtSqG68nPp72UnmhpYXEcrGfDQEShuy4CSSeE3lw?= =?us-ascii?Q?kn0ndTVOcjxs1AJvZ273TAdT4oK2spNsS2NjJUPuXui6mShfxEmJBG6q1ux+?= =?us-ascii?Q?1uCG3bqvJ7KNY3Z23IbJ8XH5GhX2LVxaQOuA/M5TZDGbTgoXQSmpVjnuTmn/?= =?us-ascii?Q?cdT4MF/Jx7XPnaYdJnEkB2uhCjXAtLoFpzak7J9jVSSadyL1B6vjmeBLAu0O?= =?us-ascii?Q?NifyP9OY+RI+2Zd8IFZZPp7juPRYZ8S5rS8lrL3e4FHiI6H1jdfR9AOOCctl?= =?us-ascii?Q?vipqoXdFdzGxKGo8+Cfu+QZUaHwK6DM0jiBKWoMC60JULFDSMU2NZEWSEVTm?= =?us-ascii?Q?okfa4tIE9iolDIEv42RvRCN6yBK0TFcSHzCVSIUuwQaaus8w5sJaOiZJfz62?= =?us-ascii?Q?u4hAp2wsuqqd7sH+bYhx6D687Ig7ezRwPaSWVZohrp4G1DwyubFwgwYwGXHy?= =?us-ascii?Q?U94ELYfiDg5s++4yoJ4p//eFZKs0Wt50o3vfA5IkNOKk1byWDStVh+IBP3Tx?= =?us-ascii?Q?ghOHCRsTjmxuq7ln/7kxZ5WwAYeFmLqHkI9kFwqaIRS02IZq8o4wV4adKY5k?= =?us-ascii?Q?HhcYS2ghOdIt9VpAuBTbzByLhcX4K5KacVQ5TBtbf2nWM/yfDsI5r3mJHQfr?= =?us-ascii?Q?SDs/yNEAssn/4ryK952+kulXoO6Jt0lhWPbY/PV3GpZCYqL748R3hG1yI+mG?= =?us-ascii?Q?8b4NrFjWm3VXFRLeudbloVn8gNjo6WdDwSDc62oYIAqH2oPn9WAtpmBIX8P+?= =?us-ascii?Q?DUY+aLDx9hBAFyrfsQikpuTsz5MGrhVcgU/A0nv0weNa+32shDgIJx/tWXMQ?= =?us-ascii?Q?eub7zLDGbaWqU4EaZBJsRqyTe2l/FIsQ7yBDazClyZIz1WySvp1dXQ82ILg5?= =?us-ascii?Q?z6v8Qp+NUJeIiSwntVuHeBZKc+LqBF7kyHgdM3GPddXQ6/ll9KiMeJHBLMeY?= =?us-ascii?Q?LMKpmGCMg7JyQS5UUHF4CUPesj75YZjAGl06JGJ8tU2xudSgslS6cuygJZmP?= =?us-ascii?Q?hXtcIjVTT7C2LOe1euZf0xbUM6RME1RDxeP1kNIfB69lbPSMHhj1KqIAMtP0?= =?us-ascii?Q?1M8JIkeSw4mCM02HPe7R0iCF9N2WRPoD1yI8VjDtEqGK5V+t/xgdMKDb2BOy?= =?us-ascii?Q?acohNUxQJ3agFKKo83mJ8Ka+G6O7A5CvfCnnBLpFd2pge6TDrvTd4SfGNmE0?= =?us-ascii?Q?iz2Qon7ecd0pGy2+6LHSKKgkfyVNLsjiXsh8jPNbicNujrDJSq6IMjqmJayC?= =?us-ascii?Q?RzelXsaQVEXSIgaQOeannSNA5K6f+xdLEI+vfuoIyAqggg6I5j8Zvzy0McBG?= =?us-ascii?Q?wiTmi5PVDJ3hX8T+/AA2mSeAnVdiHcsjJ9y+4SQcGVhC1yK/0/Ceb+q9GtYO?= =?us-ascii?Q?2srtfbhoJNztBktaI5SgMpiwWXuuL/NIDwabR/u1uJxSEyUgMeU6Ju6UnLDu?= =?us-ascii?Q?V3fKOTqJetspgj78TRnP+PEY29y+Qsgjh+c+M8uMFp6BnW7fx7Mp8Zwmpy5X?= =?us-ascii?Q?i8biV6Xo+/E4sbs4nvW1hnZeXdKW2lH2PRnj+lPoxWUFt2wB1QQhgplYo578?= =?us-ascii?Q?K0GIMro5aEM2VCR7HGQcdOfZvTgI6bQE9E1RD0T5GqjE6KG3/yL0afh0w/Hg?= =?us-ascii?Q?QQ=3D=3D?= Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: mFsBMvFYYgmFD6HlGvp2U7IbfysLNUQnZbHUmNfYt5yHnxqAmRjx8uHpNfzKe3lWBrX1+6XmlYqKnQHSy0QuEcUMLfB1gRnzQbP8Q5n97kwqyNBOP4ktyciZhjj1IkMNots0+FaH7sPRavYbm0bewokoOwiNRD+8yKKljDXuH3j0MfwI6J/mTInaAcERaf1PatfdQ2YDQKXmR5hMsCpDz4mJvB7xTaNEwGwPg3+DTxjwJ5fDtunIqs8aCai1hccSG2+Y6oJMyf325KQweRxEaFlKK4EMqOBkHBGXIlQ+XH0LAO3e0nWxkosLtofIlBtDMdO9WXd/EDWq5oyAHVgsspRwwNmhQkkPcxz6HGNF9uSsjo4c6Ly5SSSZIZWjdhWlgBP4FbXH9Q49DobXDW/8TUm9qkDeZBcY+DJeGCOHsfXi28u1/6qjhv15Qjg0jqpZ2CF7aTcz8W6E8ZDBrQLdx1ep36pBfWYSxK6EXqso0S7CSad4kcHQt90VOdhMFYvQy2qWHhUR7oqszW5dyQ7RiQ8AW6LiSZ1mZCEB3WG/DLt79XvLm+Gv4bgrA1d+sP9X2a/+BWQjFubvN9DTRPQbxEhOeA3vth8LRwz+bE7ictMPFvy7S4EBO76gST5mDS2QRxUSv8H4606ZHYQDJKn2xJxdkTX4XxC4M0ZiDtYEhTBWQyzwhlaX3Ct25O2qUvqFFNs/0GygGWx2xICt6p+c+t7a06c3nj7md9YgGlk27I2K+NIMCjiuHv2PGunXYQzWKR4KjG5ffZedwKpHsyyzHxkS55wCIik9ZQDqwxraR3oPJ6RnYzbov/t8kRJDcHyVHJarIEUyrG71wmJ9xqk7Mw== 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: b9bf760a-e219-4a2f-6f9c-08db0480f37b X-MS-Exchange-CrossTenant-originalarrivaltime: 01 Feb 2023 18:20:09.0022 (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: sS2Njj13ztHX5B+akzdt3Nn4p2gd6emfbwPLbrmTpKBw3FdbCCMFC3jnWSjm1sZW2QXsu6/jE17+kphUkZyZ3w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4802 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-01_04,2023-01-31_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2302010158 X-Proofpoint-GUID: J5POAD_bH6kUpWfmqi3IiIpIkgojuzbm X-Proofpoint-ORIG-GUID: J5POAD_bH6kUpWfmqi3IiIpIkgojuzbm 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: Siddhesh, Thanks. I will update the testing case per your change. Qing > On Feb 1, 2023, at 11:48 AM, Siddhesh Poyarekar wro= te: >=20 > On 2023-01-31 09:11, Qing Zhao wrote: >> GCC extension accepts the case when a struct with a flexible array membe= r >> is embedded into another struct (possibly recursively). >> __builtin_object_size should treat such struct as flexible size per >> -fstrict-flex-arrays. >> PR tree-optimization/101832 >> gcc/ChangeLog: >> 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. >> gcc/testsuite/ChangeLog: >> 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 >> 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: >> + GCC extension accepts the case when a struct with a flexible array m= ember >> + is embedded into another struct (possibly recursively). >> + __builtin_object_size will treat such struct as flexible size per >> + -fstrict-flex-arrays. */ >> +/* { 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++; \ >=20 > I just pushed my testsuite fix, so you could use the macros in gcc.dg/bui= ltin-object-size-common.h instead of accounting this yourself. >=20 > Also if you use __builtin_printf, you won't have to include stdio.h. >=20 > Thanks, > Sid >=20 >> + } \ >> +} 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: >> + GCC extension accepts the case when a struct with a flexible array m= ember >> + is embedded into another struct (possibly recursively). >> + __builtin_object_size will treat such struct as flexible size per >> + -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: >> + GCC extension accepts the case when a struct with a flexible array m= ember >> + is embedded into another struct (possibly recursively). >> + __builtin_object_size will treat such struct as flexible size per >> + -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/gcc/t= estsuite/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: >> + GCC extension accepts the case when a struct with a flexible array m= ember >> + is embedded into another struct (possibly recursively). >> + __builtin_object_size will treat such struct as flexible size per >> + -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; >> } >> +/* Determine whether TYPE is a structure with a flexible array member >> + 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_CHAIN= (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)); >> + return false; >> + case UNION_TYPE: >> + for (x =3D TYPE_FIELDS (type); x !=3D NULL_TREE; x =3D DECL_CHAIN= (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, co= nst_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;