From patchwork Wed May 1 15:19:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 1930255 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=AXo9sWvY; 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=EDqFEi0t; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4VV13349Gdz1ymc for ; Thu, 2 May 2024 01:20:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE767385842D for ; Wed, 1 May 2024 15:20:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 6C73D3858C5F for ; Wed, 1 May 2024 15:19:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6C73D3858C5F 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 6C73D3858C5F 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=1714576778; cv=pass; b=bytX3rfly1dsYGcPNDw3IBQR2zMwrBensPPyrnIftdUrKG2NLQcG2DceC4/hWAZ+UJ5ypTxMJ0Ah5E7UOU60XnwlFuMpYqEc6vjvVH0ZcHeBd4FHKA6tjvkV+YSBJBqzIdQwaMMIo7T9MZRkvaIW9XhXBymLtDZGEwzSuSEdMaU= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714576778; c=relaxed/simple; bh=6oUW2R+bJUBL/Zjg9LLO8CH/1RsLDlvHN9ogaFrF2bA=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=DZENqCFiZUOUy0O3/8iIyWNEt4JqjdMQPg4v1IsvThdT9+sBZojdVseilXueufUyP8u9FSpP7jMHqWL8XDUaplEn59mmjKvxkzH76t1nPsIv3/FT8EkpeaFS8am/ztM9lcEpqymPh82QEx+KlI4VHNDqAOci15JqUPyzWLrO3UY= 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 441ARxAU032762; Wed, 1 May 2024 15:19:35 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=RfWS0bbbQXuQoMO30xR0U6tJET3SZVol5UI7GNAjA1M=; b=AXo9sWvY5M5JZyGMfwfLzjdqM3eNwu988+TWdgybFuaSBuovvAu4VKU8eoSagS5TvYev sutek/kj647EA+ZzbQPdrdiFUjYY6hKFQtUBt2+u7II4iL/e8vOUFA2cBpa8Ok6y5rou adA91xpRiqzDLUFgWxaVeDotBH07zAXjIohoDq5IGD8XNPOAKD8HSmLq4RdV4TFq8QmU /00tQ/rg5L2N0eLBL0HYuCcABiuY5Z5Gy8RF3nSIsHxrZO9wi1CUvxytaJDJdd4lEaho m1GMnEWoQahCGjX1s172UY+tOBkRmHTXBQZ7YhYn5CnFNKuLegt+AwKxBPR1IQ2XTkt2 Yg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrqseyb2d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 May 2024 15:19:35 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 441DfjUx005034; Wed, 1 May 2024 15:19:34 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2168.outbound.protection.outlook.com [104.47.57.168]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt8xadx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 May 2024 15:19:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cZ3GkNMi5vq1BWFiMmtreG44egnM+XnndTGDyBQiJBXRQnwlMbfrCXPpnOTs5i4hlgNdDoG4urpNndqafss/8PPXXAPW8Y+yf1G+wGnrp9FgTQZ/YwGiYt2PenDIBw80W0KSGVnV0gbHj8MNyTnVusOKV9wj8rI7uh4rS0m7Sev++VxCZga5bUsixyotIopvA5Z1OQTBXX/2Tr5E2oX8XAbMvtSTFMDDRV6rNokCfYhC/d6MMlVV8fqWPS3SMzoMu7vCzOZB+5YhjvAAzHI+oA5a3y4qpPDwx41oGrCI1fhO2jBoKrYiLY+gScIX+2A0qGwBC7RgUFI2QPYtDrJuiw== 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=RfWS0bbbQXuQoMO30xR0U6tJET3SZVol5UI7GNAjA1M=; b=Tz9HwL53v7dhBPzzet3WsWA0+rFN3mYn4hVTg2/8oJjVonOVCXXHtfUOQplgW0XtIWcBQWQGjWXQH6hGRl2n7j+tIdIkQx+w1N6EYg2EDv9zH/dNk3/Ip/j/T+S0/d9Y33Dmd3GIcikXt0/IR4LKp4d2bzI4c7oION+Q9oMu0FukuaXbPLf5pJuwZ2vFunuwgcSD54OE0Sbm/Ug8RBhuhK6Vree9MIjlxI0D7qS+I3c6PkA5aEtsWK63CV6y7CuFgPXHqW8xuwhEDI5s1OdCDhIucziffVZTGQ9P2GwVD4NewfOVlvQ1rN7SG1M6yKlNh9fi5Dj/RVIeeNB8zpF2qw== 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=RfWS0bbbQXuQoMO30xR0U6tJET3SZVol5UI7GNAjA1M=; b=EDqFEi0tFEYiUxffU5Go9wuBMiXGvtWC8YIWSDmnO2iokXMYHfjaHHhv3C5njmEJKIKb8ihZdoYtzSMrxN9xOB5dzr7teAabwYMW8hWx3gU5IPxm90jFvo2So3SAH1bDobydZ9cjB/9ug7ENOx9lEknx9wyWpaUoDMb11RxpZqU= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by SA2PR10MB4794.namprd10.prod.outlook.com (2603:10b6:806:113::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.28; Wed, 1 May 2024 15:19:29 +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; Wed, 1 May 2024 15:19:29 +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 v4 1/4] Allow flexible array members in unions and alone in structures [PR53548] Date: Wed, 1 May 2024 15:19:20 +0000 Message-Id: <20240501151923.2895074-2-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240501151923.2895074-1-qing.zhao@oracle.com> References: <20240501151923.2895074-1-qing.zhao@oracle.com> X-ClientProxiedBy: BL1PR13CA0109.namprd13.prod.outlook.com (2603:10b6:208:2b9::24) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|SA2PR10MB4794:EE_ X-MS-Office365-Filtering-Correlation-Id: 23838dda-f613-45a0-99a8-08dc69f218bb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|366007|376005; X-Microsoft-Antispam-Message-Info: Lm7tpgnUhyF414XPZUzYcFLJqZE04nEc8ahKllvfaJJwlYkU6TTJToAtrdu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W+NuK6pzKDSO1APjiQuUd0+xgmgbxFcIJmnQ3JD/N/5/VQL+cZR/zUGgN0nFAbnJB+fZ4RandeRPIdy05BMA5Ei4aJoCI5R+tdch6uCdjRE1JNb4l3YUr5/r69OtzjuJ2nyhY+sVjglWaT9sWQWRjqfsPdRVQqO2b9Vk4Jng9SmJgmXxcGmdOEXn9kaxbw= 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)(366007)(376005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xU2eQ3DthnIc+AFB3p6+HlIEVsiXw9mgwu9ok809uxkbL/ymDn9M+ok9aH7OKD931x9OqMCOaGSbqosl3iQsANoOlMa12PC4/a4wIIMn5e0/83M+3UwFtrTuIift8zkqY7MA6QDA81uye/fjODRyxstsYSzhf/AuPxpnDczSaWcKkTVqFGdAK8AAkX10qESCX9pdtKqLv9XHtf1oVLmVa5tPvueOIdcE3UEdf6VOrAaQF118NkitBm8HPallpt/Jl02a84z06X8WA4D41MnYJPjKh1R8ZMqTzjyZodJIxuv2utHgb8OURiBknr9QX/+oeFWwctj9SdU3ohrexSQy2NoTJcMs2MNfG/QxKCwwgb00wfc9rS+tmirhdnyFCvh1N0ybxCevtI35SrnJRYDyD7FzRgIp+xBfunBuItHu1nfgtjl4rZFk6BCgA7CDbCEDbkmEAbDzfDra2S43e0PkNDVNvhQU7ZpJJj3Ar97AzZAV0LLEGvqThS6trU6CVKOL7PNDMuMO36eWwx/RVkAhsiXouWpEUhNhyRfg0Qivn5Gb3UR37/k7bC6zmzSR+A7ZPxw47c+x6fMx/FL5uQHQvTAb3XIdlbpTVlDOgqEaaXQB+sHY8wQfZ7FLKjtwy9fVC3WqCk1BgzYHa98QMQJ69JALb1R4mIOWZsD8x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mh4dIkq8pLnLmO7afXEYwL7vH1UgIwngd9QBq3nPJj69TuOGOGUYFQkfiKXzrK9avRFU1aOX10TLB+uPjcFwTI5Fm5jh+uC9g94/nAJ4WeQxUuobSAUcSRBSi/StpjF9EwXyzXFzyMH1XVgG8uqVgglbcHCQW4QhCnxuBn8mKzkePPPjjAK1QXXswTcc2xayUsDosComrFOwEgFZL+4Tf0a/EBsTwXqNg3fieaLtPrsqQC7jlapOLWQHPO4+3voRoNkVZgTUJEiMhDrHNYkLxGABaG8N0qqrZPD0ZUC+MYnTGF2LsQr8d0g/g/MNfVNiC+ZmQjMe2cPJWmJh3xDEhybrybLiKwSu96+H6bAKFr8/cfXXaEmeOGY21kAqMtjPYKecOZIDNwKhTRVW6hxVWROius5/ZZobDSFWdic98HJak7nZpwXmlxmAhorpvnbaBZg7rlvk6rhFrGFxH0cwZUAlmGjDbb84gd8FGThHTR5sZ+hb1s5eb8QY9WJ/Zpyv3D9agN/MiiQXDaYFxV8s= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 23838dda-f613-45a0-99a8-08dc69f218bb X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2024 15:19:29.8652 (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: qBwPSslPjWkEZICDCNhDCCgTGsl5grpzgstki/k9FMpCKIZGtkSQVVVmaKNb2ylZzzoOKCOEcg4Tl2mVQDucGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4794 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-05-01_15,2024-04-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2405010108 X-Proofpoint-ORIG-GUID: JHF8eivJGC_vwljxITLuBuyvXsjIynkf X-Proofpoint-GUID: JHF8eivJGC_vwljxITLuBuyvXsjIynkf X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 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..94a77d7ef39c 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 every member of a union is a flexible array member, the size of +such a 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 a structure is zero. + @node Variable Length @section Arrays of Variable Length @cindex variable-length arrays