From patchwork Mon Aug 5 20:17:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 1969169 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=a0RBA3ZK; 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=g25I6h8H; 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 4Wd7664xQKz1yZb for ; Tue, 6 Aug 2024 06:17:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5ED8C385700F for ; Mon, 5 Aug 2024 20:17:48 +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 34BB6385840F for ; Mon, 5 Aug 2024 20:17:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 34BB6385840F Authentication-Results: sourceware.org; dmarc=pass (p=reject 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 34BB6385840F 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=1722889048; cv=pass; b=AdqphhdKA6gaewUoQoFIegEXaX74hLLggFUQdQdYW/zEDTI6l8GK7F/ei8CDsRjXyJiWEEiTLg6iaYInhiQ7/Jy/pIZOXdLnYI8pr8i6XKDq9U7fqmaKb6obIPgyuvY1ElRbWr5ZAcC4AbbeCwtHJ5hO3A6sZoaCpTCtEYpzG10= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1722889048; c=relaxed/simple; bh=3xp+qef5J4icv0f/8StVnsus/KrH5d6YlRSqEauHuTA=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=q1i42CROIWbqEWHNUV4i/Fpw1s4CQKmOWtRXXAwd9B0ihsDFG4Sut9XHfLAceWyUK55Y75VXcD+bxcplCkjPMo9gDDOytzKHtuCieUGUuTJTLxv+kxjQaz4HD2LBDhhYRzURN24DYhiN2UVaK9UQqLa+M+wTVENtfAWqvZT8uqs= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 475GtXo4003502; Mon, 5 Aug 2024 20:17:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:content-transfer-encoding :content-type:mime-version; s=corp-2023-11-20; bh=8nyzgRQWoMKIm6 30Efydm96o8H6cLxRsyXSt8NYVT4M=; b=a0RBA3ZK4noSdP+ZsEwNjxVFUqqwdp jtAF1v7HYVchfWj0StHg5x9HTTLyPK7rGq5XNrXx+yecV+gpwDXBlocBwJXKUJp3 DASJbrJglgyeMy6+fEvWwkwkj+8lXDw1EnNBKQ7S0LJ0GVAx6/7ZsQnhGWZu3A8l fQJ0+HA9QF05EqFZF7fKh4a67432/CDQK40IZSN6z/Atmhi5+tszsifoArhWiU5o Sm4z+xI/yJUHC+j5d6CEvo4qEKXuSyL62ZlnFpZbs0AH2Wb8BtEM6cHtNffWflMS NJmyWLKo0VId6rYpjKGjwZxb3BbRVjuOp6/b4tRFJN/k7Ee7gXl0Jpkg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40sce93h93-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 20:17:25 +0000 (GMT) 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 475Jv1aW035080; Mon, 5 Aug 2024 20:17:25 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2168.outbound.protection.outlook.com [104.47.56.168]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 40sb07wgum-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 20:17:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eCVM47FnIs307uuvLjOCyY26RFfYJKj9r+A0BPBdAqlN0cYaZeFJO7AhkbuNo/bNvDokkKKCadE0yhv2XvrkAePPpgbBvQ1JS0vMIrhhEkfKDRI3ai9bpmYNpudEvNegyuyJefCDQ+UAWUfqep20L/a48zKf/u/VaGvNR3sxHAGR5HMmjjlmUx4oZZIMWEMsHTRiecMEpiKYOExHFlXSA9kgO8FbUgSPRu9MEL7jsPFoiX88VCoeQdEWUS3ZW7QRbzYNsTH840UlV5KpGD9XHYxKLNPo4FZaS7jvzZhWj1MUfXMAj98P+EaUChAklevhTP9nGenmEyr7PHBH4xE9GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=8nyzgRQWoMKIm630Efydm96o8H6cLxRsyXSt8NYVT4M=; b=yCorksOkm+pr+T9G8xWpT2tySC19cjrr+MeqqdEo2MMYjMMsZsUZMhZI5QI9RhvctcyjCXxnyf/ra4ZcenXsTNNBhxb4KtxSpiFtNbP7i0m99scc1FuDEJIDEJZYtlLtWEjPw2l9b1anmBmnEk44GNhtno66+z9ft1CyMa8XwO/d3MHQhIjeAb32cqEHPi22fILnMwCA6s7FaXZr9bH9e9e/CnVAyG6VNFc7pzRT3+MgwpU2JcdRhwMPCc2BGuMjmm8gmcaN0cLnWzuGlFYWa33tTPebp+fbL+q8Osi1fRqBNPWLsEOO0Fa/EBF57D7zO1Y8zhhPtifVbfh4hCJC6Q== 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=8nyzgRQWoMKIm630Efydm96o8H6cLxRsyXSt8NYVT4M=; b=g25I6h8HkEigr7gpa1RvIfS+FsooeExeTS77WAgXPyZYd1clyISKjROIp5GJfyEhiK7vIQA8R/cexXZKnwUhBV31K4bxoGEi/3UMRGyikrMfKAew+uBDDFM7OS4zm133OLw8VIzDL14CBETeQhuq3W0wOqMZFHG21uENHcnuOJM= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by SJ0PR10MB5566.namprd10.prod.outlook.com (2603:10b6:a03:3d0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.25; Mon, 5 Aug 2024 20:17:22 +0000 Received: from CY8PR10MB6538.namprd10.prod.outlook.com ([fe80::8a:61cd:764a:e47]) by CY8PR10MB6538.namprd10.prod.outlook.com ([fe80::8a:61cd:764a:e47%7]) with mapi id 15.20.7828.016; Mon, 5 Aug 2024 20:17:22 +0000 From: Qing Zhao To: jakub@redhat.com, jason@redhat.com, gcc-patches@gcc.gnu.org Cc: Qing Zhao Subject: [PATCH v2] Explicitly document that the "counted_by" attribute is only supported in C. Date: Mon, 5 Aug 2024 20:17:19 +0000 Message-Id: <20240805201719.1790276-1-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 X-ClientProxiedBy: SJ0PR13CA0002.namprd13.prod.outlook.com (2603:10b6:a03:2c0::7) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|SJ0PR10MB5566:EE_ X-MS-Office365-Filtering-Correlation-Id: 7853d891-8e36-4fcb-4c5d-08dcb58b9d58 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: 1LNDIedDqQJk0n+qt2FdA6O6NIiWm6d1p7cJQ610xUMwOvKe8YhZK2vudIA06iW6b4DzfbRAP0ln+xok0WkkmjWq8B9eJCFb/VccfKhhDV9hC6+cxqTDkDwmlGBV9+vKYJcGs1jyJI1NjwEt1MmIPN3sMzqBbCu3ECMKe8bwr69n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CuO8MXPc4T3nG1lUeV1GYRSrBKAWsCZMHAq+0juIAnOQd8lEu7RqW535PexWe88g6he1CiG0hbDaTM8LApphURE8b929fIJ0Cofe7jq5EK5vxMsd+ibC5TA== 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:(13230040)(366016)(376014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6ku163QDapEYh2M447FPLNleHBIJcx5waJ2+9IhjMyjqhPjXqd/2OMTYEhg+COcvGV/fnXix0C0RIMYyr2UA9b1gJyP4E0BHE5Dgw4NXlSRIKL2CyIkqGd6FwbrBewxdZz4jYTNGLJ2qNBewYChTeYghKelstwyVf8MOg/h/2IWAK+/nFymggpErLUqU5eAb1EfjyTus7HVW3cKzSEWP+kdB7nJAY7uCY+sag02RV+qJT+EzJRA+HASyeABO17d9x4ilaZV8VNU1rH0OyB5FCIGY+ETeOEpqF/Zfw6ppu2goGfA0gUmnNaiVp3AP4t90vJkhvh3ov70D98D/z8cAie2g85qwd3FNKKTFWvEAixO942WbeydJDLUALuK9cCaBTeWgHkvF/vDebWz926vQQFA0JGtshLL8XG7aUNEMNepvCtBTInRUB/HhSplg/wt3xO7MvH/sCkuvIF+1+SJQ7XVhgVetoJXBddsyzEIRUA2+tSNizwQxZ7B4cE4I+Asj+TuGGbf4bkZeD5nlE0H6RlWDS8krDbZzxpqsnNlAbBC2iRN+jX8oa0vGiEPqrxxyqIv5+j8Q9pEjnguBZr35KpA5zSRkWmeB9x8ww/K5IOXtVnKnj1/I+0W9CgFn5SN7iBV5Ke++ae7hT319lu5a4ntH2011qzYRPyJkdOeR2ezxCdrOVkjQX05KtxWQWpPfj+C8HWKqXpkpdpILM4QDnkhrO7jz/5H8FbHzEImXe92K5HmCqEgn+7KC9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qlOVz4whWLdGk6Cp7Y8WaSFIPrj+hXkjJ5zRejfJv+Zmz97U+2nAl0h36Oj5CFVEbsPuBwPQVy2YjhYUyThX6oQAqugmipnsSR60n+FnpumQtwov6cbriK5wz0e+VAzMH8LESPDQeM09mRS2+TxbQuUFZFGn1o47yA0mIDt/bbYeAE7OEBBjRsv/fVoYyl+2OyEIwug7dUrMCVsRUc4doZdm0f/BbF2VAZpej1hkJRWkNCwV7JlcfuL5V6bSS2iUaOk6vc4Z6hsCEEy/+kCrq4R2UUmDByaad7z563bHMDYgtShMrysEevr+pGYbVLzeq1itmSvXO07S5P+H0svRV+fWXV4sHMyvwtxxvIY7wVQVxp9r02hcn3PUljDu6s04capnVD9fjoHaw1FAcct66fUoDdIF7RC/at4nyiBhHPIwt0cdK02s1GE8sipRiM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7853d891-8e36-4fcb-4c5d-08dcb58b9d58 X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 20:17:22.6028 (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: U1W5tsi8h3B6K1dE5wsRXoNED1KHFn1MiRMWwaadAnpnp+u/jCviRRBX2KQuWLg0Oy+0JRgTfUZqLIH+yEJ1RA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5566 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-05_08,2024-08-02_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408050143 X-Proofpoint-GUID: dUL5pr917A3V6f_SM7BMyZg2wDrQIYVq X-Proofpoint-ORIG-GUID: dUL5pr917A3V6f_SM7BMyZg2wDrQIYVq 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_H3, 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 Compared to the first version, the major changes are: 1. Changed the error as a warning with -Wattributes per Jakub and Jason's comments. 2. Update documentation accordingly. 3. Move the testing case to g++.dg/ext Add one more new testing case for C++11 Adjust the testing case according to the new warning. Bootstrapped and regression tested on both aarch64 and x86. Okay for committing? thanks. Qing. ================= The "counted_by" attribute currently is only supported in C, mention this explicitly in documentation and also issue warnings when see "counted_by" attribute in C++ with -Wattributes. gcc/c-family/ChangeLog: * c-attribs.cc (handle_counted_by_attribute): Is ignored and issues warning with -Wattributes in C++ for now. gcc/ChangeLog: * doc/extend.texi: Explicitly mentions counted_by is available only in C for now. gcc/testsuite/ChangeLog: * g++.dg/ext/flex-array-counted-by.C: New test. * g++.dg/ext/flex-array-counted-by-2.C: New test. --- gcc/c-family/c-attribs.cc | 10 +++++++++- gcc/doc/extend.texi | 3 +++ gcc/testsuite/g++.dg/ext/flex-array-counted-by-2.C | 13 +++++++++++++ gcc/testsuite/g++.dg/ext/flex-array-counted-by.C | 11 +++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/ext/flex-array-counted-by-2.C create mode 100644 gcc/testsuite/g++.dg/ext/flex-array-counted-by.C diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 685f212683f..4f064457dc4 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -2859,8 +2859,16 @@ handle_counted_by_attribute (tree *node, tree name, tree argval = TREE_VALUE (args); tree old_counted_by = lookup_attribute ("counted_by", DECL_ATTRIBUTES (decl)); + /* This attribute is not supported in C++. */ + if (c_dialect_cxx ()) + { + warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes, + "%qE attribute is not supported for C++ for now, ignored", + name); + *no_add_attrs = true; + } /* This attribute only applies to field decls of a structure. */ - if (TREE_CODE (decl) != FIELD_DECL) + else if (TREE_CODE (decl) != FIELD_DECL) { error_at (DECL_SOURCE_LOCATION (decl), "%qE attribute is not allowed for a non-field" diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 48b27ff9f39..827044670e8 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -7848,6 +7848,9 @@ The @code{counted_by} attribute may be attached to the C99 flexible array member of a structure. It indicates that the number of the elements of the array is given by the field "@var{count}" in the same structure as the flexible array member. +This attribute is available only in C for now. +In C++, this attribute is ignored by default, and the compiler issues a +warning with @option{-Wattributes}. GCC may use this information to improve detection of object size information for such structures and provide better results in compile-time diagnostics and runtime features like the array bound sanitizer and diff --git a/gcc/testsuite/g++.dg/ext/flex-array-counted-by-2.C b/gcc/testsuite/g++.dg/ext/flex-array-counted-by-2.C new file mode 100644 index 00000000000..6ac2b509b68 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/flex-array-counted-by-2.C @@ -0,0 +1,13 @@ +/* Testing the fact that the attribute counted_by is not supported in C++. */ +/* { dg-do compile { target c++11 } } */ +/* { dg-options "-Wattributes" } */ + +struct trailing { + int count; + int field [[gnu::counted_by (count)]] []; /* { dg-warning "attribute is not supported for C\\+\\+ for now, ignored" } */ +}; + +struct trailing1 { + int count1; + [[gnu::counted_by (count)]] int field []; /* { dg-warning "attribute is not supported for C\\+\\+ for now, ignored" } */ +}; diff --git a/gcc/testsuite/g++.dg/ext/flex-array-counted-by.C b/gcc/testsuite/g++.dg/ext/flex-array-counted-by.C new file mode 100644 index 00000000000..8bc79d459df --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/flex-array-counted-by.C @@ -0,0 +1,11 @@ +/* Testing the fact that the attribute counted_by is not supported in C++. */ +/* { dg-do compile } */ +/* { dg-options "-Wattributes" } */ + +int size; +int x __attribute ((counted_by (size))); /* { dg-warning "attribute is not supported for C\\+\\+ for now, ignored" } */ + +struct trailing { + int count; + int field[] __attribute ((counted_by (count))); /* { dg-warning "attribute is not supported for C\\+\\+ for now, ignored" } */ +};