From patchwork Wed May 1 16:52: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: 1930300 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=Df0839PJ; 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=GonG02V8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VV36C22cbz1ydT for ; Thu, 2 May 2024 02:53:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 74EBC384AB63 for ; Wed, 1 May 2024 16:53:05 +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 2E49B3858D3C for ; Wed, 1 May 2024 16:52:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2E49B3858D3C 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 2E49B3858D3C 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=1714582362; cv=pass; b=Jfbm39bx94VQQte4OEiiB9rp2IKVZy4f6oAjtDXLBaSOPuWr0sJjVMoClF46AzEBgt41wKqhnYJUJ3hzUPmbVY74X3wz93kJZqweZQDfWxG6itFE/jtxCjxtaLHM2PBELsf9loeDaw1qKQWtN6CHYOrAAnEiFr5VCL8cK3lympw= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714582362; c=relaxed/simple; bh=6oUW2R+bJUBL/Zjg9LLO8CH/1RsLDlvHN9ogaFrF2bA=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=tzRUcjmIDkkY/p1kindnsQ62h+TYRP1hkXG6LUcQa0MAt6N8MvdA8mwGncZtUd4WkPkK77KjnsExvF67LHKCiw7oPsIA5szuov4+ovr5n8M1EhgzxVsTU9LlKcOQbawFm7bLrj/hJuVh4GryiyThfvTTgkOflzeTjkoAEV50cVw= 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 441ASZqc026654; Wed, 1 May 2024 16:52:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=RfWS0bbbQXuQoMO30xR0U6tJET3SZVol5UI7GNAjA1M=; b=Df0839PJsNQypW+ziRRR1HpBhFZzHvD0mIG07OpAS4b+z7pYOsi56CigubIEjp/4Qayu 2l3xeKwaxBMabG0z6kqRENBFZ0zPb2DPqJf0uL4pY7BhFLe2XnXxpqMbkiq+CjMAmSNe bGzA936F1gw0xuS5hlUMmlYRgevAH9dDQhfVejGoxpK7QqQFyr9n+JByCy5FKbq4Ji6g fkR24ZURZu73nzsgXjorpbfOiExh9lJ6RB9lfoH9+p6SRzUYY8/WBHZ4750zCRp5rYpi 4Z7xCcqlSj8wizZySGvbPAF8Pk8ZlqiVOTL9v3NLfQgPVZJoZNrbAlCa+fi5YHPSSRu7 /A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrr54fm3s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 May 2024 16:52:39 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 441GX3MH008539; Wed, 1 May 2024 16:52:38 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2100.outbound.protection.outlook.com [104.47.55.100]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt9kpwe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 May 2024 16:52:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AbXpfUvxKas4SSNWW0beXbl4KbzF84vZjumRx2O0+px28ByP5Xd+ihBoUiTHDhohlTTuk/mdgdB1x0p0XiJFkCv7D4V/kIbKzUCSHUh6WS9tC2wBGqMZPQ/+sHV9MJ8nwUE0WG6H52sT6tgq+DNdYrar7hW9Ul//WE3Qoc6bEsaV5b7MScUxMwW4+Pcr52IhIOk9n4pa8UBlCT9L5DMp3dptDpvLZKIYGUn7Pg7w2FCJrCYkyNBM9wCgb+4QgFD22shvMcnEeq3IKjvq98EMYsB8gABL1Nt8shSGqJhOPL1g5S5SytwZ6BHKrIINm5RNvZidNsoPIkP4eP4n/OrWcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RfWS0bbbQXuQoMO30xR0U6tJET3SZVol5UI7GNAjA1M=; b=TxDHo/Ias3uW435J2JXRUgLEGKs5hTgXoIe/TvjaIO5uUGEmIcjuvZflTGuemiKS2U45DRqv9+sTNZC/Vm9hsXBugV5pMzB5+zArJkG9IBusr0veIOVs6ULbsD8gy/sCu0Rf3/HKE3idLKyjjtUx8eMgszMtnCefAKDxg2Ut6EsuU5rYDAQ44fAbreaU11mlQ8DZ25OEX+REL7gWG8694CDgRG2UozbdyvcHkwdy6A/c3uQj/qS0Sz3XgM7+7XjqxR5EGeht0R+WaV2GOE66chmb72FoZNaCoZHu1EHLi9IU5JSwmQe5jvZaC0TZH2pJOg4fcLtyYW8UQ/Q3m6YQkg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RfWS0bbbQXuQoMO30xR0U6tJET3SZVol5UI7GNAjA1M=; b=GonG02V8J2ShHiYh0czXfKyTKTtJoPo6CW9bBz1q8uucySQYloqNeilLyPRHixBphQoo3SM2Q8CU4gyxl01Et7ANOGjU/JDpSrnJ1MdZtvomcMq+7SY0ARc93bNgUwE54WPAmK2flKf+1Ia14p0owl79iKvh1Qiwi/kki3KwxVg= 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:35 +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:35 +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 1/4] Allow flexible array members in unions and alone in structures [PR53548] Date: Wed, 1 May 2024 16:52:23 +0000 Message-Id: <20240501165226.2924144-2-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: LO4P265CA0219.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:33a::17) 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: 0b1a091d-c425-49b4-5f04-08dc69ff1a11 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: dAjogySMXL1x2j7x1JvR/iPLktpUUGbR3vDF5uYxnrgVA8VU1YZgvpM/lzPx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4rjvpLrMx5xPEDnfMNaEiRpATnvb6thN+h9ovi55RAsk1642KsFHoQcWt//Diwpu0CAFYp4pkyhXnMJWxyBiiMKYEyUHAqOVqGhL1Abw1+eu7cysmU2VEIW7jxRabTae9SwXdnQ2fJQPbd07z3AttFQf6kA8iTAkgJCa08s5x/mc7yuZwcTACJWkikJ2qo= 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: hGYgDwp5f2JSB9JD3cju29J/Fu06h+3Le4AvFWXlmeMHFO+drIL7xccFLUtuCuuXSWFrLyHWDFd8H6/1KpKZyr5r+RzXrQOdaVlLCSspMSv9IRGhr9OJtYF++rzHV8jXh0aNU44cDjsxOWORv8sQ8Dj/AXy1Z1sBcO577vbzbvoaRdVmKpUcl2veHZi5qMNBwFtlYMLlWgWVZdX1eZx9Q3JojRBn0eqWQ/hrtdFH8CSzGcc6rslw3TDjdXbEgPPQhGREUgKA8lccUZnmv7ZDEdBQKBi/b/fgC3xLnVVpE1g9sJ/noWFPliik8EoG3ITC8AGjA2jWYMG/juUg+7AidrBY9/STdJqBe80ERvihpUWh2TbhqSyXP8oB+4B+owrjqIcdtyWis1+eMhmKVlKbRctE9Ik/W7B8+b0JGfGzwmznQyeGgKSpcybvZil7idToLWD2s2hfavkxo+W6m5DE4wayKufh3+OubbL2aMHXYRRzKx0c8FU+7+aSdgCrA4a8CCion5J7ajwi38sWO+pe+dDKCXRrqfGx3n3J8adBfveVPanVALnXpkZ7yhResgdFwPswtigNhtdhP1agqz1gOdEGQenTW/yqsqFQQthZ3iwUc4K6a4Gsu03WXUkiTDnB2aTgaimhf3LhaIMIHDDRGXUWRzfi6J7Xa6ZC+r1l8A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jM1Ku0WJWUBr8V9uXeo/yxnvHfxES6GxYkjWmKfh1ewBjcYDgNDb1O4dFshEE9LgYixbnxOUOM50JM/p0oqfQ7DJl3QPHih5M9ifmKAW1lD8QRlt41GkdJJ1b+3GXPSMpHktKvdsD0Nps46b0tcEnTo1nmdjE90sAz4I+ZqxAN5UzS4pcSoHrvImhpWKxQAKt6ig+DwL3muAcB4rb99I+VWWSi+Cj9pTruD6xp7AMgPZicptX9lIBjJ9D2/KLmVMoPgZIwqXtKyxNSVaaZEBqBpBdKu5N7xbxEyPsxvTOEpILXDzMeb11/+8n+V7nz00MecmRyCKpKy2bW8wzHEAOyK1Q6/KYtHCQb/TD20Mkc43T/cqe0OOEAQtdnOejr36V0h2G2S+7ee37qZXob4H/2F4axcAkxjoO2oD6npDmUg+6JQlcolb9g4jKzGaWHrQEFY17p9xCfJk7f5VacCrgdBr4DdzrX4dWOErOzNj9JItfZQ1X6vIDy14cxiY91aPFSpUxXC0h4BUnc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b1a091d-c425-49b4-5f04-08dc69ff1a11 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:35.7910 (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: j1hMouABDxHf4K+Y7+1y0JUsLd3pAF2EeYXtYVDTAF4Cw7ujbSQkC//G53Ef+qgIvNrsTJBHRR1QYZeg3kp0Ww== 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 spamscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 adultscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2405010118 X-Proofpoint-ORIG-GUID: dhLuSE1Dlh3TDfBtTNQitsB5rBrhX4mu X-Proofpoint-GUID: dhLuSE1Dlh3TDfBtTNQitsB5rBrhX4mu X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org The request for GCC to accept that the C99 flexible array member can be in a union or alone in a structure has been made a long time ago around 2012 for supporting several practical cases including glibc. A GCC PR has been opened for such request at that time: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53548 However, this PR was closed as WONTFIX around 2015 due to the following reason: "there is an existing extension that makes the requested functionality possible" i.e GCC fully supported that the zero-length array can be in a union or alone in a structure for a long time. (though I didn't see any official documentation on such extension) It's reasonable to close PR53548 at that time since zero-length array extension can be used for such purpose. However, since GCC13, in order to improve the C/C++ security, we introduced -fstrict-flex-arrays=n to gradually eliminate the "fake flexible array" usages from C/C++ source code. As a result, zero-length arrays eventually will be replaced by C99 flexiable array member completely. Therefore, GCC needs to explicitly allow such extensions directly for C99 flexible arrays, since flexable array member in unions or alone in structs are common code patterns in active use by the Linux kernel (and other projects). For example, these do not error by default with GCC: union one { int a; int b[0]; }; union two { int a; struct { struct { } __empty; int b[]; }; }; But these do: union three { int a; int b[]; }; struct four { int b[]; } Clang has supported such extensions since March, 2024 https://github.com/llvm/llvm-project/pull/84428 GCC should also support such extensions. This will allow for a seamless transition for code bases away from zero-length arrays without losing existing code patterns. gcc/ChangeLog: * doc/extend.texi: Add documentation for Flexible Array Members in Unions and Flexible Array Members alone in Structures. --- gcc/doc/extend.texi | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 7b54a241a7bf..94a77d7ef39c 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -42,6 +42,8 @@ extensions, accepted by GCC in C90 mode and in C++. * Named Address Spaces::Named address spaces. * Zero Length:: Zero-length arrays. * Empty Structures:: Structures with no members. +* Flexible Array Members in Unions:: Unions with Flexible Array Members. +* Flexible Array Members alone in Structures:: Structures with only Flexible Array Members. * Variable Length:: Arrays whose length is computed at run time. * Variadic Macros:: Macros with a variable number of arguments. * Escaped Newlines:: Slightly looser rules for escaped newlines. @@ -1873,6 +1875,38 @@ The structure has size zero. In C++, empty structures are part of the language. G++ treats empty structures as if they had a single member of type @code{char}. +@node Flexible Array Members in Unions +@section Unions with Flexible Array Members +@cindex unions with flexible array members +@cindex unions with FAMs + +GCC permits a C99 flexible array member (FAM) to be in a union: + +@smallexample +union with_fam @{ + int a; + int b[]; +@}; +@end smallexample + +If every member of a union is a flexible array member, the size of +such a union is zero. + +@node Flexible Array Members alone in Structures +@section Structures with only Flexible Array Members +@cindex structures with only flexible array members +@cindex structures with only FAMs + +GCC permits a C99 flexible array member (FAM) to be alone in a structure: + +@smallexample +struct only_fam @{ + int b[]; +@}; +@end smallexample + +The size of such a structure is zero. + @node Variable Length @section Arrays of Variable Length @cindex variable-length arrays From patchwork Wed May 1 16:52:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 1930301 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=F8ewRtme; 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=NJ/94YCp; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VV36K0gp0z1ydT for ; Thu, 2 May 2024 02:53:13 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4994C3849AC4 for ; Wed, 1 May 2024 16:53:11 +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 BCD8F384AB48 for ; Wed, 1 May 2024 16:52:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BCD8F384AB48 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 BCD8F384AB48 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=1714582368; cv=pass; b=OWCFEzj1eDesKYppnRuWocrHlHMzmTeoVNiMkT6z8R9H3cpkuwplWysY9X9mc9PWxku9HvW2osLxPyVun4oD9m94xD3Qaj58AdSfSXwDVytoIckx5hxF46twdGYJqzMSg2KZRVF2Z0t+fhhP0AGDSYQ1O1MT7CWoMUkMLEWSs4w= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714582368; c=relaxed/simple; bh=DqxCyKccp0YyLzT3sv3UM0AomxH0pQktKP7vzQtsyq8=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=w3D30bql8W8PZB/HB1i4d2JhWcu/15Ci0Fs9r6X0wYs2sZHcXnaI7KI6TkdXBe7WyGTyYjmAg7gzVUz/zKxx9Jcvq6Ejpo47Sts56mrsxj019y1bhHtjbi3GdRyaFqA+NBjLqkRfy3nWme4jOhmHR+FlxOlmLSzFkGhXCfEoQfA= 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 441ARmYW022667; Wed, 1 May 2024 16:52:45 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=qKNVvJv4rLUXxsQu6apiHKSSIRAlkAYXF2/bd2nxOXY=; b=F8ewRtmekHALVpzyC3c6mWq6PRN+E5jy1llYQJfHoeO5Fk57rJr8p0jB5E2e+AgZEvt5 MTZxIrGjtWIUio8KnoLYgReil14ECKnQFP8A1fdcVl+7I/wvBzJzoIZPP//70LvEO/JN udm5OIYsoOvCuMZr4KPcCnKx8nlQqv/pKqhJbE+AXu+TTb6tNVa9oUdIE3Z1kdi1fRwL hJwe9ryBo0akcaS2Z1jmmL4xeV9diSz5+uVJJN3+tXwWkNi5VmHsOn9kQwLZTdRkAJbz U59KTl+aQi5N00JY0KYtLjxSOEUIT9Ic5hj8jAC5+8nA3o//cggtzyG5bF74mbp3sHx0 lg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrryv7kdd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 May 2024 16:52:44 +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 441FsbPO011415; Wed, 1 May 2024 16:52:43 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 3xrqt9h9pe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 May 2024 16:52:43 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tu5m76se/hdUAkeLdNfRwfn6Kf2mdI0BJ9ay8a3QJujURQKLwsK06iI6VSQMlzwHayxf40YkshIWqgnvUL1fmshlvo2iTJKkm3vF7od2d+1655PYz8qAtAGGbUv5YJVlC4Oi7gyLXKYLUvBm+PpkOMyqWPkpKLZjMeY4as2o2ITKJ+CmXUGYCNrhMuL3NecCUkIahp2pIztSj99yFA0I16wzmsZtrasgWAKqFF0/Pkzgs+X1/fqVHJOLHUZpVV/71XFi8dwB7vD1VKAdzEVCxlXMFX30F1SyUd+TevWvRUw5a1XzWd/rjsFPkZCBy/a+5Z3qEutwlj+SCfbzGY+jRg== 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=qKNVvJv4rLUXxsQu6apiHKSSIRAlkAYXF2/bd2nxOXY=; b=iaRr5UigGYZu1K2tdRlMHznHUM99/9qBh1tjASIBBdvnnMPGj9SSnfLBtjpXexwR6wG4JNOBz9h4fX+XUNOsuUtA5ITY4A1RtO32bwBlVvarjIRG8EsOqpZU4ut+zSRELvRcfVr66OtXb5qnnWZChfq44l7+glvDEd3qUBsTMA0kXctGCQNwkSyTPRHTqnHt/wzzaVztlooEmqTnRxoAsgW0ML3CTghavfr5F6CfLPdsJm5bk6BDSo+M0Up/w6Lroa9j0I+1V5rmfPNRum8Uaw/vgXGeyPze0yFlQdEbqj6WRwpZizu3tjXWEtddXFiiEnaU97mX1xzzKALBfz/35g== 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=qKNVvJv4rLUXxsQu6apiHKSSIRAlkAYXF2/bd2nxOXY=; b=NJ/94YCpu1NO0QXOKXq4JbWTgRq+o1VKI5ZxkwEhIdZwcO85MjDU1/NVGqC/n/FUP7PB2fhc9gk2du3lPaEn6l6+LYChSFi54KMPiekWu7g8+XiiTimJB2wZD6vrvd1+oa9TfAhrhUn7QlwoV48DQTfNgJW7Q0pNMwnxOqw8Gjo= 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:40 +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:40 +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 2/4] C and C++ FE changes Date: Wed, 1 May 2024 16:52:24 +0000 Message-Id: <20240501165226.2924144-3-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: LO2P265CA0216.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::36) 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: 5301cc40-1fc9-4bf3-328a-08dc69ff1cd5 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: 7+FX+pKHsQSoMCjDUsqG+8SGyfuhmxrnuc7Yx2PYfIDdMLJPT3SCHBmDSX5CbCReNR4BRLiiZ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ayy8gjVHOSvllEXH/QnbojP1YRMoJhRnqncyUK8aNj6jMgx3nP8RHazex3kdEykVhpr8KuIusxrtQEYHcFlctsH3g1aqVk= 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: gmFGmTUSygGMhoCAFV5rEwvGxxqERVM8go44nvo09V6wzEUBwJH48chTv0DSzJ0CMJFzEGtpjSIf9Xamuh+2xehKVLW/QJ8PVhoELgO6WucJ3H7fhfksG02cNBq6C66REuIs2e0cPQ4Fv7QWhwwoNma2w5z4bsOjMoAqezubQV3KcfeQtzvL2QksZpzNy5ZOmUNjXKrNQmG5EKJJ7dtHmGI0BwAg/a47F2NrsndNSNdFSbFiY/QbGQrYDjkjItyZwiGpXXv+NkMv7lV23ffHvz1TIBNBM5G7Odey78XOUTCDOkm6x/0sRbYZndAFvLNg8sOlE7YjrchLen2dFSK5vRvzfOEDbMppKSVxcVLiXzXfagsHIRo782+Fk62gX7lKAA2/b6r7B/m6cFOPow9XAyuDlyvJRmzttvz4XNu6sHy71YH0i+ve08c9rUCIgpVRW2zuKxaKGX7RBPhrnEB2RGC0yPIkQbyJSaDivINuGMEGiIBQspYeXvpUlUQluW11rlIL+AGXuQTXmxJhnKzBtMg9GUX5dlwjnBgZYFb2uUIKSIIMyYhrpxHHWN2R+k9tVo0YpMawTrYwc062FK2/07Kv4k2In0J4+Q0jxiZ6p31jG3U2tqkWdniy/oepEt27QRP6iLkozpD2DKkxCKR2MK9FHWGbW4MlRvYqp9sa6YhGszjZSShBNpPteD+/mhiuc+EA9VgjyNjQ7JFVceXgrbJ24l0aUMvPRrD5ahyT8MKJM7iyvwzVUL2TWyrwuEWY6WLibSv/ZuTV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Hi3CtUblfIwK/TS/KnoYKEFxl+ES8asjhALsYiHcyPquy+NOgj42fASNZi0WxpRSlZaD1ZqJUV+wR8iTOyUBQpQFjdG0B2j68kU5sYvRpiV5prvTRtWSk5YdPaqgRZkJ/TDzdR0L8wXaxII6MGHq78ayohK/xtc0hoAWgSz0LrO8fpgFCzobjNX1Gbyp8MpmLZVlCtxc5eA+1qkW3REN7ZYLKeJkCdvCAQU1bbcwiNI8YkqeROVHNtbghU/FjE/f+jlUDy2b9K6Dp3XADJOC0qYl2Q7gUhg7HfgxOX8FuJVDr1vwFSZk8WOA0FYTJELiu8UoyvMwec8mfLF7RxzfZ7njqfnqh+T0QYrYhsHnfntX2vhd0ohMC0miV++ePI39Xzeni3sajOO87xSKbXrd+TUxwIfTh1F+ZnyOVb5595HUxmRZ8o= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5301cc40-1fc9-4bf3-328a-08dc69ff1cd5 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:40.3627 (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: sk/nBoKBkG3OPKXRR5oVYmUHiW3kKjUSwCRdgb/S7VrqkmaKKxgEvHsTUpvOFWgnzkKJk9GSI10BwpNYjajW1w== 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: d1tFzV_JvScMa-IPrEbvBs8k5_rrDVfm X-Proofpoint-ORIG-GUID: d1tFzV_JvScMa-IPrEbvBs8k5_rrDVfm 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 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 Wed May 1 16:52:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 1930303 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=cJdAbpwn; 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=F7fJ1MXL; 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 4VV3795Nffz1ydT for ; Thu, 2 May 2024 02:53:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0981F385840D for ; Wed, 1 May 2024 16:53:56 +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 D9E9B384AB70 for ; Wed, 1 May 2024 16:52:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D9E9B384AB70 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 D9E9B384AB70 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=1714582372; cv=pass; b=MxmacSXLYKkQjdtCuUKj+7Hhm3Y+gzVNcK+26xWzS+noIe6d6gV9GqU8cKOWTFqVbMyax40R6kebC+N8qOYHdbj0fCzU+NbjoWZt0YHfk8F32xPG7Nx8BvYZ3iKQhwhVE1S9YBIBR40vPlWEMzEp7le6/LUC449I3NW/K5LqMv8= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1714582372; c=relaxed/simple; bh=3n0wAyTGloE80TgxiCRQuCUuS6BtO+OZ24FVOGjSbDU=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=syglX6/as3U6NNEhbyIbU3SsMNtG9PeevdzT7pAljotyP4H0jiFpW0XoMLsWHm6xlLpam0dLsK2j2fPjzmRibyZbKqNDT+HdqG45QEHMFoDz1UIGyEZvqNITrkc3AluMDdkcxCQaxtJv5TaYPITz2uHaykrJYH6D5cuZMDjUQfQ= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 441AS0WI001725; Wed, 1 May 2024 16:52:47 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=cJdAbpwnVh5D6E/zwwO8+rB66IcIDjcp8pEL+4qfHw+hy2jQc5b560KmY9xtkKstlMih 6cQybPF0Z9THb4MHtoTAcOTajx+l7yn5jX4Gx5nIV2tS3LcAg88rCcJ5PUiSRrrsLXUo fZUjJK0kAqKa3PNpQraE7BAUViy7VodvyhqoixtPJSVbeqcXh3v+cOMujJiLXhNJCnuf L+kCF7AjpyQScUK+Sv3hSlWOz04U6188Y/ly4Uy9m5RTWja7aNMijA5PFBLeAOCVctP3 j1hw3iUQ+i/WNUa/zKN+03alW1i1R+7UiDN1/yPNrO38dy696vV0OBUSclZ+Fvb3RfUG gg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrr9cqptn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 May 2024 16:52:47 +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 441Fle4j011336; Wed, 1 May 2024 16:52:46 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2101.outbound.protection.outlook.com [104.47.55.101]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt9h9qr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 01 May 2024 16:52:46 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B2EIDWR0YScvHb2/dqtH43ewW8FbX8yHswo/P6/Ra4YACFmSGaA/ql4yIW1QU1QQUiY/PmHVdJ/X0rKmxM8icLzY2hpM2xmR6HeTNWwX2y1KGiOq5ToLYaAAzvXPn1nEsFqI7P88lwr9JL+KkQu01TWKd8CUey/BfVCzb5UKwVivwgc0yjMORazA3TbvZmo8eMZdDCvdPNubJAPS8HLh4GXmd+V8xzMjhWxEY4mPVmQRDHMzf3N8prRxsg7xcN0CqH051SKCCV/ic5KVoYy7LeCe1/e+6zYwpHmCn6rhNRF/+6/g1sjOweVcY3FR2/zYphU9l6q0q2ozBHlZ1ixRPQ== 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=Pd6XGBr2wSv+k7cywQibTRRHalcHjJ3v606eGpheVyBSJlqelLugQ+iiPIx3GTDOatRcBhSq0LPPw6KbJr6KRxrLa0Ro68Y3SoGs40Eh5V28shwpfmkhJIF1UirXp3t6WHlcONJpS8uGuLSP/zWIpW6akckIT/8itZ0dREZgXoooKPxb9lRBOkoWhmuoMuy79A/Sf3FNr+XjdcOw9W4zgosCRVoMaGIKaWZzvRU2c5Cf1sW6JVmu+eTndR2adsRVDJb1/9UBsCGwWkB7VYH3jtv+ClFnavXjWwJkrFEuC3wp8am78aHHBKx77z6ZGKtCBHXrJgR/qRPO7klW/bfzSA== 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=F7fJ1MXLfLHx6t5yd8lawxFvG+TYHTwf2DJw8nEcUGYGAOKWTpa5V4vUWPPt3ZhpudZKoenIOfZPKVO6I6zIot5mggUoSty0QOPiwYMTuVbY5c40FKLyxyn1x13fgj/cfZ0inkWLmFM62WLJfYatL56AfoOI2b3w/NPeractjkA= 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:44 +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:44 +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 3/4] Add testing cases for flexible array members in unions and alone in structures. Date: Wed, 1 May 2024 16:52:25 +0000 Message-Id: <20240501165226.2924144-4-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: LO4P265CA0222.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:33a::10) 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: 7e9aef75-1715-42e6-c1b3-08dc69ff1f4b 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: A1Rwria48bMrX1aeXXp3OHjkBqwCaSMhtivo7krXGdWjRnAwgm6heVFyfYyEUoVcAlMpfLxOzQHyriE/gq/apVNd3hrwndqeJn2ftmPjLPGwAi+ZHYjpwQIoy95yS2dbXz1yqAU8kPgVNsB/0u0Sw6lkUnQy2p6tdjp8lvhOkllGdbHBeoclXQBsBz9yqyPMp0S4+837jEC2Kiy3jShqQwwTJaEeyXoTY4QiSwBrsj+fi+d45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.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: 4rJON3MHlTjKCXHA4AzgZssPlPx12mYZxliZkEvo+i+QE3wrqsjvxeNS86s+rwhv+TkkjjmgLB8azhh9XXscbOFVbXU4q8931Kf4Xtx++iFPJ03C2J9xNceuz4A1WZjkmSXeh3R1BFDMcrLTdnQMi+DGIJtDYuOEM3M3tTnOra5c0EoL2YTJDO+CroizuI2mf1ylqRzqrsMVUi2fPtSrGtMlN0REuC9bNoCrLXCFETpqq1IksvsEIW8TgeTUkG3biMKPVPxZo6h68WGsh51UsAI5ZE3M0KxDMAsT4HQcRcmDqghUWKhM1DbQM/0sv+qPf8ep4zOqaAhqdKO64OOlTpKVg0eFbTBicNBYuJaovTQr+yyQTl8jKLdi3ayOea17yCsDaSIpcgY7C98KRvVLs+l6NJgRC+G0tp6K3IN6TT++Lu9X22OCooh3WtRkBR+Bny/fkjFYprfQICGxOXWgWYL91BFEvNABc4MAagkuoklxA/fRG1NyZKyiDmba8lm2YKpFIYe44n/GMxDkWHEGvIhcTLz80axlesYm1Io1NGNgOx/LmR17Kfl3VK71h6A5aggSHeXengpS5V2Ujqxf17TMEDztzvRkwQALBgzHD1bNdko+tEwIikVZUSDHNrrs8JFoOlEP817Uq8MhfYc+Nwul2KHFB/132wYEil/rDqle8XwQukrHAFiBq2FVpXl/7E1+CyEcofBLPwMa+/DGP8iZuVkesvrm2Ar27u07ynzJVWbQcnP403Y8ef8a/f+mYhawWh1ssm36rHv5q6f/ADlaQTnQOQSBHyQ2aazo/MAq1E2ioBJQGcMByFenaMHnChyoSWnDaH1R5PVUuz2rOIBzDxeDLUBhstRfE1xFHIvVLZbqy7vDHMLeFyB9zR09wYdxFTIbgb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yjbbdi6f2aHxN//VdRPQetbIPy8SJn1W47F9xjT2OCWNLSVVKU7qApf9p0UcFMuRVCmZKBNgMdKpOwSuleqDBQit9BmuWa6PW0cr9/MZfc27A9Vmm6NgzwkIblcO6W1XhR+wlWJeCicaNHzXcdFRxPh92nnNhsi+6a8vDQ8Qp1o+bAb7SxxUL7zywHjhMXLNkbz/QrD7kyhv6rActE44mW9l7D8myn+x3N84jCyN82GT+eaz9Gs8fYCCwt9/3XTdk1hGmf7LTeU7XL9A+NpdHqND4Fex008iO+oBK/kyNslpjUurLfO2SyvHCXNY0QZ57w= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7e9aef75-1715-42e6-c1b3-08dc69ff1f4b 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:44.4582 (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: zrS3f4IpSbV1JDI9fMPMcKT5cdJWDCA1xPD8KTWubiZ3aWLu+qzJ8evnwh6NPXwgEDK0PbSBwtMPWOxdbubxtA== 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=929 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: Q6oce3PIqsKiTPPj2WSwJf3UHatg8eZe X-Proofpoint-ORIG-GUID: Q6oce3PIqsKiTPPj2WSwJf3UHatg8eZe X-Spam-Status: No, score=-11.3 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+incoming=patchwork.ozlabs.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 } */ +}; 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/8fy7yY9HSPsxBOV427CGwDUH4ptRMGKJHQqOUlrqU2ovMtIIYM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0NwPr6P9hfSINgzAw7of94EZtq0eIOtJ67RcZilQZTqB389Qd8+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/0UXYrOqlER015PVQJCrGGLBOsYF7EwxxpKANi8Dxy1THIOGOoADK4IOJvAakvLqjOSAgaqLJbMwt70AALHoYAAjPCfbZT3v5wTT6r9uuexixhrbEfLRrvQp4xcKzhFVdqZ8wUzY31uK8aWmqZV4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PN35L3sJO/4v62VQwoIGqjdY8f59cioZ4OJm4cICGZl/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; +}