From patchwork Tue Apr 30 14:58:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 1929648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.a=rsa-sha256 header.s=corp-2023-11-20 header.b=n0eiPmIh; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-oracle-onmicrosoft-com header.b=I44N5bcb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VTNdJ5pMWz23ny for ; Wed, 1 May 2024 00:59:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E8899385EC56 for ; Tue, 30 Apr 2024 14:59:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id 5E8563858D1E for ; Tue, 30 Apr 2024 14:58:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5E8563858D1E 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 5E8563858D1E Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714489130; cv=pass; b=xcvmCazpSEXAC/ouRsw54eODTxfLEiJwwZiLTZC9Lb9jFI2raF1zi4CF47lxPlnUpnDL4LpOXKkbZJtyi0LNXPan42aBHxgy5b26NiNNqvVvOb0PhUF4oLjglRWvqSeY/QvjfJMC5QsSgQFrI3aIW27NIDPQ0Q3ZmsAiPj+Kois= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714489130; c=relaxed/simple; bh=HAv4O68wh8rfLTsufQnoS1dGYkIxUXZ/IYkEsuu9K4w=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=VsPujJxqbh2Re1RDA5JaxvxEfr1TZmzSp6zXRYqNWUsVQJkoxKuGgF+7/jn4A6yuFqqYNnC2AtPVp0/JkYm5o+v1OMBzGV6pR0Ez4+FttausmF4xfEvHGf8CIy1OGqepppRSkN65qzbrbPLyvWtpYRzHDyryaC2XP8Qe0wz8S9U= ARC-Authentication-Results: i=2; server2.sourceware.org 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 43UCWsvs011933; Tue, 30 Apr 2024 14:58:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=ZtqSPD18URvE2Xf0ZV5sIoilEyMj/Q+EjFQ8UguoNIU=; b=n0eiPmIhu3Th6p9zRG9QmJcJEOMtIjsIODwJgiWE0WpeuySlLWPUbjR9Zureyar/Ga21 egc7eJM+xBWpwnDTnCMfUcETVQGGQeUJ9cvsQUJG8pXY2gADOHxy+Iv1+qCOiumxoRu4 XmOX7jD8Dgm64uImksR7p3mVN/JcgKPlhCenhOfMUgbl/8kJ9WSFC0yZV1s48uuf8eGX C+8yEqfUZ+ij32IA3WIgihADNU4+roRgZpTi9rLJzrfjcLHNHQpWwcB4ZjGmzgKHutji 7ukovE2BqWOYIqNmHBLhphQJTetzwsveNVzJ6D6+9Qg+D+4+cyoVU8ktaKKLniVjQVFj 5Q== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrswvnay4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Apr 2024 14:58:44 +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 43UE172C011355; Tue, 30 Apr 2024 14:58:43 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2100.outbound.protection.outlook.com [104.47.70.100]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt827dt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 30 Apr 2024 14:58:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I/hN4QPw8nrKmNhaZTqxSBegn/0Gx61DNwSA6KwB0btB/7VLw82PcxyRNOp3WchKkjpWCnTq2cPBVmJHPJGnqJ1tnSkeUvhv0kVTxL/L9A4vkL8uMdlEmJAoA4Mj1pPH0R6EExIKJSE0brw5R9yrDD0lrBU6jWjq2ilHHIEW/e++PTDAlMcQ4Y+PKj5Y5rHrTimuHpOkEqqIwbEbFQljgLthOhcyY+W0kLhBrMtvIGnKKwy/DvbXj/ayK19fCWl6yOLWHNQcFH0MJqo20kd5bA38xUP9QUUSmq5GVGCmk5+uCQBKniAUP8FOZhasjeGgA2Lv1s3O949bPXX4fZqkMg== 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=ZtqSPD18URvE2Xf0ZV5sIoilEyMj/Q+EjFQ8UguoNIU=; b=iliQJMdG4kUCzY8Rl9JrZn4JceQBdj16B7Xx/tzQVdAXANOlrFQc7XebMiU+juTL/Hj/sZF5TXG37uYw49WyqgJBSCG0ZaCXL6YCQQb+qUhg8fy6P/hKdrWxIaZGlRKe3aoO6xPllxZrPyHMt2ugVf9E93J3zZ2OLYoWkbVwoJQJmuPk/73HXh88RFNARuc2MecHgp8ccAZqwBnBim0XpEAw1HhamK1jhPPODOzr2TzAxRLMPU76cneLvkBLaqT95jJYHmzmV1vQ6yHLfV0WsNxmi/86CHzooXYFl/jyf5gLkorkP6SRPbXh4GrowQqzeK4K2fcAaxg4d5uWiYU4bw== 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=ZtqSPD18URvE2Xf0ZV5sIoilEyMj/Q+EjFQ8UguoNIU=; b=I44N5bcbhzOGMvVbM28sjjH45C9xen8UTc2NJE+WQC5LkRkmkZnbJN3+XGqi8T1qUkPhw9YpUAnZ3sMOCscv38GPsrieZJwos5ExhEv3pVucaeSoyMEfTdvf0kpmHa79rV0s89lsBaFbPXRfhnJQCIGyMmHfpo2cnFgfI5NWb0E= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by MN0PR10MB5984.namprd10.prod.outlook.com (2603:10b6:208:3c8::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.24; Tue, 30 Apr 2024 14:58:40 +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 14:58:40 +0000 From: Qing Zhao To: jason@redhat.com, josmyers@redhat.com, richard.guenther@gmail.com, siddhesh@gotplt.org Cc: uecker@tugraz.at, keescook@chromium.org, gcc-patches@gcc.gnu.org, Qing Zhao Subject: [PATCH v3 1/4] Allow flexible array members in unions and alone in structures [PR53548] Date: Tue, 30 Apr 2024 14:58:30 +0000 Message-Id: <20240430145833.1366425-2-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240430145833.1366425-1-qing.zhao@oracle.com> References: <20240430145833.1366425-1-qing.zhao@oracle.com> X-ClientProxiedBy: BYAPR04CA0014.namprd04.prod.outlook.com (2603:10b6:a03:40::27) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|MN0PR10MB5984:EE_ X-MS-Office365-Filtering-Correlation-Id: 46311265-3334-4d54-a882-08dc692605a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|376005|1800799015|366007; X-Microsoft-Antispam-Message-Info: NkAi5BvtC0goM2e7B7/NGEtFKU091+M+xSUj9tddCpwWfrLmuMfBnHI/AHSP3i/kvjB/h1oSMXjHfk9WCV+0QiEs+vdxXWURZ7zF8lr6dhtHdlrQE7C7neaPsj1PeLp6bBujf5nj+llcvJASzjkp1Q7DoPY86Ihe+b/teqe7Vt6Eho1CTwrwNfpNKwc0NgNL+dUQNB1wnn+n7tDBPF8LWsahuR6TU7FUS4LAwgGzPPprnI3bmrIgtpLLmXaenRInDMAJ7/7wola3d5Cdou+gqOLKHtlWGIrS29Jch3uFqsrsw2ZvaN27LeCxxgMP7CP8sGOzkqbwi+O9GY+U1aexgOX9MevkpjNZwphTXtnnqKhJIuehC5SRv2vOB5DoIKNpayS295R/mWUQeW2k0/za4hZVJ9RR3LOdMa1nFsOYwaNV2Yt6QyOfSMTTJ6vscJfqqfe08J5tJEh7fLJCOBzPAbByO5TOivPKbq4TMD1itoescG5z0T/s/18k/9cu6izgXUpBGC02NAAr6i2VZCR3UbgHG7d7FhChkXFfvp/dILoOTN7E+bF/5/uB1LIaxDeDZjn8564kp/2p+lc2TpCatvrFnUWRHySpLe46168KgHeoKgKpID9ncieNAwyG2xYu0xqdGGJl463RTQJ5O6h3vJyBY16/3f90HOmZgIQQPlKhKA6kHAhcq/sTbuKARGESfGu9kYpXf0WnJrjfBhu/RnUxQTiS5d8wrNMVgUGD/TWj29olAwXlCOWGOxWZRk81RbUMoAiCg2mLKwNr7v365hnJRSAx40cvGQJQA8y1fnwXVHQYKKzNe6yy5X3HDXcHg8wwqbToQdKxRg25WVhhifnDxGg5F5iSMMnIc5ib1gCoKeev+Pq0fEk4EulmKlnA9yQBYutsOyVTfXas3y1fKoRPDks50YYK1Xq7Gg4IG+9OueW9VTld8YNiUYj+xt1garuG4EgHnDtpeN+vZpQ1Q3zgjWNqoAMUeJl2d5ZPW8SAUmvLL4BLsjOBAuwwZLLbgxU18meq1nOf0C4aoOX68a+eeBKFx7mcV1/ZB5KNjzV6fSxfphhb28a979QLj0nFn34o/8kqnF1nBDUmfhmVzgYMA5ZZa358b0FiilRIWWvWE8Q4l80pIJQkaGud7zEW3Bd64r3eSsqEn+vKA8HtHa8q8T9iHZFbqobfCo4oL189Y48l5gh0hiXT8gqg+3g1ub1VdYIo2FLsutqEn0U2e/IMQVEAFU7lUkdgaYqt8V5OJhYipMCeQV2OCiJbAe8f1Kgw5hXDYBG+nRk3hMApcl/2f429BeQWsXpOl4uKUS0= 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)(376005)(1800799015)(366007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tj17HjZWg2g0rBcr3YINMG+3U8LGPQkHtFlOzsr6qq3NHtqQnV3fi1AfFUKnvWLYBplMVGc1lHOxerGUgD+bmDjXZtW1hJrPfuqrzrkvF3O0LNJR8DsrRcZCH0p/Smbob7de0aT1fGU+XwRXB0u/mdWaWgxfOQtoD7GQXcBbuU/SpuZ+R+YTvmSSXFXTK+3Le37BZkzQD2ZvJbgfTZFMSxmim1X2aINJkUq0UgwUryOFPiIhMIWwyRj3eD4sKkYvGf16RtO0PnwK8JvNJHsoWpU9SroQj9BOMleilA7w3OIKVPAm6T2gkYtHM4yt2Y8bV0RYUfqGGjMyqg+SOwFUx25qjfRu+GeFl6ml1h6aOWpzoRUKF/cZYjvP2KeFmgcdlrfsemEZ5Xrm8raDBV4fL901sIA3JrJp7ifcRly82L1HS6o/VOqbDDH7ZJ6eIDEYPM2NZUGif3XOlooh61NPLdrxeDv+3vZV5aTBLhAPmU2VQiGrDrOw3ZdW8BMtelp1kUzQWLOO5ahPVLEbTJTFG3bya0npMsBTZnJ6HkK6D9/8RiWqi9rzTIHER0ZezohWCXPeSle0Peh6gx8aXFGa16jyof2qhMWnds1K78tMWZhXA5evD5u2yiJbe88VYZ+6VF04v3RNjXqCzvG7xQUUmeyXIo6DKJWd7k+2hlGavgRBiTVXOwGk9nSEvfFcxNs3JtswhOpwM+m6OW94zGY3QuonZ8NdMZabbX7sd/6tRZIyZTDKpprhu1qEYkL/NLk71bAF3ArewdYD2ZToh3J0lovMyBZqFgOr5czFrj7f2aRKLckxRPTmXQAeFBEcX0T8Sd3ybNhvkftgMC6O2ErGVYQ7LE4OTlta+QqtmGDdkNG1SuIS7t3RHNEZurgyj3Yx1ydXihTIbLIi65HIBLPAzfm7By/GOEvuOwmreDB4cgHX+MIMvgsWrjJRsNLFK8jG/io6rKn4hradU3u2es+b/524va4JEy7Pdk15bmtCaJFMiAJz5++ZzuIpJjWXpiju2dCZ/WcPM7WXaR59RvVnL6OzYAQygpVvwKJAwrhgJY4OWECGOkBzLljZ4aRAgo5QxYAdW0XMWixPu/U0L76nsieXZScij3qu73606VSOHki7Mq5e8qLMAMxi2dS3Ly2q41xw8tWRzRlMnDUDnyCyKp124Gc6X/KRgfmYEVRCjueTdyLpE23MgzX8iyqYOwHCRXRm7RUOtxqbYHmSKJREioV+4np8+mhmKwVpdVvAb4LXbjhuFF/tg3IAGn21HC1mHPLRZ9VubuhQi8yd3WbiBWDWDN3DznCX1GfFjDDYPheU2rZjtpDaQqN9ban5sad2uco0IkR+yHAaZHYdxSloxMN7SFnUnlPfwM5mUf9NvhaU1zyhqGpQGrmQDGYIrJPguMGe/dSC73evtc/5eSjlF1CRoFtsicdge6wU4bEGbFEiT7nCi3yDTM9cNyu/zdgLfuzB4684A3rHxafjW/AdxscOWa+XuhAOUKLMDB+XYxa7YAxMdsjHSCrE22yl689WGC1G7CaxSIM18ZuY0+lMMIxl16mY4fbQFzJAYI12xd0wzDDJMYZSYuAByfuTfPAb X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: hhaUz+tHiAlTjFRcdvlknvOZzZQfwvG5/KhXFOFQfSOaH6CgK0jtLjR7hbWCeiQMj0weBhcO/RnTySD1W7oiX0IGv9dbpIwvWe/M/sfpLtg6MmrdpI1QrjSUuJHMma5AR2fvMDgiIfi7zpps9xdZugPp6Hq8V3los9ySasje7MSayPnvREbwJUI7l19ccAByp3zGpBF0dGBTfAzaCF1A4ZrCzVSK0GEzrII8Ow7G9kM/mpzdRQ/QEVf84xmQm3bOoxioF/ZF0P4ua7gtA3E9Ygxyy/9R2Ek5S2zCYkFQ4oZOPaSFDrK3wfE2bOf7DHHaEUW4lmrX9EwxEi8JwyCCeqEeGIxCei4JT3l+/K2T5ga06+pnfRbMkhIQby33Txj29R+tWGwuA0w0+ilrUK72zOwifaO+kvI100a+azCcPkjOw1ENmqfdiTMl26vqgGIeGcC5TNfJN3sdohygRl+GzRaL541zIztx7u7XnTi3GrGHPHwNWisjyeo1MzwO73K8yBoyBGn50JfbdyC34ZQghfnszuAbA56VCQSI+a+FG2DA6cd5XMtIwk5uDqi0ITP2olvS71/t6LSnt8dRuqSXuXeUWClkaVf/bCx+mGUju84= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 46311265-3334-4d54-a882-08dc692605a2 X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2024 14:58:40.5397 (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: TnDWubUXLxmbMdUSWWysaaQ3CVbzRGfT1RNY1KUjweExf+TJSGiZtZC2Q2p/IHy9tTGhYIbg9JI0FQAZaiNFEQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR10MB5984 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_08,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-2404300106 X-Proofpoint-GUID: a-2WM6NDfe5mcvkmUjDKfyVvq30pAGVn X-Proofpoint-ORIG-GUID: a-2WM6NDfe5mcvkmUjDKfyVvq30pAGVn X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org The request for GCC to accept that the C99 flexible array member can be in a union or alone in a structure has been made a long time ago around 2012 for supporting several practical cases including glibc. A GCC PR has been opened for such request at that time: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53548 However, this PR was closed as WONTFIX around 2015 due to the following reason: "there is an existing extension that makes the requested functionality possible" i.e GCC fully supported that the zero-length array can be in a union or alone in a structure for a long time. (though I didn't see any official documentation on such extension) It's reasonable to close PR53548 at that time since zero-length array extension can be used for such purpose. However, since GCC13, in order to improve the C/C++ security, we introduced -fstrict-flex-arrays=n to gradually eliminate the "fake flexible array" usages from C/C++ source code. As a result, zero-length arrays eventually will be replaced by C99 flexiable array member completely. Therefore, GCC needs to explicitly allow such extensions directly for C99 flexible arrays, since flexable array member in unions or alone in structs are common code patterns in active use by the Linux kernel (and other projects). For example, these do not error by default with GCC: union one { int a; int b[0]; }; union two { int a; struct { struct { } __empty; int b[]; }; }; But these do: union three { int a; int b[]; }; struct four { int b[]; } Clang has supported such extensions since March, 2024 https://github.com/llvm/llvm-project/pull/84428 GCC should also support such extensions. This will allow for a seamless transition for code bases away from zero-length arrays without losing existing code patterns. gcc/ChangeLog: * doc/extend.texi: Add documentation for Flexible Array Members in Unions and Flexible Array Members alone in Structures. --- gcc/doc/extend.texi | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 7b54a241a7bf..cba98c8aadd7 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -42,6 +42,8 @@ extensions, accepted by GCC in C90 mode and in C++. * Named Address Spaces::Named address spaces. * Zero Length:: Zero-length arrays. * Empty Structures:: Structures with no members. +* Flexible Array Members in Unions:: Unions with Flexible Array Members. +* Flexible Array Members alone in Structures:: Structures with only Flexible Array Members. * Variable Length:: Arrays whose length is computed at run time. * Variadic Macros:: Macros with a variable number of arguments. * Escaped Newlines:: Slightly looser rules for escaped newlines. @@ -1873,6 +1875,38 @@ The structure has size zero. In C++, empty structures are part of the language. G++ treats empty structures as if they had a single member of type @code{char}. +@node Flexible Array Members in Unions +@section Unions with Flexible Array Members +@cindex unions with flexible array members +@cindex unions with FAMs + +GCC permits a C99 flexible array member (FAM) to be in a union: + +@smallexample +union with_fam @{ + int a; + int b[]; +@}; +@end smallexample + +If all the members of a union are flexible array member, the size of +such union is zero. + +@node Flexible Array Members alone in Structures +@section Structures with only Flexible Array Members +@cindex structures with only flexible array members +@cindex structures with only FAMs + +GCC permits a C99 flexible array member (FAM) to be alone in a structure: + +@smallexample +struct only_fam @{ + int b[]; +@}; +@end smallexample + +The size of such structure gives the size zero. + @node Variable Length @section Arrays of Variable Length @cindex variable-length arrays