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 584F33849ADC for ; Fri, 19 Apr 2024 18:43:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 584F33849ADC 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 584F33849ADC 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=1713552214; cv=pass; b=o401QdC2j6AcAOyh0AneVulgoocXdOzwClJrh2Oz1doxIEjcpdooFKMX2/Kqc/pf1TOwgVMIVBLSPEA3vT/l9+kpBwITBXfKsdyRK8n5nvMG4jIaV66JRP91c7yQnW31cQgCBNFxauVcmrTKvM1vROYDctVmuzQR42kis2S0NKs= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713552214; c=relaxed/simple; bh=2rSlzJHcPUvVIsyq6lIpjDtHKdF5dJzw4vw1xIrGE9s=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=dgPhwCHwFW+BY/DeOGlcb26ZtV9EfTGAHSfxt33qNkmXZxIn5hEIgmveNqWdPTl+3EsrGR2KC5evnVWxxEGDyBwgw3QJ5tuVynyBkNa2H6KCI/2jKUecNrMkGBmetqhhmsCfcbTbrSQm5AAFgCE9Ei6lan1oTpPVr3jDFgCV69k= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43JIO5IE001391; Fri, 19 Apr 2024 18:43:31 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=tKwo2NgN5wPJhvESoualwC1cxr84ZSdWkl4T9dFnwhY=; b=dDqELpKlazrMTf1HOp0qWG1yFwdKzfpI5Zm/G9YbaQsebpkqa3FmFq9dUJlmSzsAzeJ6 R2710xfHXrsg/a/gZNrRed++0tE7PMdNauRhEmy8dues62QrVAEi9+Cl49PukW9N1ADd 8+XXQ77lHD7IPY5ZV+lnO58j/oBaSbX4xo8vQc/VZTfWr+gzbSlzuJSvqesmYFKotmab idOR9W69xcCrRUqTDihbUvk+hRIsC/Pl53vC2LBhYuj4YxU6no5Bn5Od7i53MCDDX+4K zo+QO3yp0yjr1/vsTKaTuxuU68GU/JDn0RSEcR92KxFB9/H5ZzyX0wcd3rQx+ZcXiNVL AQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xfgujwng4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 18:43:31 +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 43JHLAk3014319; Fri, 19 Apr 2024 18:43:30 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2170.outbound.protection.outlook.com [104.47.58.170]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xkc97xrwk-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 19 Apr 2024 18:43:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xc+bP071gdg7olxEE2awJXMZ+Pg5KNPQtrFzCw1SQe7+bNPPmccMmr7emAaU1kcRE/utKaASIyTE1zXl8ZgV21J1wf4BFoPy6W2epLNU2OEZu/hCzcTbJq35A57E8Kg6vG3J8iiNdyYvxpUOeg+SWmM1bnIxwLYPdAXrOUd47HndUtlsAPYtvCUeSw+/Sx73IHxhHEWV0BiJN+VG3fzzxaNOtiQYl0qSX1M+Mhex6B+o/VUC1TfsAnFi2rKPl/M7xJ0/sPqAlGPWjrJNgG3EsS9KXGXtbQBg9WtcQ4R+bI+gh25EQsQetLKAisfjjn/g1FvzQreZLoACb/hSXBvq3A== 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=tKwo2NgN5wPJhvESoualwC1cxr84ZSdWkl4T9dFnwhY=; b=bJnSah8fi7U7w10i/zau/Oer5t0QPRjWFcbIIogWT+kJ+XIHc/C+8Rxh2/X71v5MG5cnmgKD76xHzzfT1GBJ8XtH7DFTDyXNKevB4a2/xPWZsmFvxJL8KH7iR2QC+RtSEV+ftF7azBrKniL8jgb6mkJZY+hWOpWSBwZ6eVAy7ZOvSy7hJpPORa93ag1KrBNxwzEZToYSxeDQKxrFiagmk46kyHe5p7BnVJ2iPtkqSDIS54Tj8T43s5zqLzf1T1x7K0c7NtxsMyyGFzyJur9wUtnQ1Kk3o6Exq0wDnzKuhh5tBPtW0ztEAUNfQ2VFUWfuTkZ/YBnM7j9Q22zZVGRcsQ== 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=tKwo2NgN5wPJhvESoualwC1cxr84ZSdWkl4T9dFnwhY=; b=YF3xb4N+Z1W8bX3572ebPMSEBeKS2en7+c/IVMhQEvZ5EiAYIXWVRQm2nDV1/okjGua+SM+kc4/ej34hz+c4irrcktCnqsGV8OufsNBQ6EwVtiCPud+2n7tVmQ/6NocEIgiU9MqPsqA3zs2xD4LZN6uGZBwkbJQM0Y4+FdojABE= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by DM4PR10MB7425.namprd10.prod.outlook.com (2603:10b6:8:180::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7472.43; Fri, 19 Apr 2024 18:43:28 +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.037; Fri, 19 Apr 2024 18:43:28 +0000 From: Qing Zhao To: josmyers@redhat.com, richard.guenther@gmail.com, uecker@tugraz.at Cc: siddhesh@gotplt.org, keescook@chromium.org, gcc-patches@gcc.gnu.org, Qing Zhao Subject: [RFC][PATCH v1 2/4] C and C++ FE changes to support flexible array members in unions and alone in structures. Date: Fri, 19 Apr 2024 18:43:15 +0000 Message-Id: <20240419184317.2138890-3-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240419184317.2138890-1-qing.zhao@oracle.com> References: <20240419184317.2138890-1-qing.zhao@oracle.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: BL1PR13CA0283.namprd13.prod.outlook.com (2603:10b6:208:2bc::18) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|DM4PR10MB7425:EE_ X-MS-Office365-Filtering-Correlation-Id: 69cd157e-95d5-419c-ee97-08dc60a09aa1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8VL/cmjSHoJs1LNT6b3X3bz3RmBTH1lJNMHA1oyQmYq/2LJJz2lTY+bUwORB4rGFhfrq3hSXjeMqxDA5bp4o/dPXtuuU2kRGHmyWmm/aft4JfqMHVpKRQsfhCl3FEWHs5sM4bnXmH0ozr9FXBO1Yw8St1Qfaje6Hgypt6o7XgwmlP9p/jEHV3+SyLJwxuK0mOaSylQTemhrBxrMHujsjRlH2HwJXFcpIUO6Jk8vy18Ge/1a3B21VSumwvGfeYVPVX7JwhCY7Grg2TT1/7IW4CDVADqaKMokhxnjnEuD0uBtx8Yy4gSJiOk46Kj4PtApCHONsgLF7/dzU2wsv+rMNXTiuhp+5SW2Ld85KyOUyBOJODwZTJPTheoVXxVh2OWCs8HtpKJbLzguhsnDcWYbzgG2FEBuReSLkaB6ANzZg6x/+zIO1IRbb6ATbfjo2EoHTns/y2J6zlsYeXoBN6jShJoTJKgx+RmCxSDNEh7W4lqBp3r9WNrryJ0YE/+X6NxDq5rVUK7x9seOdYEi62UFODBOleEZ020sdI9NGBPlnYwJ+Dzt6YsKB00ykZfxIwJ6lrLMgF2oGGe6cqR0ScYr5Y3/pAdTIUuDZi3XM30XdQZcsLJ4v96K2gZqaUXDs6iS3w8X2h7R4Pq08mIp3e6nlvtS5/8V36kPa1N8IeguQI7A= 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)(366007)(1800799015)(376005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?6HG5QDXaGSw5EnyT0WgJ5sDxLKlkXMzEyHn1LuylGHYSJnBhO80M3ALcPH4x?= =?us-ascii?Q?BrRO/wATOWUIxaVg+1WSV9YvFnIMjv7QMj+8yW2Rwfb7RTvrJ+5wvKcJXWEm?= =?us-ascii?Q?q0+HusdKL8WkmFDaiC/+xiqFIoAonGqqc09NalC1t7GdfllWugmuYYrwh4F9?= =?us-ascii?Q?WNiL0DybzcHw3KoFISORijxobcfKZF2bkGzdBi5rUZFGSr3SAZXovMUHfuQr?= =?us-ascii?Q?N2Q6qNvWj6kNejplm6SfPo7zJhIRoWgZTxL1P1s6xQ/gsoHB2XBaZoTsHhbB?= =?us-ascii?Q?QJ1Z80TiIPiw4OvuSH+g++VGh8zyF9ac/eJ1XjHB5vvYhVtIIpSU74krkJlN?= =?us-ascii?Q?pgxGMSzFyBqDmThYnAD3glo/qJDPF8BKcjh3dwWiWfrZ9Fq0xnOa5wbMVFTb?= =?us-ascii?Q?HHZx6AdolT0ytlzdyFn6hLk62LGi8hYAGAGW7p0YeUUOIXWe0W+DW0QSepe+?= =?us-ascii?Q?+HdXXwybj5eHEkDP284azUOPo9pZgvAY4ZGa45/hZqkXdTGUsjDbOKy1dlKx?= =?us-ascii?Q?4SZNIDDsHgxZaEzxFMOPOO/AwF3QxRJYF3IovjH+yHjzjhTVEC3oVVNFnISU?= =?us-ascii?Q?5ZvIBcnh/jr9A5HccFLeIqCAXWaLov38kaPM+Um3cbzSssi8CqVXKDpY1XEj?= =?us-ascii?Q?4EErp1KonDJ2U1+LFtISk8jM1o3s5U+9L3tYoGQE7FrIXZN05CtVbqIrZY1N?= =?us-ascii?Q?34pDT5jfQkTFDFQMtNfEhGj5cgjTG+4QfnFzsuHdKwQfNduZqBjRTy5sH85a?= =?us-ascii?Q?LeZ2bHI/VLFYSKbzG6eeWpjHJ+AD+dtpccCldYWgJ2MVo50OHLW0pof4i1a4?= =?us-ascii?Q?w3d58OW5/M0xbzNpM1gp8lhiDLMBOyLYcrwVk10Z9ft3Oou/lJTom9cU3ifb?= =?us-ascii?Q?MU9tf+AUccs34qG+HP73sYwoRRZsw9KUoNVtTmvDehpQfO6fSiUIzVhbLyFn?= =?us-ascii?Q?ZP5ZnF8RPhJbSzUuevABa9CzBDTUfn4uZ5dw7ozede4Kd/Pv7CK2kFYbzGNn?= =?us-ascii?Q?8KvbbOw2zvmDP8+CFeKUuf452vqFj+icj95HdXU0FqUIBf9vRTctEmmHlLrG?= =?us-ascii?Q?5WKrdkZnuLsoGwxuJxDW9dhIncvyvKbrG4NQ9nPt/MHWd7fcaNOvGKsTniGh?= =?us-ascii?Q?QVxiXQl5WYsSfe7Muzvi1WZWsaJ6+R6MYsam2R3ypOmnbq48fl1MF+l6jADB?= =?us-ascii?Q?SvsxDImbN0dfhqlDp9D0x9cIcTGuX1JS1s8ZuSkBASOjU83XSelB1cqujdEY?= =?us-ascii?Q?78jj41RmRbs8IHTkvak8z5mq8c2cuNtOeklVqBUW12DYIhGQm/iRUEhypTTe?= =?us-ascii?Q?eDyGesw3QmEimm5E5GFSMli22fG3t8m2RoRDTMJKfe25L/enjrz8bP78lmgS?= =?us-ascii?Q?WBqOkrU6l0BjgRwvvg+/AEieD85kCB2Knxo1gvXqKfCaL1ICN2zrbsctWS79?= =?us-ascii?Q?/6/kNcIEQ5XjG7+Hapi/FSJN0opZrstwpP274uNsvKyl/X+CvBcAUaDQQgy4?= =?us-ascii?Q?EjfSQKxXy0QPJmnlTLxszl0bGLz/ZwDRT3CdLK6Vy1uSmFnOWOd8Iu+zRFG8?= =?us-ascii?Q?aG/+gHVn3OW2MfCe/4P7LUI0RBIrowBNR8VldDpM?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Fmv01sKVn7b61bfv2WXpxqdbCbPqBlHi5eqixYQsWTDbMcl4xEb2H2MrQ0Y2JRSdE6ReFb3L/eVO+EvWHX/NjT642IqWMeddXfTFVLGudVDPL2I4VLmc9dHyyuUh77UoojqiO1Xuq9Vul6qJCspO3Lj7g0raTM4yUrvp7Yj2s00ke1DH6koOiu67Tspam5MaLutr3uML+DazJTyigxnNx/9XMmGG8GfxeKkJkDJZcDnSj1ifH7gywSH7KhdM9FtsXSU8mzUkh8YubyUpmAuJA14SS1Jsptap1+WiCWH+ZOg+DJZiR6TYJ6Csk9qa3diP0/otryLUwL1W0gZi7m9OGKqOcH5YLmRb97bJkt+H4rpz8BNh1O0UCAAn+HD+0fJO+YrEexx1v6Z6SGUJMZcIryrdEEeLFwlVkb+JY9Xn64UpnBvzVHpRutizmn6/JUx7IYnF1/cqIw8CuRhjZqrdu8fqfl0NjfyLI7gMr+mFimsRfdvL00Pa7nnYdWPRbLOBYWD19e739zw1DXEsHByHgyLtceilFWUua+iSj/uaSn81X9zuZ2XQ35DA+Na8Z+C/fczI7oQAX7W2QGoams36VbZHaIiasH+0nZUVkQ8HTu0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 69cd157e-95d5-419c-ee97-08dc60a09aa1 X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2024 18:43:28.6134 (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: 4UEBTX3duav1o7ux2MDEGPS0oCmVkgMjVjkKiifZmjMSp3yQJdG2gpNyYMOTVpbhfL1mC8J72NRxYhdpD18N+w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB7425 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-19_13,2024-04-19_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 adultscore=0 mlxscore=0 spamscore=0 mlxlogscore=999 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404190144 X-Proofpoint-ORIG-GUID: juh-hyPNkXh9n3ELD4QIeHeT4bfkawSR X-Proofpoint-GUID: juh-hyPNkXh9n3ELD4QIeHeT4bfkawSR 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,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: 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/c/c-decl.cc | 16 +++++----------- gcc/cp/class.cc | 11 ++++++++--- gcc/cp/decl.cc | 7 +++---- gcc/stor-layout.cc | 9 +++++++-- 4 files changed, 23 insertions(+), 20 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 -- 2.31.1