From patchwork Wed May 1 16:52:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 1930302 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=VloGZmWi; 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=xajxRRaC; 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 4VV3771kptz1ydT for ; Thu, 2 May 2024 02:53:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8200A384AB55 for ; Wed, 1 May 2024 16:53:53 +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 A52713858294 for ; Wed, 1 May 2024 16:52:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A52713858294 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 A52713858294 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=1714582375; cv=pass; b=BJUdIkRWUr752CzPnrJd+zx4nTxWwZrLs5Kue7x6bwM5WDSSzM5i4gVbBvr38bRoNsVpTsfY04fctBnYHxIZbySh7Pje3yh4Bto2Go4ENx0qZrToc4ulozeDWKzxvSZT/n9waW0PTqTzQi+z4ICr5BvzLPcQHiDgNm/j6Xg1cVg= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714582375; c=relaxed/simple; bh=veylbEe0GS821nSlJ8AXXZhljjO3Ygt6CdstlyGP6sE=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=xvLqP3QbbjHcZiQqT3baW3xAiEFckvILugS6K5SSC4eMA4wwoQNUXU/igeeG8ObalFNEAzQN/y3YwjFyxdQZ+1si+C5605cFD9DHFvHIfsc5poM1pjIY7Y9K8oc4bgb2Qqw41fD9YQon3tIS0B2SL57df1aOL4rcMF55eOJTvpo= 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 441ARxld022722; Wed, 1 May 2024 16:52:52 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=zkm6wVL3/66cl7rH+lTAErx4E38U0WSe2Y8LkekHCZk=; b=VloGZmWiupEL+gnLlQRwrRkW6WT7qD9YSTi5rF3HT1W0DIdSzFIYH1OjYDWSzMtnt206 9yloKgmAwb3HBN0rPqh2FK0xsSLBGQShHpoeuLJiiMdUIJHKyfbrqrGBqTLdTZwi4VIf V1Bm5UhSYH1NUyPYpjH6479+l9yNfHeWRk15Kn6TWa8JOT0Z7pkXYYd+4f9zaefrZDPy 7376FInm9+uYcvY02qs5hsSjUrOYWeTmJVh1UNxvetYKw9CY0UyVa2lYq23sZF3NahXF Jm/e1TP83Ptscq4jJ236K85Z1wHjn+fiw+ud1IGqhviyHTfh29WtrHSydPVxLyVk0vh1 rg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrryv7kdp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 May 2024 16:52:51 +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 441FPNpj011346; Wed, 1 May 2024 16:52:50 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt9h9sc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 May 2024 16:52:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jm3sF4bImZlW+YnfjUIGdETiF3JdoklNcURC49q8Df3HC1ApehztSIBvlrAvvG3bLzM+mfXpuaKN/muekDx8jpyAjatta/GtetxBxWSPsyc57gA7/I37Q+ABI46pQB4pWVXL4Ma3uWwYMxsO4Zw2WTWC2rq+rfVC9b/+B/tlJXnjYhHIbh5I5Li0fqBsDu1E13kf2Gz4IqCi/ADnyuo+BOo7deZqaGomA95DFX41VIrgXXQ/grrnMa9m4gIdYyrZidDNVjMXyUtIyfL6WiRUAo79TqLUZgo3sLw5Gc4P9r5Z3T0gJflF6Jnn/6snFO1BurloWqtDmUrnEP37efnBhw== 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=zkm6wVL3/66cl7rH+lTAErx4E38U0WSe2Y8LkekHCZk=; b=iJclB4Oa2hoEdAamnaE5NXorMTvSjmPVl5pgd8AZGpau/4BW1up5Ao8SOI+uMAI4rFp6ihenAwBBuyoqWVDs4T+beyNsomZcbECod6si748cq7jgi8umFm6WjcQnpXxaXbKCCFXUjQF8HuxdXpsCb2DjlGwlWDrDl0y+IZvgtMrXwPPt76ks4BBu7PbyNYXQdn9HdLGPxHRbozfuKahOBM6XNzV5FAaGBeKS2IM+pNgLqIIdZxK50b2RabP765yME14zXS0BBqFSCFvUktwCcFcZDqZSZTH+/nPh1spvScvQBxbEp8B/ZFbcPyYDVURNqA2gADhI+bzGQL9nnGZ97Q== 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=zkm6wVL3/66cl7rH+lTAErx4E38U0WSe2Y8LkekHCZk=; b=xajxRRaC5xbKtyRwjZP0DsJPPhbkxrNLEGQX9ajqgLJONlRAzuf9hUNkfbDmLiTcqYD3Q/MpztpTcXeRD7Q6coFJVHs/NqwTP/0n0PM/TDm10ccdOhIXZY2fDVfeBkGRHxbFJ1WsctVrMtGGBJpEfwDw+yhDBm4cHQTOqSW3LIg= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by BLAPR10MB4962.namprd10.prod.outlook.com (2603:10b6:208:327::23) 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 16:52:48 +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 16:52:48 +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 v5 4/4] Update the C/C++ FEs routine Date: Wed, 1 May 2024 16:52:26 +0000 Message-Id: <20240501165226.2924144-5-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240501165226.2924144-1-qing.zhao@oracle.com> References: <20240501165226.2924144-1-qing.zhao@oracle.com> X-ClientProxiedBy: LO4P123CA0547.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:319::16) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|BLAPR10MB4962:EE_ X-MS-Office365-Filtering-Correlation-Id: a32df548-3e8d-42f7-062a-08dc69ff219a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|366007|376005|1800799015; X-Microsoft-Antispam-Message-Info: /dmdLhjU+f32iY7UdhmQBTLtznaWj9IXc25qghVKP5W5gvLNJ/8fy7yY9HSPsxBOV427CGwDUH4ptRMGKJHQqOUlrqU2ovMtIIYMnGiLvjp7KibTjBq+W3LIu/GnAhDPwwD60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RcZilQZTqB389Qd8+nRoD/p+JH8xz7V09BoHcnd1X4nHgF9pgDUyEouVOP/DOBRB+/n6f0u+wjm8e/DOcqzA5io7pfsg== 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)(376005)(1800799015); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: D3NSLDcFHoeqQDucfPvPQN6IUIMXbQCYmrr7wjL6MoXQ2b6U3468YvyQrEEkwjCQBD/I+0eigzMdszkh8OBitBk6YDZ+eo0z+DyWoEUJ8ZCNOmk4G1cN5ZUzp5A4zubv6VJp3eW+O51zdb4e24dpM5FvLKwMcf9Yw2De3u3H1HooXCffY0GglHgGFHSAzuUxeueUI+EyJKixCEux4XDEBhiBApAmYSTJ7foR16gdNDNme5rmOh88N9WAeW0dg8E4l3vQ09EqlYip9y0vGfeN/mkeHCpeSDYxJsHj3X6yQw+S2QbEpF32o4gFSAMkSnVcwKs7LOBg83dtFuig6aJQjX492BZ3Ip8wRi0QsvlyfBzle0/ZBtWIB96kguBmaKqk0VsHhrf8C1/8IOJRKoVl+vFBTM3T6ZXXM0kF0zfk/d/3svQs2y0cCk2ncb5uSKuv7TsRY/8QgXkcqm5KEBPAUz0hUMj52y/0SohXQn70gMNaOrNafyIHRo3+nJn8YmXlhoWw2ZA2fZ07k6aqbLOHftcO4Fku+Trls/KNLwyh/IJCvSN16RGCHyh61qm0uvPicB1ATYxrnadxQpyeGQf/0UXYrOqlER015PVQJCrGGLBOsYF7EwxxpKANi8Dxy1THIOGOoADK4IOJvAakvLqjOSAgaqLJbMwt70AALHoYAAjPCfbZT3v5wTT6r9uuexixhrbEfLRrvQp4xcKzhFVdqZ8wUzY31uK8aWmqZV4x1MO50YcX3uvah81VtQc3et41VnZ1AwZ6I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Jm4cICGZl/gg0qrMIOAA88yqcrR0vn30vPLv8xP3LMXlktKhpOFywNVfYu/C1zXvaAMZ4wenl/p0DxP+XBeZjd9MyD9H1fIJH4Qi8x+xXjkv0qWQE7VKQvyEP3DxH67eA5PYkKvQayonz0aJVjpYGwD64TWSdo1ly5RC5Q8KsC4dtxrIEL0RmUKUbOQKCUdjWo9CLw3mH5bFQJ8XYLTSi7obDzUBdKpkq+YcGKK5fBpol0UGo8LaztEm9WK49euKWuGtTOxTr9DK4MHiTna3je3jX1hFfGsj1/oQTEmrtW7ONIIxXH4n5P74BjHUtJOHgBKFi1NuaTD+/x1KfSWbf90sJGWP1eZrjEX/nPaoo9dCAyCUbFUcVYGzcOkTKw1Q9rz/MFNufxvtV9u7lyMeR6rMAHGwXcaGvYP5ssfDsAasfMRHwNHmNfSzItY/I= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: a32df548-3e8d-42f7-062a-08dc69ff219a X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2024 16:52:48.3824 (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: anOEoqE+VFnhTH/QtCKKKjd+xnnBYfmrfg25lE4B3MnVSrLDNukLBtncuglnGw3oNLlBqCwVuM6+LnB7lDgXdA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BLAPR10MB4962 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_16,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-2405010118 X-Proofpoint-GUID: V4skguybmTyUd39akRIDscxp4gRRdXii X-Proofpoint-ORIG-GUID: V4skguybmTyUd39akRIDscxp4gRRdXii X-Spam-Status: No, score=-11.7 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+incoming=patchwork.ozlabs.org@gcc.gnu.org "add_flexible_array_elts_to_size" C++ FE routine "layout_var_decl" to handle the cases when the DECL is union. Add testing cases to test the _bos for flexible array members in unions or alone in structures. gcc/c/ChangeLog: * c-decl.cc (add_flexible_array_elts_to_size): Handle the cases when the DECL is union. gcc/cp/ChangeLog: * decl.cc (layout_var_decl): Handle the cases when the DECL is union with a flexible array member initializer. gcc/testsuite/ChangeLog: * c-c++-common/fam-in-union-alone-in-struct-bos-1.c: New test. * c-c++-common/fam-in-union-alone-in-struct-bos.c: New test. --- gcc/c/c-decl.cc | 29 ++++++-- gcc/cp/decl.cc | 32 +++++++-- .../fam-in-union-alone-in-struct-bos-1.c | 66 +++++++++++++++++++ .../fam-in-union-alone-in-struct-bos.c | 45 +++++++++++++ 4 files changed, 159 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos-1.c create mode 100644 gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos.c diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 947f3cd589eb..5d571621d915 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -5337,8 +5337,9 @@ zero_length_array_type_p (const_tree type) } /* INIT is a constructor that forms DECL's initializer. If the final - element initializes a flexible array field, add the size of that - initializer to DECL's size. */ + element initializes a flexible array field, adjust the size of the + DECL with the initializer based on whether the DECL is a union or + a structure. */ static void add_flexible_array_elts_to_size (tree decl, tree init) @@ -5353,10 +5354,26 @@ add_flexible_array_elts_to_size (tree decl, tree init) if (flexible_array_member_type_p (type)) { complete_array_type (&type, elt, false); - DECL_SIZE (decl) - = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type)); - DECL_SIZE_UNIT (decl) - = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), TYPE_SIZE_UNIT (type)); + /* For a structure, add the size of the initializer to the DECL's + size. */ + if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE) + { + DECL_SIZE (decl) + = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (type)); + DECL_SIZE_UNIT (decl) + = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), + TYPE_SIZE_UNIT (type)); + } + /* For a union, the DECL's size is the maximum of the current size + and the size of the initializer. */ + else + { + DECL_SIZE (decl) + = size_binop (MAX_EXPR, DECL_SIZE (decl), TYPE_SIZE (type)); + DECL_SIZE_UNIT (decl) + = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl), + TYPE_SIZE_UNIT (type)); + } } } diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 9a91c6f80da1..78e21b05296c 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -6555,8 +6555,9 @@ layout_var_decl (tree decl) } } - /* If the final element initializes a flexible array field, add the size of - that initializer to DECL's size. */ + /* If the final element initializes a flexible array field, adjust + the size of the DECL with the initializer based on whether the + DECL is a union or a structure. */ if (type != error_mark_node && DECL_INITIAL (decl) && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR @@ -6577,11 +6578,28 @@ layout_var_decl (tree decl) && TREE_CODE (vtype) == ARRAY_TYPE && COMPLETE_TYPE_P (vtype)) { - DECL_SIZE (decl) - = size_binop (PLUS_EXPR, DECL_SIZE (decl), TYPE_SIZE (vtype)); - DECL_SIZE_UNIT (decl) - = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), - TYPE_SIZE_UNIT (vtype)); + /* For a structure, add the size of the initializer to the DECL's + size. */ + if (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE) + { + DECL_SIZE (decl) + = size_binop (PLUS_EXPR, DECL_SIZE (decl), + TYPE_SIZE (vtype)); + DECL_SIZE_UNIT (decl) + = size_binop (PLUS_EXPR, DECL_SIZE_UNIT (decl), + TYPE_SIZE_UNIT (vtype)); + } + /* For a union, the DECL's size is the maximum of the current size + and the size of the initializer. */ + else + { + DECL_SIZE (decl) + = size_binop (MAX_EXPR, DECL_SIZE (decl), + TYPE_SIZE (vtype)); + DECL_SIZE_UNIT (decl) + = size_binop (MAX_EXPR, DECL_SIZE_UNIT (decl), + TYPE_SIZE_UNIT (vtype)); + } } } } diff --git a/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos-1.c b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos-1.c new file mode 100644 index 000000000000..aae9cf39c8c7 --- /dev/null +++ b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos-1.c @@ -0,0 +1,66 @@ +/* testing flexible array members in unions and alone in structures: + __bos/__bdos */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +union with_fam_1 { + char a; + int b[]; +} *with_fam_1_v; + +union with_fam_2 { + int a; + char b[]; +} *with_fam_2_v; + +union with_fam_3 { + char a[]; + int b[]; +} *with_fam_3_v; + +struct only_fam { + int b[]; +} *only_fam_v; + +struct only_fam_2 { + unsigned int : 2; + unsigned int : 3; + int b[]; +} *only_fam_2_v; + +void __attribute__((__noinline__)) +setup (int n1, int n2, int n3, int n4, int n5) +{ + with_fam_1_v = (union with_fam_1 *) __builtin_malloc (n1 * sizeof (int)); + with_fam_2_v = (union with_fam_2 *) __builtin_malloc (n2 * sizeof (char)); + with_fam_3_v = (union with_fam_3 *) __builtin_malloc (n3 * sizeof (int)); + only_fam_v = (struct only_fam *) __builtin_malloc (n4 * sizeof (int)); + only_fam_2_v = (struct only_fam_2 *) __builtin_malloc (n5 * sizeof (int)); + return; +} + +void __attribute__((__noinline__)) stuff( + union with_fam_1 *with_fam_1_v, + union with_fam_2 *with_fam_2_v, + union with_fam_3 *with_fam_3_v, + struct only_fam *only_fam_v, + struct only_fam_2 *only_fam_2_v) +{ + if (__builtin_object_size(with_fam_1_v->b, 1) != -1) + __builtin_abort (); + if (__builtin_object_size(with_fam_2_v->b, 1) != -1) + __builtin_abort (); + if (__builtin_object_size(with_fam_3_v->b, 1) != -1) + __builtin_abort (); + if (__builtin_object_size(only_fam_v->b, 1) != -1) + __builtin_abort (); + if (__builtin_object_size(only_fam_2_v->b, 1) != -1) + __builtin_abort (); +} + +int main (int argc, char *argv[]) +{ + setup (2, 3, 4, 5, 6); + stuff (with_fam_1_v, with_fam_2_v, with_fam_3_v, only_fam_v, only_fam_2_v); + return 0; +} diff --git a/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos.c b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos.c new file mode 100644 index 000000000000..21badc57982b --- /dev/null +++ b/gcc/testsuite/c-c++-common/fam-in-union-alone-in-struct-bos.c @@ -0,0 +1,45 @@ +/* testing flexible array members in unions and alone in structures: + __bos/__bdos */ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +union with_fam_1 { + char a; + int b[]; +} with_fam_1_v = {.b = {1, 2, 3, 4, 5}}; + +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 (__builtin_object_size(with_fam_1_v.b, 1) != 20) + __builtin_abort (); + if (__builtin_object_size(with_fam_2_v.b, 1) != 4) + __builtin_abort (); + if (__builtin_object_size(with_fam_3_v.b, 1) != 8) + __builtin_abort (); + if (__builtin_object_size(only_fam_v.b, 1) != 8) + __builtin_abort (); + if (__builtin_object_size(only_fam_2_v.b, 1) != 8) + __builtin_abort (); + + return 0; +}