From patchwork Thu Apr 25 14:06:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 88990 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C5DC3845148 for ; Thu, 25 Apr 2024 14:07:52 +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 ECE2A3858C98 for ; Thu, 25 Apr 2024 14:07:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ECE2A3858C98 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 ECE2A3858C98 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=1714054028; cv=pass; b=fnBBycRKh9KG4c5Ui2k+18kVeNATNb09XhSQjoFxtJ0Q8tZme7OiTJfNAlWpKsCXaQTyznOeC6eYFST/8CPxaP7CUU5Hgxxa3VBUKa4GySsVUdAGKkbxfiMpfEGMjTJO1qZ/ga16hQR3H/j2Bt9nUDNIwgVAv8OWO/wCUpEOwIU= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714054028; c=relaxed/simple; bh=HAv4O68wh8rfLTsufQnoS1dGYkIxUXZ/IYkEsuu9K4w=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=osyqDw68XGgEzHeCIhUEROmkBDJsUWifSMEAMWBvpWCxn0zwfdaStc0DGC4xueK0tGKsqgeUjqeJ/rzMI5iwVcYn8Om/GAK3ryrl6ADAZh96awVWdvlBdtZrKE2Tk+7tBoDa1+nPzuirIcJp7fEs/OyQlmGMw806RiFbeIoBAgA= ARC-Authentication-Results: i=2; server2.sourceware.org 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 43PE6vKO007531; Thu, 25 Apr 2024 14:07:05 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=lTtdxDiCWZWgdWdL1fumyUSfNrGc9LHXMUr144EEcBI2nwAs4cbwDQfYGOy/aEy2YU6d Sk0fOM2ZzX2W4uH802CzDMCt549WRcwbmmt6/Lehd+G0Hz8SzkR6MfpKRgHmOs6ZTynG iFeWCyfXn8RtEafSx0HbixjtG07fKIGqWnig8FiLPy1laFS3USsuOK8BWr/UfZIybFe3 Lm+v+rVvvON1mE/FV7dWfK0Mldsile9TgBq+XyIkwxUzci5zZdTZI6bYzNdKzvy42PGc jq1XobUEolGOHSEPwcCLmS3qJ1neAl7adMJdptTPl32S2RNgmp8SibUkh7T+P8NiM9KQ 3w== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xm4a2ka9a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Apr 2024 14:07:04 +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 43PDNRpO035774; Thu, 25 Apr 2024 14:07:04 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xm45ad6kk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Apr 2024 14:07:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EiPEX1Gl7LZj7cMcri69O2jyNjKKzpIceu9x+aiCXyI5uWW7VwRcYjouO+YKl92uQkIdel9Qba72Hfq00/LiTTYyd5KZboZ8tAeO2NIIBP3Iu+ZIUzeird4bwSTOORpjS6YLd9UWlzVr0KnE5M98GqIGumpt2LWLXODmvQRSIlwuo/THwViZlQQhUkY3CqrgZVHCLkEYvfzSZoYjw5HyETM+6BIe4sv+xZGgrH9mcY1Rmj5czAaM4HJcsVh98v7sZe5oJG67SOfcbLGWEaJWdqOUkT8hEGjJXgSyCCJWrdw/jKmTMOB6EZtU5ABwAGs9N7QQpJPOOu8b7n0cEbxTJQ== 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=aCodyoW2g6N0FAtPJQelG0gop/5l/xhR01JjzgYlJDSHxY1aTxtDjpOf+eR2LdyItefnFNqpydub+6jJhFsQUnH00QCmnChNn2AwQVA4KnUo++TNyI2U1E09ECcCAML1JuIC/xiXWV2L+D2xBP9kHEC+EHnqJrdh7X9S9Lbpby/SACl6XNo4bLyWth32Xu98RNOdluBiqgUTwmUR7gkDlq3tSAq2b4Xa5ctwn0YrZ3+2iVN/ujHIDVgGy3Y5NnoLjGC66TC/yAIB3baqWIOr8/EKlxM5SYkHq21ac/mHtn733B+LK1WwRa2UBMjXilDjCpXRMRIkJut4EyFTBUIYVQ== 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=OkLjJk6vSi7yYvHHHdTzqpan7Ve54YZJOInZ77LxtS3lcnwTO5L8eCQ2UkdluOMsz3QUBFuc71Ct02BnhcGCaZwkVq2FzvLiuI9bUC+0MI2gWVXBpozqWHCA3oTT3ODaR2wNXp99ocaECaH21TdC71EH/DuDguqC0q2hL5EH28Q= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by PH7PR10MB6083.namprd10.prod.outlook.com (2603:10b6:510:1f9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Thu, 25 Apr 2024 14:06:56 +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.7472.045; Thu, 25 Apr 2024 14:06:56 +0000 From: Qing Zhao To: jason@redhat.com, richard.guenther@gmail.com, josmyers@redhat.com Cc: uecker@tugraz.at, siddhesh@gotplt.org, keescook@chromium.org, gcc-patches@gcc.gnu.org, Qing Zhao Subject: [PATCH v2 1/3] Allow flexible array members in unions and alone in structures [PR53548] Date: Thu, 25 Apr 2024 14:06:46 +0000 Message-Id: <20240425140648.1407274-2-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240425140648.1407274-1-qing.zhao@oracle.com> References: <20240425140648.1407274-1-qing.zhao@oracle.com> X-ClientProxiedBy: BYAPR02CA0025.namprd02.prod.outlook.com (2603:10b6:a02:ee::38) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|PH7PR10MB6083:EE_ X-MS-Office365-Filtering-Correlation-Id: 1ba51db6-d7d7-4ebf-7941-08dc6530f74f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6PNT/DF2DpTQe1ZFhal1M6+ttlshGXw3fq9yl+GeECOkxY3Eiid2wZdb30fXQX/1sfrcgMeHAa33oM78XrrRhBiW/CHLJfFop0BFh343bE8ZtPdEil2xPcIvUZiMzNpcSGltwrpn3q/uEE2jv79sX4HHA025pt7LwZzFDo4WeBJ4kxJD/a+oCwqLb63dyeFRdQ3V3NNSm4ecGYKI8TWD8gKtQbqhj3GdYwrk7WLprLUfyU3TMRSGMJGhAsrLy7RSU5qBzaasGtM4mmQCftGmxTx/m9aUHRtH7hQyakfLQVDdbWZPBrKGMaMzgfoxDOf9ZGBGJfmBHaVfKtoOya9qg3TPxKLOYcUIQqQSCbqVD+Tyo3pk7pHhFpIX6QumVnF+LBC0B8xkyQhIXwQVwWUs5Gpfh8wynY8Ba++IhxdEZE79x0KFGnjT8tjkjNme0IssCSWkEC0RbXVPpfEDMpiK4+tOBzFSepzxvJOD/UJbaocaBtPlH8/NoLVo1Ny/T5SM/Gpu/lrYSAh4Lmp/NbqhheUgfwSZ5lCR0f+3hSbwVy/+q0v7KsKOaeXfuccYEuA+pnXBQOgjdNl+pVZkpdNSEQ2rU0Fx33JMyru8pQ43QEo46udRzokAjnfbSwho6RAeXOKN9zL99jvrKpf4GgtzNVxj3wETN0JbEnBEHT8YzgkoxlQZyuoGrVbPbeUxlMf68q14XHL0pa53vI0yinnmO3dKUhZN8gaT856kjpLv4khyU58rP+1CS05FQlhMwXXCygLO4oE/4OqNQ3Y3U7/y3NJ3QvcdOCXzMdxqg9esZU7c10W87wKBgNZjONELJiDVnE8WYCBNC0ehkDlqMwQYBZWg4YdUk62frzhwNLyFMwEDrgiMmrMwRfJPdOlERYaLkzBtWJmB6YdluauICp+MZpSwbba3igk3PyZr4/JYU9qnF7+O2KpJdqoDKCV7sLyp5JxD71HqqSNM3Y00nP6moqTd8gWNpWOfazrz0pBPm6dOlc9WF+pPjEMq4cehj5VtYGNU591fYLoGJNDIFN9c9d6uuCYrH5utvc4IAFj2QaGxCRNbH3T1goBJBLjX72e0CRyzIjAcp0B4851HkgrIiz8X36s6JxfGVts/XvQoflaeQKAiEFKChNgC2ddWvMcrcM40L9ddNHjZAy9XY9DM5AXrc5HRrelghDMSPs84cnT+KL06ycYKPrbFpZwugQ8Sg+70UH+nyMRmOwOR1PnhrfY5gATIwa99+uAXdlaUUmQMoTsfxD2f5nWBxe1czIqOM1E9RAOTAE1xeze/vZ06Wl89ddA/XzYVujcqY26evWo= 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); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: iWgoj7dWY48kdiWetL/L7iBmsug+jVG86PrS1BW7mTQlmPfRwT6/TAd65oWST0azu4Vfh3DU3T84E8RMBcm//mIRAePJxjQ018hDmZQFu1yKJZdazu9xQJ2FXDdpHue/nJNpOj73OcvWR/djdYUx3/nBi6RNhwIo6UlhzDZ0Cg5sEkG1l4L2FMASc+Z3sDrifPOjJY7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YiREsNUyGmvddLS/to3epmF01C9Ubt/1IMaX6gyfYtg139y0dd7E6rz+5bPDheAfNumakpbOEf3Z3dVDpChsG1sP3i7+IH0xJbTZxGhGkmjWBZAqE/USb5WkSln35F7duPQnulKcujPj1PQRZCq/8NtxatAmMufXsvshrBv19KghEZxpB0B6oWEc816IyXROIMoVwjM5WbnftWQroG4NpH3Obn0fDl45KqCaVwjGzqWDM5isD9GyBWSSPO75Lj0Bx8/f2UsFIiBjdVKyek0w2fbSKD66GUziNfhZ0iKmujdoKYnAHa5bIh5SrRhQTI7UC X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Tm7PnY0/ooWj6/7dbFwYPWq/O8gREkfUP9vhfrp4rBPe6OxFAbGq/NNWv+2o+BXknVYwCCR/VN3j4baMOjgUhc03NivUIqlUMHZ3PKCPz2yuL2JwRsa/WX1iqXOpqmS9C/cDY/KkizQQamwHmI+27zvplgZDcvzalORjan4ddJlMHsREuRrc9qmhKN+PdevJ1AqzBV01gBzzHDHuffLVbTBHeZ8zKA5nihCPTgvX+N31EOjpztCVW6NCyp944h0RQ2eSZMchtAphwle3WqpbJ83SGLL6m0GtXpVreM6FRYUVWVDqozIo+qxz1pr/0h/tyjYSrbQ6xheRart9Ohg4rctzsuZ56ZyBK7adZAM80j8IaKFYxqTf1LLXi3RB0I0tYXXCQEvay9KuGtGUmri02A5p6kQGJjKJAkNzpNghB98hRsvIS2OqbtLn/Lfaw1/3yuBVK850L1bTgPAU5K2yy620YAx8U6zd1CuHWC6vsYksB4+w9cFQ/PnnVBHKgT5qWbM0xOe4Tyc7eD3gzscpSu9Xp95F5dQ9M7G3wRFYfxiJP3NHeBYI/cpqYnKzpBiIqPHX2YAjTHPy+z0jGMKca8IMs01SxhgLdZlnOz2T4lQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ba51db6-d7d7-4ebf-7941-08dc6530f74f X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2024 14:06:56.4603 (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: Q2FeHSaibAlIIaiGf7Kr2XUO0okWAg+5CqxgfC5ssw3ZM8nyRkxkp4GQKWq1n5IurRK0+MXRxvCcmW30edRFcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6083 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-25_13,2024-04-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 suspectscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404250102 X-Proofpoint-GUID: kpLdx-wEm0vSbKAbTRWsAYZaV-DlI2DQ X-Proofpoint-ORIG-GUID: kpLdx-wEm0vSbKAbTRWsAYZaV-DlI2DQ 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+patchwork=sourceware.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 From patchwork Thu Apr 25 14:06:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 88991 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A582384AB64 for ; Thu, 25 Apr 2024 14:07:54 +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 622F03858C50 for ; Thu, 25 Apr 2024 14:07:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 622F03858C50 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 622F03858C50 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=1714054031; cv=pass; b=A04JEWkKNDfI812CcKbHIzx5a9sMTQjwp0OPPdQILbSmYL4p/tE8qXn0s48yHkHG9drYQ4CJu3JL8GyEdXKG9E+J01+3bOLOUwRnANKVIHVTdQl0H9vkDUovmaX1xKGOASESsMgqTRApSH1k4T7hflCR3KL/kSAlva8o+mitLeg= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714054031; c=relaxed/simple; bh=7LD+iiY6BfwXG63gtaognKLeW4fst+GRIJFaUFIRkN8=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=FheqS+dbg3FzlRVhwZKudJbL1QxOQP9t+o37GPcJNEC0JGZE+6/vQ0pYslCRyMWRcXCX2R3uUKUf0P361NhfkGhDuzQeBSxzB1EI8h0I6ngbdBGAocDTIWeqVf257LxU4VDPJFOGFoJNGQ38s6USRY1x4FfMIL5JCS5COHnWPTE= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43PE6wrg009197; Thu, 25 Apr 2024 14:07:06 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=kmqQC4Fv2jq7N+ddvIR/O85kYY3PiDVbBF+WUK69Je4=; b=jAhiQw9vR7mKIrrg4Nj8liaVEh3pXwgYa24MJTcel0m5cAdLOyGd/SqXds4y+0+qDQTs kDOxfyaoIvvZRY0+XoNShhHCfMPsJMQ06Gjl1lM/Mjsaqc6aN8hx15s36V0DyqeWepOQ iwUVjqPE5dqzIcHnNaIj5D49oFMsaaXNyUtcOYRZ8cgXCrEbQC+IEKS6Ka2HHV50qmOD Jay4RWmveYJ4h3HoWabAhYGXPxCG7o/NJn1qF/gTWyKwhHHXst9phnp5/jAvUf9QvEQy lLWHQStriB/1sGX0xDw3wECw18at2GkosS3U4UpADpXzo/mW5gMID2jo7ss2hHav3puU KA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xm5autj7a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Apr 2024 14:07:06 +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 43PDNRpP035774; Thu, 25 Apr 2024 14:07:05 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xm45ad6kk-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Apr 2024 14:07:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yn8zEUHSF1hj1MCS4uQosCUg+PgUKi3uj9A3GDk5TE1ac1Ss/LLFOK01emJP0L/3ui0TltJn3JPU9uozkrOZBQUl+FHoJezKVWD8tdPu4BVSckMW4I6zVVZyojr3O+NiRM9aGV0EmpD2mBw/maufRBlcWogG50ZDHyFumn9rEJ1IeYwDfjC+WNKNnS1XyeJWY6np4Ruh2FVhu31djV3iUO/dwlKdpr2MdCowTey9IbCcTva2ijruGb6pN1ZChcKnU4ThAWQEvxtV34jvcx4EIFhyXFvWgLWxRLEvb2+xRkyc9RPUCrItHnvuWqwGyOG7Jc7ON3b55jdetRhW9rCPZg== 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=kmqQC4Fv2jq7N+ddvIR/O85kYY3PiDVbBF+WUK69Je4=; b=fNtEwWNvL4dn+juE3+Y1kFYTpB/VLkVzuYIxZ2mQE6Io8XnUgPD5WIgE63Bxl4cKC5qCjjfgR7zvrrPz7hsu6SFawQnklTgfZHvmm6xeTNEsIeWFTpXHV7yQ3OzlNLOhPZnMYjT2njWx24PpkL9tp8+zCZNYIwVMAM9Cm7iPn/kip3sZSERsLUMhBNXbgRaw8Mm4PcM6mtqe/FxrXU6PJk6ltmg93eMOv1XZEKXyX5Bsbe51ySr2hSOCrrSDA4FdpJ4LM9ZVY+xoPT3kRQM95VlkfQuslLix5gjatY5RdEwsaHjajMsVyhNtoIPRL2kI+Z43VWhI6AdPGK5cda0s0w== 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=kmqQC4Fv2jq7N+ddvIR/O85kYY3PiDVbBF+WUK69Je4=; b=FaB8wp/DZTR0/t+ynye7cbszvvvXzMZ2K9eLgYlgzt+YkKTyPWVGorTJaUY4A/bO8Wz8S1sN5GUnR2OxhAZT4seUa3f7NwUBifs/9nQXo+5gritqhNniaUoaGsx4qW9g5j9ebT/5DlCCTuhz07sN4NE1FolZhYYxZaic6ZJ0f0k= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by PH7PR10MB6083.namprd10.prod.outlook.com (2603:10b6:510:1f9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Thu, 25 Apr 2024 14:07:01 +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.7472.045; Thu, 25 Apr 2024 14:06:59 +0000 From: Qing Zhao To: jason@redhat.com, richard.guenther@gmail.com, josmyers@redhat.com Cc: uecker@tugraz.at, siddhesh@gotplt.org, keescook@chromium.org, gcc-patches@gcc.gnu.org, Qing Zhao Subject: [PATCH v2 2/3] C and C++ FE changes Date: Thu, 25 Apr 2024 14:06:47 +0000 Message-Id: <20240425140648.1407274-3-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240425140648.1407274-1-qing.zhao@oracle.com> References: <20240425140648.1407274-1-qing.zhao@oracle.com> X-ClientProxiedBy: BYAPR06CA0051.namprd06.prod.outlook.com (2603:10b6:a03:14b::28) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|PH7PR10MB6083:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d26b118-4426-4774-b1e7-08dc6530f947 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ta0c7GsFmDZJfKdNZ7YJHc9zjVyd5RpYr2znS4aR+kKI07hJJ/nGwxrLW4JFWoovGD+t3jSzEEDt0qS15HpCuHBxpoyorJxbdXgFVsMcXSqiE1n+AQZ8BDrBJu4jZShVRA9bAPi33Od9dV3cxmshuM9RjR0a9mO4L/iC5MVOKD1H5kHeKwepUwvBxg/hUx60foY0+Dj2e1oiv4JJI2HPeg3nldCeCO5nbPqpg0TGGWmu4kiSL5SU2FUEf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FV:NSPM; H:CY8PR10MB6538.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(1800799015)(376005)(366007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9Sn895HHu5Th+Ez9hRcPs1xWhPcGynBbcfeMKiJ39zopEX6P/hfRIwJs4h9HmMdlrbu0ImDcfgbDWHtlLnpQCEFGq2mH4af2Uv+7cskErxt27JSDC7TgAmQ7Wwj/DdV8wqAGmSCxLVE+lj8kLOE0OU9hRQlv6WcWVeDVUMpeNgMgTAJGygtwWdr+5h2CNUoJnrUb9U0suFf1xklD3JCsjbELo5wBFioNLwBC2Jzh5L4zu3fvMMH+goHMtHbrgJdClXhqC0wrxXASjftFVHtJtzuoXlOgELo0gER6a2sIrdsDLFYeFMRA66HUA3kKyP3CiG+SjhpANXir1kajFBxmzXRFkSHCSrDNywgUQ1KE8KVUTbfO/K2EVUOkE9k+MojBnrv5XumT6aJS8Cqnb1LgUPu00esLOc/XUPdNG1tZKmBGwsefUbzCxlOAC0SiQQxxwK3FId1oA349NiHoYXC4vasvo+wkscTyDLTmt9Lfe+SZbkqgAILz5S7/rrf6hVbYiB6tma9SZ0PCHqfWEOP0iFWzuQOUGZdfUSUDod7Rlo+dh8O1qigeKLUw3j1DAPBkbOqccI5XUCY41K5I1NfW8JVFYlSOJi5saygl4wu45jZwI3+QlqBV52L13ltA4sMO1OaVEU1kLs4GiSukAhf23wvCrpPkTyorGsrkNlVryZvBlhGw+Fqy4OYMhj6M47giI0sRHUK6QDW7T8mF1SWaUZFgxraZUyO+BySvthvbBOAEz8JFsz4Tc2urhKI5N8OPlmS0ERaHeur/FPz2j2OTJxFWO8hwtFMNVIwlwUe4L3W51Y+vKzzHLlHGCIH97kjdG+I0nIRxnZ41U0/ufahLtUn9c2ozqUi/nmq6UthT58oM1BthM2S7f5IF8IvknaGvgh+F1zNcLKMN2dSZNLKlt22GSvpr6J0bs5S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YnQMhzJopwSa/6IyHkuvOMt8cTsPxhspvdP0/MiDQWzYt7o6l4aY4f154JiBqmo5ZmSt1AWM7wjmC89vtGnltBgQKcMuZ90RCK9xxRuPxsm9hosW+YcSTNTZM5JqBzeVdoFo5FMHguC0QLQzIXeEpiCcOm55VH+kiPZWD06kotKK2Wivdp29tX/cqoBLysyySKoPViSjxATvFrRSYWsJNtns+7rD/NJYXTVyQkPhgQ7oqqLgxCKNr9GamcREkoM7HApuQN9kzcNKTCAn9Zsa/TxuJbSw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d26b118-4426-4774-b1e7-08dc6530f947 X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2024 14:06:59.6930 (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: jrLgURYMZT6JNIl5aU1PDT3muh7s0fJNdnHwSUfZVCtGW2qEeMVfDDQgZUEsBW2THF/5BhAyGcvpyX9evPo0tQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6083 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-25_13,2024-04-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 suspectscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404250102 X-Proofpoint-ORIG-GUID: GgPFI8Jh-atLgbV3aT78rdcrQH9ZRiEi X-Proofpoint-GUID: GgPFI8Jh-atLgbV3aT78rdcrQH9ZRiEi 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_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+patchwork=sourceware.org@gcc.gnu.org to support flexible array members in unions and alone in structures. Adjust testcases for flexible array member in union and alone in structure extension. gcc/c/ChangeLog: * c-decl.cc (finish_struct): Change errors to pedwarns for the cases flexible array members in union or alone in structures. gcc/cp/ChangeLog: * class.cc (diagnose_flexarrays): Change error to pdewarn for the case flexible array members alone in structures. * decl.cc (grokdeclarator): Change error to pdewarn for the case flexible array members in unions. gcc/ChangeLog: * stor-layout.cc (place_union_field): Use zero sizes for flexible array member fields. gcc/testsuite/ChangeLog: * c-c++-common/builtin-clear-padding-3.c: Adjust testcase. * g++.dg/ext/flexary12.C: Likewise. * g++.dg/ext/flexary19.C: Likewise. * g++.dg/ext/flexary2.C: Likewise. * g++.dg/ext/flexary3.C: Likewise. * g++.dg/ext/flexary36.C: Likewise. * g++.dg/ext/flexary4.C: Likewise. * g++.dg/ext/flexary5.C: Likewise. * g++.dg/ext/flexary8.C: Likewise. * g++.dg/torture/pr64280.C: Likewise. * gcc.dg/20050620-1.c: Likewise. * gcc.dg/940510-1.c: Likewise. --- gcc/c/c-decl.cc | 16 ++---- gcc/cp/class.cc | 11 ++-- gcc/cp/decl.cc | 7 ++- gcc/stor-layout.cc | 9 +++- .../c-c++-common/builtin-clear-padding-3.c | 10 ++-- gcc/testsuite/g++.dg/ext/flexary12.C | 6 +-- gcc/testsuite/g++.dg/ext/flexary19.C | 42 +++++++-------- gcc/testsuite/g++.dg/ext/flexary2.C | 2 +- gcc/testsuite/g++.dg/ext/flexary3.C | 2 +- gcc/testsuite/g++.dg/ext/flexary36.C | 2 +- gcc/testsuite/g++.dg/ext/flexary4.C | 54 +++++++++---------- gcc/testsuite/g++.dg/ext/flexary5.C | 4 +- gcc/testsuite/g++.dg/ext/flexary8.C | 8 +-- gcc/testsuite/g++.dg/torture/pr64280.C | 2 +- gcc/testsuite/gcc.dg/20050620-1.c | 2 +- gcc/testsuite/gcc.dg/940510-1.c | 4 +- 16 files changed, 91 insertions(+), 90 deletions(-) diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 345090dae38b..947f3cd589eb 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -9471,11 +9471,8 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, if (flexible_array_member_type_p (TREE_TYPE (x))) { if (TREE_CODE (t) == UNION_TYPE) - { - error_at (DECL_SOURCE_LOCATION (x), - "flexible array member in union"); - TREE_TYPE (x) = error_mark_node; - } + pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic, + "flexible array member in union is a GCC extension"); else if (!is_last_field) { error_at (DECL_SOURCE_LOCATION (x), @@ -9483,12 +9480,9 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, TREE_TYPE (x) = error_mark_node; } else if (!saw_named_field) - { - error_at (DECL_SOURCE_LOCATION (x), - "flexible array member in a struct with no named " - "members"); - TREE_TYPE (x) = error_mark_node; - } + pedwarn (DECL_SOURCE_LOCATION (x), OPT_Wpedantic, + "flexible array member in a struct with no named " + "members is a GCC extension"); } if (pedantic && TREE_CODE (t) == RECORD_TYPE diff --git a/gcc/cp/class.cc b/gcc/cp/class.cc index 5f258729940b..0c8afb72550f 100644 --- a/gcc/cp/class.cc +++ b/gcc/cp/class.cc @@ -7624,6 +7624,7 @@ diagnose_flexarrays (tree t, const flexmems_t *fmem) bool diagd = false; const char *msg = 0; + const char *msg_fam = 0; if (TYPE_DOMAIN (TREE_TYPE (fmem->array))) { @@ -7649,15 +7650,19 @@ diagnose_flexarrays (tree t, const flexmems_t *fmem) if (fmem->after[0]) msg = G_("flexible array member %qD not at end of %q#T"); else if (!fmem->first) - msg = G_("flexible array member %qD in an otherwise empty %q#T"); + msg_fam = G_("flexible array member %qD in an otherwise" + " empty %q#T is a GCC extension"); - if (msg) + if (msg || msg_fam) { location_t loc = DECL_SOURCE_LOCATION (fmem->array); diagd = true; auto_diagnostic_group d; - error_at (loc, msg, fmem->array, t); + if (msg) + error_at (loc, msg, fmem->array, t); + else + pedwarn (loc, OPT_Wpedantic, msg_fam, fmem->array, t); /* In the unlikely event that the member following the flexible array member is declared in a different class, or the member diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 65ab64885ff8..9a91c6f80da1 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -14566,10 +14566,9 @@ grokdeclarator (const cp_declarator *declarator, if (ctype && (TREE_CODE (ctype) == UNION_TYPE || TREE_CODE (ctype) == QUAL_UNION_TYPE)) - { - error_at (id_loc, "flexible array member in union"); - type = error_mark_node; - } + pedwarn (id_loc, OPT_Wpedantic, + "flexible array member in union is a GCC extension"); + else { /* Array is a flexible member. */ diff --git a/gcc/stor-layout.cc b/gcc/stor-layout.cc index e34be19689c0..10c0809914cd 100644 --- a/gcc/stor-layout.cc +++ b/gcc/stor-layout.cc @@ -1245,13 +1245,18 @@ place_union_field (record_layout_info rli, tree field) && TYPE_TYPELESS_STORAGE (TREE_TYPE (field))) TYPE_TYPELESS_STORAGE (rli->t) = 1; + /* We might see a flexible array member field (with no DECL_SIZE_UNIT), use + zero size for such field. */ + tree field_size_unit = DECL_SIZE_UNIT (field) + ? DECL_SIZE_UNIT (field) + : build_int_cst (sizetype, 0); /* We assume the union's size will be a multiple of a byte so we don't bother with BITPOS. */ if (TREE_CODE (rli->t) == UNION_TYPE) - rli->offset = size_binop (MAX_EXPR, rli->offset, DECL_SIZE_UNIT (field)); + rli->offset = size_binop (MAX_EXPR, rli->offset, field_size_unit); else if (TREE_CODE (rli->t) == QUAL_UNION_TYPE) rli->offset = fold_build3 (COND_EXPR, sizetype, DECL_QUALIFIER (field), - DECL_SIZE_UNIT (field), rli->offset); + field_size_unit, rli->offset); } /* A bitfield of SIZE with a required access alignment of ALIGN is allocated diff --git a/gcc/testsuite/c-c++-common/builtin-clear-padding-3.c b/gcc/testsuite/c-c++-common/builtin-clear-padding-3.c index d16cc6aad05f..a4f49f26db14 100644 --- a/gcc/testsuite/c-c++-common/builtin-clear-padding-3.c +++ b/gcc/testsuite/c-c++-common/builtin-clear-padding-3.c @@ -2,14 +2,12 @@ /* { dg-do compile } */ /* { dg-options "" } */ -union U { int a; char b[] __attribute__((aligned (2 * sizeof (int)))); }; /* { dg-error "flexible array member in union" } */ +union U { int a; char b[] __attribute__((aligned (2 * sizeof (int)))); }; struct V { int a; union U b; }; -struct W { int a; union U b; int c; }; void -foo (union U *u, struct V *v, struct W *w) +foo (union U *u, struct V *v) { - __builtin_clear_padding (u); - __builtin_clear_padding (v); - __builtin_clear_padding (w); + __builtin_clear_padding (u); /* { dg-error "flexible array member" "does not have well defined padding bits" } */ + __builtin_clear_padding (v); /* { dg-error "flexible array member" "does not have well defined padding bits" } */ } diff --git a/gcc/testsuite/g++.dg/ext/flexary12.C b/gcc/testsuite/g++.dg/ext/flexary12.C index b0964948731d..6ba4b6417135 100644 --- a/gcc/testsuite/g++.dg/ext/flexary12.C +++ b/gcc/testsuite/g++.dg/ext/flexary12.C @@ -6,7 +6,7 @@ // { dg-options "-Wno-pedantic" } struct A { - int a []; // { dg-error "flexible array member .A::a. in an otherwise empty .struct A." } + int a []; }; void f1 () @@ -40,7 +40,7 @@ void f2 () } struct D { - int a []; // { dg-error "flexible array member .D::a. in an otherwise empty .struct D." } + int a []; D (); }; @@ -52,7 +52,7 @@ D::D (): // { dg-error "initializer for flexible array member" } template struct C { - T a []; // { dg-error "flexible array member" } + T a []; }; void f3 () diff --git a/gcc/testsuite/g++.dg/ext/flexary19.C b/gcc/testsuite/g++.dg/ext/flexary19.C index abfbc43028af..9a06f9ca758f 100644 --- a/gcc/testsuite/g++.dg/ext/flexary19.C +++ b/gcc/testsuite/g++.dg/ext/flexary19.C @@ -12,7 +12,7 @@ struct S1 // The following declares a named data member of an unnamed struct // (i.e., it is not an anonymous struct). struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s; }; @@ -21,7 +21,7 @@ struct S2 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s[1]; }; @@ -30,7 +30,7 @@ struct S3 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s[]; }; @@ -39,7 +39,7 @@ struct S4 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s[2]; }; @@ -48,7 +48,7 @@ struct S5 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s[1][2]; }; @@ -57,7 +57,7 @@ struct S6 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s[][2]; }; @@ -66,7 +66,7 @@ struct S7 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } *s; }; @@ -75,7 +75,7 @@ struct S8 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } **s; }; @@ -84,7 +84,7 @@ struct S9 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } *s[1]; }; @@ -93,7 +93,7 @@ struct S10 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } *s[]; }; @@ -102,7 +102,7 @@ struct S11 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } **s[1]; }; @@ -111,7 +111,7 @@ struct S12 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } **s[]; }; @@ -120,7 +120,7 @@ struct S13 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } **s[2]; }; @@ -129,7 +129,7 @@ struct S14 int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } &s; }; @@ -138,7 +138,7 @@ struct S15 int i; typedef struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } T15; }; @@ -159,8 +159,8 @@ struct S17 { int i; - union { // anonymous union - int a[]; // { dg-error "flexible array member in union" } + union { // { dg-warning "invalid use" } + int a[]; // { dg-warning "flexible array member in union" } }; }; @@ -209,7 +209,7 @@ struct S22 struct S22S { static int i; - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s; }; @@ -218,7 +218,7 @@ struct S23 struct { // { dg-warning "10:ISO C\\+\\+ prohibits anonymous struct" } static int i; // { dg-error "static data member" } - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } }; }; @@ -227,7 +227,7 @@ struct S24 static int i; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s; }; @@ -252,7 +252,7 @@ struct S26 }; struct { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; // { dg-warning "in an otherwise empty" } } s; }; diff --git a/gcc/testsuite/g++.dg/ext/flexary2.C b/gcc/testsuite/g++.dg/ext/flexary2.C index c0253777a1e9..7095a3b0fb2d 100644 --- a/gcc/testsuite/g++.dg/ext/flexary2.C +++ b/gcc/testsuite/g++.dg/ext/flexary2.C @@ -13,7 +13,7 @@ struct A { struct B { B() {} - A a[]; // { dg-error "extension|flexible array .* in an otherwise empty" } + A a[]; }; struct C { diff --git a/gcc/testsuite/g++.dg/ext/flexary3.C b/gcc/testsuite/g++.dg/ext/flexary3.C index 8344b42dd163..7785c9b190a4 100644 --- a/gcc/testsuite/g++.dg/ext/flexary3.C +++ b/gcc/testsuite/g++.dg/ext/flexary3.C @@ -11,7 +11,7 @@ // { dg-options "" } struct s { - char c[]; // { dg-error "flexible array member .* in an otherwise empty" } + char c[]; }; int main() diff --git a/gcc/testsuite/g++.dg/ext/flexary36.C b/gcc/testsuite/g++.dg/ext/flexary36.C index 5bb827cfd0e0..87d6fb092100 100644 --- a/gcc/testsuite/g++.dg/ext/flexary36.C +++ b/gcc/testsuite/g++.dg/ext/flexary36.C @@ -25,7 +25,7 @@ struct { union { - int a[]; // { dg-error "flexible array member in union" } + int a[]; int b; } du = { 1 }; diff --git a/gcc/testsuite/g++.dg/ext/flexary4.C b/gcc/testsuite/g++.dg/ext/flexary4.C index bd28cf55de2b..a87b7e71edb6 100644 --- a/gcc/testsuite/g++.dg/ext/flexary4.C +++ b/gcc/testsuite/g++.dg/ext/flexary4.C @@ -11,79 +11,79 @@ #include "flexary.h" struct Sx { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; }; // Verify that non-data members or static data members either before // or after a flexible array member in an otherwise empty struct don't // suppress the diagnostic. struct Sx2 { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; typedef int I; }; struct Sx3 { typedef int I; - int a[]; // { dg-error "in an otherwise empty" } + int a[]; }; struct Sx4 { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; enum E { e }; }; struct Sx5 { enum E { e }; - int a[]; // { dg-error "in an otherwise empty" } + int a[]; }; struct Sx6 { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; static int i; }; struct Sx7 { static int i; - int a[]; // { dg-error "in an otherwise empty" } + int a[]; }; struct Sx8 { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; Sx8 () { } }; struct Sx9 { Sx9 () { } - int a[]; // { dg-error "in an otherwise empty" } + int a[]; }; struct Sx10 { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; virtual ~Sx10 () { } }; struct Sx11 { virtual ~Sx11 () { } - int a[]; // { dg-error "in an otherwise empty" } + int a[]; }; struct Sx12 { - int a[]; // { dg-error "in an otherwise empty" } + int a[]; virtual void foo () = 0; }; struct Sx13 { virtual void foo () = 0; - int a[]; // { dg-error "in an otherwise empty" } + int a[]; }; struct Sx14 { - int a[][1]; // { dg-error "in an otherwise empty" } + int a[][1]; }; struct Sx15 { typedef int A[]; - A a; // { dg-error "in an otherwise empty" } + A a; }; // Verify also that a zero-size array doesn't suppress the diagnostic. @@ -91,7 +91,7 @@ struct Sx16 { // a_0 below is diagnosed with -Wpedantic only and emits // warning: ISO C++ forbids zero-size arrays int a_0 [0]; - int a_x []; // { dg-error "in an otherwise empty" } + int a_x []; }; struct Sx17 { @@ -123,7 +123,7 @@ struct Sx19 { // so doesn't contribute its member to that of the enclosing struct. struct Sx20 { struct S { int i; }; - int a_x []; // { dg-error "in an otherwise empty" } + int a_x []; }; struct Sx21 { @@ -148,12 +148,12 @@ struct Sx24 { struct Sx25 { struct S { }; - S a_x []; // { dg-error "flexible array member" } + S a_x []; }; struct Sx26 { struct { } - a_x []; // { dg-error "flexible array member" } + a_x []; }; struct Sx27 { @@ -193,13 +193,13 @@ struct Sx32 { ASSERT_AT_END (Sx32, a); struct Sx33 { - int a []; // { dg-error "otherwise empty" } + int a []; friend int foo (); }; struct Sx34 { friend int foo (); - int a []; // { dg-error "otherwise empty" } + int a []; }; // Verify that intervening non-field declarations of members other @@ -277,7 +277,7 @@ ASSERT_AT_END (Sx44, a); struct S_S_S_x { struct A { struct B { - int a[]; // { dg-error "flexible array member" } + int a[]; } b; } a; }; @@ -300,7 +300,7 @@ struct NotAnon1 { // The following is not an anonymous struct -- the type is unnamed // but the object has a name. struct { - int bad[]; // { dg-error "otherwise empty" } + int bad[]; } name; }; @@ -328,7 +328,7 @@ ASSERT_AT_END (Anon3, good); struct Anon4 { struct { - int in_empty_struct[]; // { dg-error "in an otherwise empty" } + int in_empty_struct[]; }; }; @@ -366,7 +366,7 @@ struct Six { ASSERT_AT_END (Six, a); class Cx { - int a[]; // { dg-error "flexible array member" } + int a[]; }; class Cix { @@ -390,7 +390,7 @@ struct S0i { struct S_a0_ax { int a0[0]; - int ax[]; // { dg-error "flexible array member" } + int ax[]; }; struct S_a0_i_ax { @@ -417,7 +417,7 @@ struct Si_ax_a0 { struct S_u0_ax { union { } u[0]; - int ax[]; // { dg-error "flexible array member" } + int ax[]; }; struct S_a1_s2 { diff --git a/gcc/testsuite/g++.dg/ext/flexary5.C b/gcc/testsuite/g++.dg/ext/flexary5.C index d5ec13204966..3fb88c0e8a2c 100644 --- a/gcc/testsuite/g++.dg/ext/flexary5.C +++ b/gcc/testsuite/g++.dg/ext/flexary5.C @@ -13,7 +13,7 @@ struct S_no_diag: T { template struct STx_1: T { - char a[]; // { dg-error "flexible array member" } + char a[]; }; template @@ -37,7 +37,7 @@ struct E1: E<0>, E<1> { }; struct E2: E<2>, E<3> { }; struct D1: E1, E2 { - char a[]; // { dg-error "flexible array member" } + char a[]; }; struct NE { size_t i; }; diff --git a/gcc/testsuite/g++.dg/ext/flexary8.C b/gcc/testsuite/g++.dg/ext/flexary8.C index 7a1811deaff2..a0477f0fa410 100644 --- a/gcc/testsuite/g++.dg/ext/flexary8.C +++ b/gcc/testsuite/g++.dg/ext/flexary8.C @@ -4,26 +4,26 @@ union U_i_ax { int i; - int a[]; // { dg-error "flexible array member in union" } + int a[]; }; struct SU1 { union { - int a[]; // { dg-error "flexible array member in union" } + int a[]; }; }; struct SU2 { int n; union { - int a[]; // { dg-error "flexible array member in union" } + int a[]; }; }; struct SU3 { union { int n; - int a[]; // { dg-error "flexible array member in union" } + int a[]; }; }; diff --git a/gcc/testsuite/g++.dg/torture/pr64280.C b/gcc/testsuite/g++.dg/torture/pr64280.C index 5c569e864b4c..1ea70c4e766e 100644 --- a/gcc/testsuite/g++.dg/torture/pr64280.C +++ b/gcc/testsuite/g++.dg/torture/pr64280.C @@ -15,7 +15,7 @@ public: typedef int jmp_buf[]; struct C { - jmp_buf cond_; // { dg-error "flexible array member" } + jmp_buf cond_; }; class F { diff --git a/gcc/testsuite/gcc.dg/20050620-1.c b/gcc/testsuite/gcc.dg/20050620-1.c index befdd9636500..0a9e1d478454 100644 --- a/gcc/testsuite/gcc.dg/20050620-1.c +++ b/gcc/testsuite/gcc.dg/20050620-1.c @@ -5,7 +5,7 @@ void foo (void) { - struct { int i[]; } u; /* { dg-error "flexible array member" } */ + struct { int i[]; } u; } void diff --git a/gcc/testsuite/gcc.dg/940510-1.c b/gcc/testsuite/gcc.dg/940510-1.c index 46183831d096..9bcd7881f715 100644 --- a/gcc/testsuite/gcc.dg/940510-1.c +++ b/gcc/testsuite/gcc.dg/940510-1.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ /* { dg-options "-std=c89 -pedantic" } */ struct { int a[]; } x = { 0 }; /* { dg-warning "ISO C90 does not support flexible array members" } */ -/* { dg-error "flexible array member in a struct with no named members" "" { target *-*-* } .-1 } */ - +/* { dg-warning "flexible array member in a struct with no named members is a GCC extension" "" { target *-*-* } .-1 } */ +/* { dg-warning "initialization of a flexible array member" "" { target *-*-* } .-2 } */ From patchwork Thu Apr 25 14:06:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 88992 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 042443858C98 for ; Thu, 25 Apr 2024 14:09:10 +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 C62093858C66 for ; Thu, 25 Apr 2024 14:07:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C62093858C66 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 C62093858C66 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=1714054032; cv=pass; b=hrGYC3thFDoV2B9+3vEhKPXys8+XU8QqINQcST04YumqjT8w108C4kG552SjrKO2K6Jxd2AiVWiaU14cUGo4ORVMWDdCJUyivp0vnClJGHV/hgzSOiC0exQaBPClPwsvNnibQdkyMub6+/Xe4KCPCgzFpYKehe9WiXN4335XlQw= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714054032; c=relaxed/simple; bh=3n0wAyTGloE80TgxiCRQuCUuS6BtO+OZ24FVOGjSbDU=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=XYYkcAu87XmLapf9JTFCi8Bn6Sk1HvymcCVPrkVuZx4RD7w4b1yq/k059y3JgdlII85mwmNgKL5QliqHQeBYyxhp4DmgPa08w7xzHNXJyms8LzMumHy0qt/i3s3UWZCQ8q6PGJ6TwWe8IyZFFj3vQZS3Z1tVYokxLf5G39C/XE4= 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 43PE6nYQ020164; Thu, 25 Apr 2024 14:07:09 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=WrbDp6hZ5loKo2HutobE8RtDbCKPwtrDDXEQCCnzNx8=; b=CasIBCaMIbPU2AMkePdrOT/2Z+o58HRYdoOVtqSGxJ5tEc2N9xCjC67U7OXoxqJ3z980 KWOHvQobMhx6TyC2hQQb/J0LDVEY1WATIICcfPggcutXrSpPakX3LB4zJ8ig/mc3x84K uriKJQSmQIA2hekhuJU8uG3g6lGU9gDPDkY3tMHI8ianxeZAqMz0YbfBZITfJGR6c/0D c0m4+SBtnZ/GQpV/GlugJ8c8QvET62tp7HRq7oPs8ml8GYS8818/xb3a78Tl+uEhHosl m7yQM/TBRlwkjYi7JOaR3FopST3rfIhLAhL7vK0cSvFdMY/51OFX7uuGgJrKkW77diBy dg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xm68vk76n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Apr 2024 14:07:08 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43PDDLj2019675; Thu, 25 Apr 2024 14:07:07 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2041.outbound.protection.outlook.com [104.47.57.41]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3xpbf6d7b9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Apr 2024 14:07:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VITXaBIN/pxDL5RRHdd+r0QZvTnLX9q3jtFIaFm/WLNkBgN81F2KjZ6pYeiHBxGp+bDtP3JxNJ+qpEerTOgh0+OzbcL4M20pYuGKNzp+IeAU5cklreT8GzmveoJhR784WbRNf5LaRJ4QtQq6s0TeMK7U4d/LEktX/Aefc3Kx1Sq2qljGMCsFsxN4R7UquN+gk7Fwi6ILr8RdopfRAeFC7adl+YbaoU5swBSpEWsxl+FnHLJzM2UMoAzuVyurLkpy56EWtSkgiWUb2BSz5gdiGwz4uszmHy7PLzDexVVGIOVp7RHrNlAoyXTBYpWO2BKTm7EVCzGnAUVzxGlqomldMw== 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=WrbDp6hZ5loKo2HutobE8RtDbCKPwtrDDXEQCCnzNx8=; b=lFyqUB6OuTXQ5K0maiXbaKC4yWj1un7Yi1iu1tCktvphI9te7KMlYnVgRNQlK5nBH3m93pP+EQNoPjYQUNQ9j8S7YUr3/5WXJdIv1RrxXJt/wGsLti8ki9jkBdiIJnoyuneWJl6VLSeLW7p5wnTNBs31+MRJ4DBd+qaPhhJtd6LLXiHnJDohYnavVNUNzI0f1EXvVIgggJJsr6OSLlJYBwqoecyQxoFHjcpc3KiIyxtigaOgoP6NST1FzYj1Ev6fZr3Bl7V7hUA+WMUkYRpjrLnelGiJCfxg3tLrRUM8yLDFFqwFjPICmeI/RiFhu+QNkR8pWzPnDLizeUfbGE/T7Q== 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=WrbDp6hZ5loKo2HutobE8RtDbCKPwtrDDXEQCCnzNx8=; b=RPk+WKLGlL214PAHHNeZzdL8mrWN/X48ussUWTfx7HpJUMJOOM3KEEn3+zlq7+wLfXk5EYz3Ww8WncMwF9uUB6uKbvmmDFlOq+9GevnmrER+43roRsgSir9EkQL8BSKd6F2qAT07/32UOj10O1V6TeoS8B/XeaLe/T4VXg4G5S4= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by CH2PR10MB4392.namprd10.prod.outlook.com (2603:10b6:610:79::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.44; Thu, 25 Apr 2024 14:07:03 +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.7472.045; Thu, 25 Apr 2024 14:07:03 +0000 From: Qing Zhao To: jason@redhat.com, richard.guenther@gmail.com, josmyers@redhat.com Cc: uecker@tugraz.at, siddhesh@gotplt.org, keescook@chromium.org, gcc-patches@gcc.gnu.org, Qing Zhao Subject: [PATCH v2 3/3] Add testing cases for flexible array members in unions and alone in structures. Date: Thu, 25 Apr 2024 14:06:48 +0000 Message-Id: <20240425140648.1407274-4-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240425140648.1407274-1-qing.zhao@oracle.com> References: <20240425140648.1407274-1-qing.zhao@oracle.com> X-ClientProxiedBy: BYAPR06CA0057.namprd06.prod.outlook.com (2603:10b6:a03:14b::34) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|CH2PR10MB4392:EE_ X-MS-Office365-Filtering-Correlation-Id: 9b67e2ba-af6a-4246-c073-08dc6530fb41 X-MS-Exchange-SenderAD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cZBLTDmYxqEjeJGnZDdyw1jp7dLho9UlYIDbtACtulI3IVByGzSGtjCPMz3xPDHysL8SBUyKnE0U59ObKf+MOcJFCKo5zBvcchpNNiAwyw5m1mjuaBp3gzThkagJh/Dn84x2OOuAbwgvzbh4uouISI5vfHVxd9aWJmwq6Y8wGPnCpeSF7g5vJ1f3dHdtMOfAtewWvtRJ229babCeS7j8UWeMtvh2z0c+tqtyHmy0tutmGwAO6lZe+Af5VHeExRQEDSsMpBbQGiRmamBOvVhdhlXsHYQOzuaUicHFE8Lw== 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: dqLQ5DejiYW+V/WKHeYzS7G/bOP50OP/mVMMsEmR34I5B8cNxKLu+EqT11ZFsejeEzrv1r3gwj4MFTUi62mdbaRx3M64KxxVCP/2pQ8mGwJi1K4fiJY2vwHWoMbK+2hx5j1NXTmxHdjyYLbOclEz6UVzde/nTGI8nXZ5Jtx/1FjBQ5RIbxd9D8swU5be6vdtfCRlYkks+lqNgB8pvrwDhbE/ODCp9rsVg1j5jR0Urlq3fPBC5v4UnLyPYsQUWIPlNnOSoYKlpQ8qPmuSdawo3HXhIkNcskPHo7PmPA3gLklmz/uvTKjTbMbw+Wjap7ixkelnIg1Ij331cItGjCh6X3unD6h0FnSmtJrzhiWoAFUQJSv4qg+nhkCZMj+CI9ZCQvD+32zZf4m5DgUWSe5QRnLs15HQ963x8c9UCjqZK8NAyBxcb+QfKIuoNOJTJl7h+RtiQMWodm/AX/hDO80frN0bmGp6JdXAut2mY5KmTdE9+AVvmUWKXp26wAZyTtyv3N+AgS/8KIe3y/3oU+WbI8v94LwGpcepi3Sf5WwnAKwQjpKsjz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ntiSpam-ExternalHop-MessageData-0: r5kYg9SUE4b4FDnoi3PC9znRmXjkH96DdMObNJGf5Agxkd6VztcHUVUe5jAVbPMeeOVSC0g6q/p4syP14BwqysQJTyhhNZH0nBAFefNSRkjtjOCgfIhY2a6dPDh9K3sDztFMMmPKgQk4NdFMPkNqCyCze06JKXzzectuA2uf4hhTjH3LxkwV5dLxgGVzGr7LubFCjHEh+hXCQx3lCqxe372FadVD/zYKSG3NPGSyT2q7xQk8ZUWRybouHuGEsO8C5R8zmTsLNEuWIiIXXD/4a6ybASnbCGv4pVq12ulBXwr5PXaTYK5bsIMah6yMlxure0vmV3IKAQTbBf5bgbDpa9uXvb//oJKZ3s4IzSH1msqmMFusIFxOJchB3IKL6Mez4u33++UBcSYVj//9uc+y3LKiJi7AT9sBqwdhllocXtx1MzOcF+Tq3GrYKoMV3IGTw/OBtthVKM4J0vQJXluNArOvSdc8qcIjlyTRVTmGUxrnUGt6ajxy2guf/NYqC8mvP6EcRMuJ1au4tXVAAsDCJl9VEDWsPUWhuftw18sqe69ajZPNMJhrkyon2867SjSAXcqDerWp8dQFGpLkru7EHCDf6fdxPj+WRvq2uYHlOBc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b67e2ba-af6a-4246-c073-08dc6530fb41 X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2024 14:07:02.9356 (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: GaQZvdHEHczX8JaOoB+64DMt8/1bS8pAWksjb/wvUA+y/jLj9QT8SjikaGWRU8k1kbO7T8u3RNm9dZIYZxfH6w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4392 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-25_13,2024-04-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxlogscore=929 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404250102 X-Proofpoint-GUID: tnwrxoqCYnjepGI2cXQkNWSE7Ggzn73P X-Proofpoint-ORIG-GUID: tnwrxoqCYnjepGI2cXQkNWSE7Ggzn73P 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, 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+patchwork=sourceware.org@gcc.gnu.org gcc/testsuite/ChangeLog: * c-c++-common/fam-in-union-alone-in-struct-1.c: New testcase. * c-c++-common/fam-in-union-alone-in-struct-2.c: New testcase. * c-c++-common/fam-in-union-alone-in-struct-3.c: New testcase. --- .../fam-in-union-alone-in-struct-1.c | 52 +++++++++++++++++++ .../fam-in-union-alone-in-struct-2.c | 51 ++++++++++++++++++ .../fam-in-union-alone-in-struct-3.c | 36 +++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-1.c create mode 100644 gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-2.c create mode 100644 gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-3.c diff --git a/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-1.c b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-1.c new file mode 100644 index 000000000000..7d4721aa95ac --- /dev/null +++ b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-1.c @@ -0,0 +1,52 @@ +/* testing the correct usage of flexible array members in unions + and alone in structures. */ +/* { dg-do run} */ +/* { dg-options "-Wpedantic" } */ + +union with_fam_1 { + int a; + int b[]; /* { dg-warning "flexible array member in union is a GCC extension" } */ +}; + +union with_fam_2 { + char a; + int b[]; /* { dg-warning "flexible array member in union is a GCC extension" } */ +}; + +union with_fam_3 { + char a[]; /* { dg-warning "flexible array member in union is a GCC extension" } */ + /* { dg-warning "in an otherwise empty" "" { target c++ } .-1 } */ + int b[]; /* { dg-warning "flexible array member in union is a GCC extension" } */ +}; + +struct only_fam { + int b[]; + /* { dg-warning "in a struct with no named members" "" { target c } .-1 } */ + /* { dg-warning "in an otherwise empty" "" { target c++ } .-2 } */ + /* { dg-warning "forbids flexible array member" "" { target c++ } .-3 } */ +}; + +struct only_fam_2 { + unsigned int : 2; + unsigned int : 3; + int b[]; + /* { dg-warning "in a struct with no named members" "" { target c } .-1 } */ + /* { dg-warning "in an otherwise empty" "" { target c++ } .-2 } */ + /* { dg-warning "forbids flexible array member" "" { target c++ } .-3 } */ +}; + +int main () +{ + if (sizeof (union with_fam_1) != sizeof (int)) + __builtin_abort (); + if (sizeof (union with_fam_2) != __alignof__ (int)) + __builtin_abort (); + if (sizeof (union with_fam_3) != 0) + __builtin_abort (); + if (sizeof (struct only_fam) != 0) + __builtin_abort (); + if (sizeof (struct only_fam_2) != sizeof (int)) + __builtin_abort (); + return 0; +} + diff --git a/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-2.c b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-2.c new file mode 100644 index 000000000000..3743f9e7dac5 --- /dev/null +++ b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-2.c @@ -0,0 +1,51 @@ +/* testing the correct usage of flexible array members in unions + and alone in structures: initialization */ +/* { dg-do run} */ +/* { dg-options "-O2" } */ + +union with_fam_1 { + int a; + int b[]; +} with_fam_1_v = {.b = {1, 2, 3, 4}}; + +union with_fam_2 { + int a; + char b[]; +} with_fam_2_v = {.a = 0x1f2f3f4f}; + +union with_fam_3 { + char a[]; + int b[]; +} with_fam_3_v = {.b = {0x1f2f3f4f, 0x5f6f7f7f}}; + +struct only_fam { + int b[]; +} only_fam_v = {{7, 11}}; + +struct only_fam_2 { + unsigned int : 2; + unsigned int : 3; + int b[]; +} only_fam_2_v = {{7, 11}}; + +int main () +{ + if (with_fam_1_v.b[3] != 4 + || with_fam_1_v.b[0] != 1) + __builtin_abort (); + if (with_fam_2_v.b[3] != 0x1f + || with_fam_2_v.b[0] != 0x4f) + __builtin_abort (); + if (with_fam_3_v.a[0] != 0x4f + || with_fam_3_v.a[7] != 0x5f) + __builtin_abort (); + if (only_fam_v.b[0] != 7 + || only_fam_v.b[1] != 11) + __builtin_abort (); + if (only_fam_2_v.b[0] != 7 + || only_fam_2_v.b[1] != 11) + __builtin_abort (); + + return 0; +} + diff --git a/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-3.c b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-3.c new file mode 100644 index 000000000000..dd36fa01306d --- /dev/null +++ b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-3.c @@ -0,0 +1,36 @@ +/* testing the correct usage of flexible array members in unions + and alone in structures. */ +/* { dg-do compile } */ +/* { dg-options "-pedantic-errors" } */ + +union with_fam_1 { + int a; + int b[]; /* { dg-error "flexible array member in union is a GCC extension" } */ +}; + +union with_fam_2 { + char a; + int b[]; /* { dg-error "flexible array member in union is a GCC extension" } */ +}; + +union with_fam_3 { + char a[]; /* { dg-error "flexible array member in union is a GCC extension" } */ + /* { dg-error "in an otherwise empty" "" { target c++ } .-1 } */ + int b[]; /* { dg-error "flexible array member in union is a GCC extension" } */ +}; + +struct only_fam { + int b[]; + /* { dg-error "in a struct with no named members" "" { target c } .-1 } */ + /* { dg-error "in an otherwise empty" "" { target c++ } .-2 } */ + /* { dg-error "forbids flexible array member" "" { target c++ } .-3 } */ +}; + +struct only_fam_2 { + unsigned int : 2; + unsigned int : 3; + int b[]; + /* { dg-error "in a struct with no named members" "" { target c } .-1 } */ + /* { dg-error "in an otherwise empty" "" { target c++ } .-2 } */ + /* { dg-error "forbids flexible array member" "" { target c++ } .-3 } */ +};