From patchwork Wed May 1 15:19:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 1930256 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=R9Tvn20c; 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=jew6QtPh; 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 4VV1484pqDz1ymc for ; Thu, 2 May 2024 01:21:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E6BB33858C78 for ; Wed, 1 May 2024 15:21:10 +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 4DB1F3858429 for ; Wed, 1 May 2024 15:19:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4DB1F3858429 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 4DB1F3858429 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=1714576785; cv=pass; b=Hd3u+Q81tUa2WXJwfEpgp34Of/kuvqsxi4EEbLeG3NlCqSYrVZicVQm71RNeUQE2v/rdq3OG2Vv48y/UAlHhniB/KmMjPdVyoq1p82KfsfCZamcazXhh1HVMu3cs79hiN+8odChzgy/2n2iYWH+kS7Ad2Y8pMP4CIyQgX3YyZCE= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714576785; c=relaxed/simple; bh=TD1voB6vhRbU2sETMgRNJLbd74eDScWPshhveuNkMQM=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=kapzpDqzMfzCiR7xGr8pYlBKyWMbH81YW5/yRW6eZ7P0ajb0TO4ibcJf8HsO4ZyCz/k41MLJVQ+yhBPS1QJWYLOsRxsnkFqXUdxk7hizHa0vgev4H4Ic8MxNcK1x6cfgoH1wiJZnoTJUgor1GvEH+XuIomNo4N+qoNoSP9UkBL8= 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 441ARlTW024843; Wed, 1 May 2024 15:19:40 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=nk9otAPwnd5zx4lo7eUAkvQ4+YyuRIdjoAOZdaJYWQA=; b=R9Tvn20cA2kxl3vuu0JQTT4EgAgxgNrn+4uClNlYsRZujRyFZApYtAErZE1+zP7X8Wgy r22OX/FRWtzUgWktgwOgJsep2iUiRbdQj0ym8tOJ6bHr+tVLEilfsI/fQ0ilqLhXBxnK pKwiWTRU9XaPBdOfbWyo7VHxfgJ6PSfi+34W/GQXu/4UtYMYfup6HnYNCACKLg9J3wbY 0Z1YYEq1OJDHI4wHTNtsVkwFdZVqvKqpWQlTUiCAPG/BOcaLEOt8JYJ6hM28LUWkY36m ISSR3kZ7OIvf39AzMSigMUw9K+dXBcPAdSjPhYyq1mgFCE/YDQ/yfvZnxgOJZXT0MUQ7 yQ== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrr54fdsc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 May 2024 15:19:40 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 441F3MS3005048; Wed, 1 May 2024 15:19:39 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2169.outbound.protection.outlook.com [104.47.57.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt8xafx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 May 2024 15:19:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lc94gKVHMic4yFlT1hpu9gASg+U+rcKvdoljdQsMoxZ+yFPAvSiIZheoRhNzk2zAtEt6B2Rty9PC1MohWibIPDf7aePi4g8UXyiXov5t2I7in0M5J0fNDPmpX4AND55p4IRIJNvfvr1xddn5xBB4Tpx/8q/LwRU9iY0vru1EYiswiyE5TcQpD1ELbkmGFgKvEa18oGJBkM7MwRAK9i/1/0cbM5znY+oNzJBrIEYy6J5AiNDGc4FmUUTewCNRr2iGn3M0ukOKUJTX2AoIkiFp4001q9ariStiQFk0X1SlpSGdVGXE/TGFdVUoSJm7/qB4vae6ICQVFRV48JnwOOrZHg== 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=nk9otAPwnd5zx4lo7eUAkvQ4+YyuRIdjoAOZdaJYWQA=; b=NqKQCKnEZYH3w5RQyNdsv+cZOVnf7emJPSvi0gfMFF4EPEkRhq5OnX0WUvgllfag5J+fpV7CG7LHvUv40PN6VsFqbZQi3u8GViZzUsiE+eZ1Zfixieyza+oi2qn8Se2dmRnUVe3gihDGM1539eo1XxQoukAUU8OsjrSOj5QYgeWaKLYjxCDIcyQHSr3sVmAwd62tsYMnu+r961w/ATtT8o15o1papMX6gR9TV/dyd8hze2fduuh8VCvB9iH52U9FkXutwmL6RROrIXVv9W+iHU+oMynC22u7vytaGn8hJmlVewX64YFP00ZGkm3ePevUjxFgrwrBYjQyriVY54zBBg== 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=nk9otAPwnd5zx4lo7eUAkvQ4+YyuRIdjoAOZdaJYWQA=; b=jew6QtPhl1eil91QKPs9im9Iup0xblFQpqAzxNtMbxeVN3QkZ1YkpXeYNLubr0mN5pW+5VkqhyQR2A9H4b6MK5CieKWCkJagnq/08lk8FQYIJLki4LVWq+idzhocUn9HSRe9Pf6PnMz92kD281dufOyA1iLF0r9XU8PtKHk85U4= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by SA2PR10MB4794.namprd10.prod.outlook.com (2603:10b6:806:113::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.28; Wed, 1 May 2024 15:19:37 +0000 Received: from CY8PR10MB6538.namprd10.prod.outlook.com ([fe80::2dae:7852:9563:b4bc]) by CY8PR10MB6538.namprd10.prod.outlook.com ([fe80::2dae:7852:9563:b4bc%6]) with mapi id 15.20.7519.035; Wed, 1 May 2024 15:19:37 +0000 From: Qing Zhao To: jason@redhat.com, josmyers@redhat.com, richard.guenther@gmail.com, siddhesh@gotplt.org Cc: uecker@tugraz.at, keescook@chromium.org, gcc-patches@gcc.gnu.org, Qing Zhao Subject: [PATCH v4 4/4] Update the C/C++ FE routines Date: Wed, 1 May 2024 15:19:23 +0000 Message-Id: <20240501151923.2895074-5-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20240501151923.2895074-1-qing.zhao@oracle.com> References: <20240501151923.2895074-1-qing.zhao@oracle.com> X-ClientProxiedBy: BL1PR13CA0262.namprd13.prod.outlook.com (2603:10b6:208:2ba::27) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|SA2PR10MB4794:EE_ X-MS-Office365-Filtering-Correlation-Id: eeeba625-6fc6-41b4-31c0-08dc69f21d15 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|366007|376005; X-Microsoft-Antispam-Message-Info: 2Nu0JM8p7ekXUqurnLkcL3iTljiocV9BGwIr7AeVzpxiIoufWS8iYHf0KY3JrSFULgpGvpwYHN5hVOZksT3ScL8nsh503nKaMc0Ei5d3S4l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/GO8heI4XyQUaRnIZa7WRL3PhmMj+jXLrYcYkzddgTaY2yk4aEg5pfVGYKcBfA8G+mMUvzFx3+T4CeUeSgfLjGaQtb9UqHMbuWdj4NR3ZnBXQtgTL9//UPnvqgLxJfMXx5XdRtw== 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: pWMOUouuKLEc+z2Eu2qVJCC0EJj7qRMtYRslILw3H4HWztzyhWLgR+csI8DQDp6tWFGGIHkeCf/0DW2ux2cxJQDQsvPgZL0iaSRt0igKCQ3mcvgAfosE05so/3rD4de8WgDPIFHBLHL8Xe/kErBiJTGda5Gvl2cLZStu8Yb0y9M7BnXSKXtgRVZ7nDeHEJtpETO8kTq5lj8/iPz1l0NOnWFDjPb+XX+2kEMolGw5E1ReGxP5KftisoqQHf1j0D7jC6SL+r/3BkG9bIuHx7kI1r+G9d8LECYylol6hCPuopUMPJVRBkAgBwA2F+3AVkBIOFmTDVnMOHWDPUunZlx9ejlG5fYxNi8gP8zTekYFGCbjqYhZtdAo+GCH43TrektavDsxPVbf+GERcwi/SV0vmyjjiCVBSsIiFok7tidy9l2lXnD297cpnL04+SHstx4hFLYN5lRiF522p/KwsBw9Xcm0aKFTWuyV9rRvDU/t76V7tV2YrlnlF+UgVz6jglk5k6ZJ6wLJxMLi6EyQ3GAAJskZxXAI7HZImNo84p0xPyZ1Oukaelr6rZKo3aQgkobpTK6O+LvHj0CL3nQvGrnSkNXJckJ5r0VzFCUfqlfioQca0aymd+aiYal44e2wPIkyX/QHbpUS0NouUD3f1NOFPHbT/Rn1swG/fBru2zfjNiJ5OnOa+Q0rr9My0OCNPokRVBC7Pj5SdbeNQ0gr5gPiR1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6yF7Up7vTX6wT3sFKWaqf/he9YRrZzwZQr+NPdA3A4kuYeVVRpyar7jyzAlRFl09afQFOuCwe929vatnz0FGmYONFLlTQWxAOQSplhquPPWrC6GFu7J7/mH6YdWdyicm7fzU2LWCJyCTKuGGUCy+GAub3kQicJKh1+a2ux8QeObwAkcUb6RY3/0rpPXtmzeJeL9x7QEmWpUuwQolnzxCBhlO5XO/LeBO+dno2/tmbw3LzwOVYwfuv3FhDbaHIpsFglw7uRpk3zT5/8IzJgyZgfkwIvzYailPAd/pCw5CsT7elw6YlzBeZqVZhKEdXoEO6yW0Mx/AVn8lU/xGx9bo/2R0VonbHoowHf8q/f90BBZGSMFMiZdwUmgoLBBa5WZ9C9oovt7Sx9Z/HM/zd/bYvkA4JlSh3mtJThRIjrkXuyzWSGh/br9tCB6v+VEJ4ILuwxDg3ExQd8mxZOtF03IK/RT6YLVb155myZIQ/m4mOzZWTUqA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: eeeba625-6fc6-41b4-31c0-08dc69f21d15 X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2024 15:19:37.1940 (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: wF3ojP4Vhv+oEZlrc5sdJFSWvaS1/I72Yg+psozuwcMFcNscJ+1ywR+0T8jfzDDmnj2xImJYzBgJuSPyLBQPCQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4794 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-01_15,2024-04-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 mlxscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2405010108 X-Proofpoint-ORIG-GUID: zBALXcwK0lK6HIjMBdkb2MkrVOW3Sn9H X-Proofpoint-GUID: zBALXcwK0lK6HIjMBdkb2MkrVOW3Sn9H 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 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" and "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 | 30 +++++++-- 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(+), 14 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..9ba92690daf5 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -5337,9 +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 +5353,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; +}