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 D64763858C50 for ; Tue, 30 Apr 2024 21:36:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D64763858C50 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D64763858C50 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714513004; cv=pass; b=ktXbIFwDk+t5lON6hjGj9sUijZ1IisO/iQG3HF/geSyH6Eoi8Lr7ww7821lsgaOGO1tsecpGp07uiN4t8OlBsfVQoFdbqgSnf8yG8O7Zcs6pTQG0YYrJcx6SpePkVnGba6VaornCr8Al5ztyqIbbZLuQZjbS1UGAwpiVzVtcdeA= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714513004; c=relaxed/simple; bh=JOQejVKJTALDsTWikZGZM9vpNuzPaEDv33yt/d/Icfc=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=yA0PbCJIEfxRme5mZLcgVWkk6ckGvNXDILEvBRBMSHT+vThE08HbKOiFlsoFnIUiioCwRAyNAWifGvBPzQmoLKTD4WggrfZBg8TUeqsnYRIYYefZxYly9zXkva4PM4P50rZO7nZ9DO/oM6V6wH9O6hTrXdm1zOUnJs+amiYsy3Q= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43UKT9GA006777; Tue, 30 Apr 2024 21:36:41 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 : mime-version; s=corp-2023-11-20; bh=xZlCWY00GZbZ1H5SDhhj4B9DVYmbMC2Xc0/SWZPd2KU=; b=PPe331XQkqh7Wvdwj95cVy1rAgb+GrwSFqGDuOUM6sMi/4pCDCM/diqQp6wk3dmYcBHo gXhHxAS4wyQj6TaCKIIkJ73JsMD8+96TOFmEISyUAdwqTGtx5C2B7dN+KGQwaJbYMm3Y nFnjvI3CIN2F5BGXzBzQAmhjEjIIzWUSnBx9gsQJ28Lp4qRsgeodUnHhjC7BdxsJDuc+ DMaEOYGdvbUzmIyMqRlhPCHl4KwgDEyQYtOcNcj+YNSMXTHOpc1gHng/DHPZi8jdfqQh EnE9kgzYc4UbVl40/irhIb4yGbIm0jl4e+tQhE3ryiBXXt846Dmlz/6rpDhs5npZeqBk dQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrqsex4g8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Apr 2024 21:36:40 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43UJg3T7011393; Tue, 30 Apr 2024 21:36:39 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2041.outbound.protection.outlook.com [104.47.56.41]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt8jv8w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Apr 2024 21:36:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gegAsvmAbmWhydYUR2D2BYlSdSIAZX2fDdkDAFSm6gLjvmI3tukV5DMFwqMk823w6PwS+Gx+JuWv3QBBiAoS2cH2g9jGyVap+yQH4ut60SsWNMqYudRYLfQJfu4LMjU15s/ntqzhVLLSMCknq4v/8R3L488rd26k9gE4pAnpVbYnSWrAbp11JTMBXQJthoERgU5K1VpQXHZqkv6mNyqRSSVD7F1mgnVQ+VHtdELFRMhwT4w+DsLD3jRXVsrD2ri4DmsFwEz1XWyC6rpR8PD63pnOQbiH0Nc3jsMv65+0513Pid1AyVHuGnyfhjPriod6GaKh+NDFzo4c9d+nkjhzzg== 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=xZlCWY00GZbZ1H5SDhhj4B9DVYmbMC2Xc0/SWZPd2KU=; b=VpgDJ+4t9Fq4j+UjGd30GQtw8BS+dX/z8VpcFdPxBaHMzRa2m9I7eDYbE84KxJMgp8Onxo68yNq8RvZVNWzhHD8k7KOIN1HwceZZBZzH6ljDdOONbws60+5ee+yH26Ajd2x1aIzEMWjho2ebMfADeApL5H8Ggtsj71nPfC/OLk8LE7n0xK+Qk5aYxYYGHRN5+KH4vFu3EXHTmlR3fYSTK4LaH4s7biD/okbS739QBU63FemZJvuNgMSPpbthVaACXxcP/pm5Wzfk+SzQsLQZj7D13Rr03l7RzSKeey1fatjNHwZCNSjanAfxMLwCbcGO3XDsG7cnZfr8st5otF0A3Q== 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=xZlCWY00GZbZ1H5SDhhj4B9DVYmbMC2Xc0/SWZPd2KU=; b=oIZPU20nLOXCcgkbXK+WiQ7p2Ggrj1mD9/4ppJQkj85JZMbtGX38ddi0JDc5AN6GdjyDdJwSKQj6Q54WMpwXMAwBz50YQjjLY3q8dCL6G6omLyKbUDPrYs0TjCdf4Qz47wlVjBVxhlC2d8Jkm3132LNhATwmqNOjhJ2GJhXhwQg= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by PH7PR10MB6274.namprd10.prod.outlook.com (2603:10b6:510:212::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34; Tue, 30 Apr 2024 21:36:36 +0000 Received: from CY8PR10MB6538.namprd10.prod.outlook.com ([fe80::2dae:7852:9563:b4bc]) by CY8PR10MB6538.namprd10.prod.outlook.com ([fe80::2dae:7852:9563:b4bc%6]) with mapi id 15.20.7519.035; Tue, 30 Apr 2024 21:36:36 +0000 From: Qing Zhao To: Jason Merrill CC: Joseph Myers , Richard Biener , Siddhesh Poyarekar , "uecker@tugraz.at" , Kees Cook , "gcc-patches@gcc.gnu.org" Subject: Re: [PATCH v3 4/4] Update the C FE routine "add_flexible_array_elts_to_size" C++ FE routine "layout_var_decl" to handle the cases when the DECL is union. Thread-Topic: [PATCH v3 4/4] Update the C FE routine "add_flexible_array_elts_to_size" C++ FE routine "layout_var_decl" to handle the cases when the DECL is union. Thread-Index: AQHam0V2plUQgEKS70m3qzbEMpw0drGBVlyA Date: Tue, 30 Apr 2024 21:36:36 +0000 Message-ID: <0E55E654-A549-4901-9B8D-A22F9B3CEAFC@oracle.com> References: <20240430145833.1366425-1-qing.zhao@oracle.com> <20240430145833.1366425-5-qing.zhao@oracle.com> <28d8b00a-f3a5-44b6-be74-c6fdb56fae70@redhat.com> In-Reply-To: <28d8b00a-f3a5-44b6-be74-c6fdb56fae70@redhat.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: Apple Mail (2.3774.500.171.1.1) x-ms-publictraffictype: Email x-ms-traffictypediagnostic: CY8PR10MB6538:EE_|PH7PR10MB6274:EE_ x-ms-office365-filtering-correlation-id: 9fc3426b-6b64-4f4f-d12d-08dc695d9cf9 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0;ARA:13230031|1800799015|376005|366007|38070700009; x-microsoft-antispam-message-info: =?us-ascii?Q?r8zWKAGv6EgPlc3dmWREz/lcrKyvHDPgBraqD5eatj9QRi0AVBvvw/TwGITH?= =?us-ascii?Q?UtN+XHhSnDjd4cHEQGFaErpwbJwEzh2Q/f0D8KAdt9zQu8D9fz/Dt8B9vK7x?= =?us-ascii?Q?6qbMVqMbxQf+VxN7wGedrlaQTdYRVGJW9aCd9TgtYG1weqZ2u86zp1+oHJJI?= =?us-ascii?Q?cH1Js4mCpmJ8RRGdug+P0t+w4vDpH4sPZ0c6z06Vc2oGP9lkQzgqvWbhZi3X?= =?us-ascii?Q?tS/4+OA01q2F6zmHDRXkoJtlPuNxUzuZzrgSF9ScBzYKRxXvUr+INFHN5Tjo?= =?us-ascii?Q?i3L1oG0tSdJfxiKSNH6qPr3M0dPzv8oT3QRMawDxOEjJErzZIelVMsXgnVMm?= =?us-ascii?Q?0T/CedFFBZ3EHuZfeauTWLqQhCDyBAeup3Bu+cUtS4i+PJxXPzEYYrixTY4C?= =?us-ascii?Q?OuaPQJStUCZ2QHdfQfZPNE7MgCsvAnYRo0j3bXvVeHFHesjxJqChc4xG3it/?= =?us-ascii?Q?70jTxd3ms37oOlnUVMy+rLtGcV0BOH7FhJVJdKWX+DQFZgzBojh3QF392Nvc?= =?us-ascii?Q?pE9AvL36IWK7eXEye7RHTo+XLLDRnEtA1bvTfqtrMMsfXDFmPebXTT2mMXRH?= =?us-ascii?Q?dpM0Z4zpkqnfzG4QsHl0woh+OgklKp9+81+McHFiAd6fbSf/zKdT22WXSBIp?= =?us-ascii?Q?ZgJ73nnDCkR+pG3mHdhRE3nnNlGTqVzsDM3jCS7iYUldF5PhKn9qPP+UeSBW?= =?us-ascii?Q?JQTFiLgd0SiUeeNkgeVvqqBkWKw78RJb5tKJroVurfl/GG0GlGF4DOCXPsAd?= =?us-ascii?Q?XdVjkouYudEK0wUfaekBVPfjvubvMiONV4R4Xqt9kzschGqkt2nDGgpOjhQY?= =?us-ascii?Q?m5Ka5cbi4bZ4ZbySJTGJ+np1xIRDkBOYKL+DYjqiKFDIJNwIcITsz4Bnp/xV?= =?us-ascii?Q?gCLNTPlv7DqAAzX1u1AnCnOm07MGSIDFd4c8H0E/Hpnd6Nc8fVI7gRI3DvxE?= =?us-ascii?Q?68ZVb/UMiYx7iUAYwY5/yUwlbkohLZAM3/B/diEWND873upoJCYyvUMTM+Ql?= =?us-ascii?Q?UJOXDbkTdeamP1kmNj8uWBZAjHrJUHyEhjEdspRNmNhU08ANrHMgHgNeaFmj?= =?us-ascii?Q?qInv2EchZcuJ8/7b2cL0bXN4Mhy1QGfMVDZ/arKAGJk7fDwkdzytW2K8C77N?= =?us-ascii?Q?jonKg4NVrh9vrPcyTTTcmhAyAzVJ3h8BdtGRmEyGubi1ZePREPdWTaCBkwYL?= =?us-ascii?Q?pAILwxsNIhED7btrv4534cB+eSS7gcc4QV7heuK1ZtnB5RkGJEsXY6KcpDTg?= =?us-ascii?Q?gVRMoW86Qkt4X34OKeoJooUuV2QeafYrtOGdPWTR+CmmNTLFJpYNuagCg4lQ?= =?us-ascii?Q?EEKuCBSFcFrcJ8C3ca+iB5WafKtG6uWYjoihDucMnrkW2Q=3D=3D?= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CY8PR10MB6538.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(366007)(38070700009);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?VqX8zFyrkavi5HHMynIT+T1X98jg8qpHPxbAoleWkzXJh/oeXtEjKCtyRGMO?= =?us-ascii?Q?Ltg8ZF4mfirtykHM2k5iL/ibd8RMoShcDWVznkufElb6w6xz9+Mjj8U3TMIS?= =?us-ascii?Q?tlywjBlMK3KTZd5JV1I/AUUIWllPUu1mnioerT+HdRZqc8A+nr58SS+tWpiF?= =?us-ascii?Q?DX5VVy/7k8O8yiaLOA0v4zFCwa+HaV5nqLj9Ck07+IrhWwaTRUDDjO4Rzaci?= =?us-ascii?Q?8udVwPR/0e9hB58XrH6LTXZ1QPaBe/7VaXGY+DTUdd3T9cxjzpf6ix8M2RUD?= =?us-ascii?Q?c/K+06cXWf7HsB6SU56y4dM0jVbsXKlK1Zsp67aH6eMNstiQnySHa8Y5TB9K?= =?us-ascii?Q?m6ORQF+xBJa88/8lZf2884VqWY+XBtHeoMkU4w1pnEYythLqYsIz+/Xjf1C+?= =?us-ascii?Q?huh9OTpJdOwCjeBL+0m0/p+f9/f/zx8eONMvVUu2rCrZH6iGqRv+ain5YKBY?= =?us-ascii?Q?LjBQ6t6D37FkYlMHG9a4XBMqGnOuHcFKOczZt8QivvBW7OjLCEW1y836hU1i?= =?us-ascii?Q?4ieiOD8ZtuQ+d1WTDAlCthG1sk2fM+QMykrMPVuLGHO82rDwhPvUxVExT2cQ?= =?us-ascii?Q?w55Q16k46gwLOoNd49+jftm/yYVbU43VgdxgMh+Nxn6lUcCIMW1rzk3rUf5h?= =?us-ascii?Q?EIok9XFeLdu+GYFAXixgvQ1y5ZgiDevT1bXzY6AIzZkJTiF5Xig5pyh2Nn3b?= =?us-ascii?Q?NygkvrFeGCkCX+dsc1uHk7btQs3V8HNDXBiwaQw4sye72XtDM8GXyKUuEqC0?= =?us-ascii?Q?JQbi+x8n88ruNYMlNlGTMgXNSLbKBlGZJb0c7xisePXfJLyM2Wcr5W9tjCNz?= =?us-ascii?Q?47LqdhC12vvG0AgsgWzh9I6kCzyZrwe0IUbYUxe97DNlfLDdB5FrZuL/sABO?= =?us-ascii?Q?AeWG0PrtzIsmbJvaR54tsCu86B4j6ItsJEXQ8xybaUX66rSfhbku1nPbO8+H?= =?us-ascii?Q?gQWXkHriM1wT8UIFsimQCFK7D6w1ID9x4dgWkOBav61tVG5+F6U1O9oaJjQ9?= =?us-ascii?Q?a3JlPEIsdQZf4S62sS30KrKKhCGqwtvIxo0Y35IufPCOaBUwpjIvXGAdDk2Z?= =?us-ascii?Q?6pjAMn6NJHrvVlaCt9nPBnfIeLPvEyibJETWqc9q2q5Nc17rwViNys/2jaU2?= =?us-ascii?Q?XZK6ptAufZ7clV9ZJZxLYCQLUE5pv47eKocegY9P1ttZ601pTDQcIop18p7m?= =?us-ascii?Q?4OYfoKcddjS8GVBo1rVfEI6FmUhR8Ihia3u8ggfyrI2lkO0kdnpKW3Z4VutN?= =?us-ascii?Q?cq0eM2w3OibMu7oZoLEeySX9z/YHVZ61lc+Mq11FxfiQXybpiDAAzq2PB/uk?= =?us-ascii?Q?AVRZrWP6S2yZQHhbVjSuTijPL3Rux0CTdUp/8Nvkx5QQklEfR2SdqwaQy/xw?= =?us-ascii?Q?gGaopaQcaDj2qD4z5YZApa/yXjBwZAt8UCs+cbLL4UdExE4T3xAzBJz4rSf/?= =?us-ascii?Q?MItAhOwUXbHC7lf1R79fvpfmOeOjwufq3mnQvyY5S3k2XSZHxjDjQX0kgKrQ?= =?us-ascii?Q?A/bYfxXFP106MtKRqYCuPR0/sKTSj2imv3K0VqsIASqmsdB1D1KTt0pthz+P?= =?us-ascii?Q?pkETlWEmR15VMm3nT5qi6+/EXK07BBNNqF/mtvkytGYZVfi5RRpgfyizranK?= =?us-ascii?Q?SA=3D=3D?= Content-Type: multipart/alternative; boundary="_000_0E55E654A54949019B8DA22F9B3CEAFCoraclecom_" MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 2GAlVcJjlDiWjN0xZedVnQHtYdGTI4dUzbPvaqtv7EZacUIELK14s0TZwCM1ThNMF+SKrdty5yiDEEFMYxu2NkF5P/+Q5uLF3BRJMKU4DP9JeeAOxiihFFjP+ONIa/DpYZvjYrQ3AF+fgSWvfp0GAQ+mGEcvSudJCcjmsUXA66PKB9+sT4pkOGj48vUETKS4FwUKYilNjrsGH+D0MgxiVrNc6CQolA5mOEKld/riGknS//y7fMjUyZKj83uldnwHcgDj4zJYO2kk/uVy3+GT2GG9pYsGtzwhQG22kD9jQQXAsmsmSh1rkCM7IvYLLVZCMrameTN1VmZ1Jf65BzVRI5AzzYs40GoG10LfNmxEsoiqFby/LvEO0el/2yvgLYgFB0VhZSuNdMCB3CcazjLoeJu1A3KnHl7sY7p83/DC71ccdbjKjEBMZDyu0AlUthf4X3sUnCwnRYD6k2o9Rp58zjA53qJ8Z5yWpHgjff2XJm8jWBRfke6K+FqbJKmOOFWOU9skEb3x54ddowfs5HW7QdWU8SrydT5ix7r/gE+qedBp0hqL/IXWK1Pr1aaBTtYI9AcIntuJaENO1+2btYM5DJNtDOuHuYSkQwzTNpIT4tc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9fc3426b-6b64-4f4f-d12d-08dc695d9cf9 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Apr 2024 21:36:36.5915 (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: AcbCsfJXavi0P0AlgbLcotoVW3womuH8rxOrDuDaRsQHCwOZbjYG3eFlPPteXQ7t0nPhmF283dX0GklkX1NGIw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6274 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-30_13,2024-04-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 mlxscore=0 suspectscore=0 phishscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404300155 X-Proofpoint-ORIG-GUID: jlIionvCuXQCBtvFknf5lRxJVzC8CPkJ X-Proofpoint-GUID: jlIionvCuXQCBtvFknf5lRxJVzC8CPkJ 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,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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: --_000_0E55E654A54949019B8DA22F9B3CEAFCoraclecom_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable On Apr 30, 2024, at 15:29, Jason Merrill wrote: On 4/30/24 07:58, Qing Zhao wrote: Add testing cases to test the _bos for flexible array members in unions or alone in structures. gcc/c/ChangeLog: * c-decl.cc (add_flexible_array_elts_to_size): Handle the cases when the DECL is union. gcc/cp/ChangeLog: * decl.cc (layout_var_decl): Handle the cases when the DECL is union with a flexible array member initializer. gcc/testsuite/ChangeLog: * c-c++-common/fam-in-union-alone-in-struct-bos-1.c: New test. * c-c++-common/fam-in-union-alone-in-struct-bos.c: New test. --- gcc/c/c-decl.cc | 32 +++++++-- gcc/cp/decl.cc | 33 ++++++++-- .../fam-in-union-alone-in-struct-bos-1.c | 66 +++++++++++++++++++ .../fam-in-union-alone-in-struct-bos.c | 45 +++++++++++++ 4 files changed, 162 insertions(+), 14 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct= -bos-1.c create mode 100644 gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct= -bos.c diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 947f3cd589eb..59302c5cfb1f 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -5337,9 +5337,9 @@ zero_length_array_type_p (const_tree type) } /* INIT is a constructor that forms DECL's initializer. If the final - element initializes a flexible array field, add the size of that - initializer to DECL's size. */ - + element initializes a flexible array field, adjust the size of the + DECL with the initializer based on whether the DECL is a union or + a structure. */ static void add_flexible_array_elts_to_size (tree decl, tree init) { @@ -5348,15 +5348,33 @@ add_flexible_array_elts_to_size (tree decl, tree in= it) if (vec_safe_is_empty (CONSTRUCTOR_ELTS (init))) return; + bool is_decl_type_union =3D (TREE_CODE (TREE_TYPE (decl)) =3D=3D UNION_= TYPE); In both C and C++ front-ends, I don't see any reason for this variable to b= e declared outside the if, since it's only used inside it. It's not clear to me that it's needed at all since it's only used once, but= if you prefer to have it, please move it inside the if. Okay, will do that. thanks. Qing + elt =3D CONSTRUCTOR_ELTS (init)->last ().value; type =3D TREE_TYPE (elt); if (flexible_array_member_type_p (type)) { complete_array_type (&type, elt, false); - DECL_SIZE (decl) - =3D size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type)); - DECL_SIZE_UNIT (decl) - =3D size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type)); + /* For a structure, add the size of the initializer to the DECL's + size. */ + if (!is_decl_type_union) + { + DECL_SIZE (decl) + =3D size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type)); + DECL_SIZE_UNIT (decl) + =3D size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), + TYPE_SIZE_UNIT (type)); + } + /* For a union, the DECL's size is the maximum of the current size + and the size of the initializer. */ + else + { + DECL_SIZE (decl) + =3D size_binop (MAX_EXPR, DECL_SIZE (decl), TYPE_SIZE (type)); + DECL_SIZE_UNIT (decl) + =3D size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl), + TYPE_SIZE_UNIT (type)); + } } } diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 9a91c6f80da1..0ea3ef165b66 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -6555,8 +6555,9 @@ layout_var_decl (tree decl) } } - /* If the final element initializes a flexible array field, add the siz= e of - that initializer to DECL's size. */ + /* If the final element initializes a flexible array field, adjust + the size of the DECL with the initializer based on whether the + DECL is a union or a structure. */ if (type !=3D error_mark_node && DECL_INITIAL (decl) && TREE_CODE (DECL_INITIAL (decl)) =3D=3D CONSTRUCTOR @@ -6568,6 +6569,7 @@ layout_var_decl (tree decl) && tree_int_cst_equal (DECL_SIZE (decl), TYPE_SIZE (type))) { constructor_elt &elt =3D CONSTRUCTOR_ELTS (DECL_INITIAL (decl))->las= t (); + bool is_decl_type_union =3D (TREE_CODE (TREE_TYPE (decl)) =3D=3D UNI= ON_TYPE); if (elt.index) { tree itype =3D TREE_TYPE (elt.index); @@ -6577,11 +6579,28 @@ layout_var_decl (tree decl) && TREE_CODE (vtype) =3D=3D ARRAY_TYPE && COMPLETE_TYPE_P (vtype)) { - DECL_SIZE (decl) - =3D size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (vtype)); - DECL_SIZE_UNIT (decl) - =3D size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), - TYPE_SIZE_UNIT (vtype)); + /* For a structure, add the size of the initializer to the DECL's + size. */ + if (!is_decl_type_union) + { + DECL_SIZE (decl) + =3D size_binop (PLUS_EXPR, DECL_SIZE (decl), + TYPE_SIZE (vtype)); + DECL_SIZE_UNIT (decl) + =3D size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), + TYPE_SIZE_UNIT (vtype)); + } + /* a union, the DECL's size is the maximum of the current size + and the size of the initializer. */ + else + { + DECL_SIZE (decl) + =3D size_binop (MAX_EXPR, DECL_SIZE (decl), + TYPE_SIZE (vtype)); + DECL_SIZE_UNIT (decl) + =3D size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl), + TYPE_SIZE_UNIT (vtype)); + } } } } diff --git a/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos-1.= c b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos-1.c new file mode 100644 index 000000000000..aae9cf39c8c7 --- /dev/null +++ b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos-1.c @@ -0,0 +1,66 @@ +/* testing flexible array members in unions and alone in structures: + __bos/__bdos */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +union with_fam_1 { + char a; + int b[]; +} *with_fam_1_v; + +union with_fam_2 { + int a; + char b[]; +} *with_fam_2_v; + +union with_fam_3 { + char a[]; + int b[]; +} *with_fam_3_v; + +struct only_fam { + int b[]; +} *only_fam_v; + +struct only_fam_2 { + unsigned int : 2; + unsigned int : 3; + int b[]; +} *only_fam_2_v; + +void __attribute__((__noinline__)) +setup (int n1, int n2, int n3, int n4, int n5) +{ + with_fam_1_v =3D (union with_fam_1 *) __builtin_malloc (n1 * sizeof (int= )); + with_fam_2_v =3D (union with_fam_2 *) __builtin_malloc (n2 * sizeof (cha= r)); + with_fam_3_v =3D (union with_fam_3 *) __builtin_malloc (n3 * sizeof (int= )); + only_fam_v =3D (struct only_fam *) __builtin_malloc (n4 * sizeof (int)); + only_fam_2_v =3D (struct only_fam_2 *) __builtin_malloc (n5 * sizeof (in= t)); + return; +} + +void __attribute__((__noinline__)) stuff( + union with_fam_1 *with_fam_1_v, + union with_fam_2 *with_fam_2_v, + union with_fam_3 *with_fam_3_v, + struct only_fam *only_fam_v, + struct only_fam_2 *only_fam_2_v) +{ + if (__builtin_object_size(with_fam_1_v->b, 1) !=3D -1) + __builtin_abort (); + if (__builtin_object_size(with_fam_2_v->b, 1) !=3D -1) + __builtin_abort (); + if (__builtin_object_size(with_fam_3_v->b, 1) !=3D -1) + __builtin_abort (); + if (__builtin_object_size(only_fam_v->b, 1) !=3D -1) + __builtin_abort (); + if (__builtin_object_size(only_fam_2_v->b, 1) !=3D -1) + __builtin_abort (); +} + +int main (int argc, char *argv[]) +{ + setup (2, 3, 4, 5, 6); + stuff (with_fam_1_v, with_fam_2_v, with_fam_3_v, only_fam_v, only_fam_2_= v); + return 0; +} diff --git a/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos.c = b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos.c new file mode 100644 index 000000000000..21badc57982b --- /dev/null +++ b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos.c @@ -0,0 +1,45 @@ +/* testing flexible array members in unions and alone in structures: + __bos/__bdos */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +union with_fam_1 { + char a; + int b[]; +} with_fam_1_v =3D {.b =3D {1, 2, 3, 4, 5}}; + +union with_fam_2 { + int a; + char b[]; +} with_fam_2_v =3D {.a =3D 0x1f2f3f4f}; + +union with_fam_3 { + char a[]; + int b[]; +} with_fam_3_v =3D {.b =3D {0x1f2f3f4f, 0x5f6f7f7f}}; + +struct only_fam { + int b[]; +} only_fam_v =3D {{7, 11}}; + +struct only_fam_2 { + unsigned int : 2; + unsigned int : 3; + int b[]; +} only_fam_2_v =3D {{7, 11}}; + +int main () +{ + if (__builtin_object_size(with_fam_1_v.b, 1) !=3D 20) + __builtin_abort (); + if (__builtin_object_size(with_fam_2_v.b, 1) !=3D 4) + __builtin_abort (); + if (__builtin_object_size(with_fam_3_v.b, 1) !=3D 8) + __builtin_abort (); + if (__builtin_object_size(only_fam_v.b, 1) !=3D 8) + __builtin_abort (); + if (__builtin_object_size(only_fam_2_v.b, 1) !=3D 8) + __builtin_abort (); + + return 0; +} --_000_0E55E654A54949019B8DA22F9B3CEAFCoraclecom_--