From patchwork Mon Aug 5 13:33:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qing Zhao X-Patchwork-Id: 1969051 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=GrnjM18u; 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=zaJYcurU; 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 4Wcy7j3P5rz1yZb for ; Mon, 5 Aug 2024 23:33:35 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B671C3858431 for ; Mon, 5 Aug 2024 13:33:33 +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 2B890385841C for ; Mon, 5 Aug 2024 13:33:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2B890385841C 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 2B890385841C 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=1722864792; cv=pass; b=pqXBcVTeDSUwjiIasVPFvGuuovUAX/Jp3oJvKgqHZgnArIsFa6FNf0+wiQQUaJlRFeUh5ymY/ozZK0GtRz0uJg1R12+t4BSx5MO9nvtDejOForrVMLEfmof4OaxfswzY9q51KLhPFava2BwumpLER+b2BWTSGvlXX8khrRflClA= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1722864792; c=relaxed/simple; bh=k96e+KJknT3RFzfSUzL8YAsxlEk9pVebpBSwF46RzaI=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=Bh4sTDWTMtVFwLVyrMvsBjd2AW0+s5OWUDoAAfQ50HsRS0oaslADuz/ExanVRxWwuTD5elTJueHALFcdpEaii4YQYaloRZxYmgaDBs0nyAVGJ389zuY8RHqAFhgAfq4snf7sZMb2bt57K+bp+75WETpbNeSKbP4kJrzDxZ7+4LI= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4758fZuO017627; Mon, 5 Aug 2024 13:33:09 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=djWx+TaVu8tFoN OGSyvj/ebSrUXA51xEuax8aoQBj3A=; b=GrnjM18uLKZiQMVDzaX+v5JY7bLagT e2DMMGjxUz/s9qIX1u4JSjgmm0HsvPbYtf5Ny1ac6HnNFHeWjpuy/ztdF++JImKp qiyw29zWNI9pBgrWnPFaP42PfKECjfeqlo8c0Ofx9QwBvCleJLedInshM940Rory hb6ISpeWNH8N5/44/c838dCSojl5JFUhz1lTxPL29HrTDnIcg+5mbHXkjsetIeTK Kv0gaJ8dmlv425dko4J3E+XBMCqHPh7FaEQbktaYHHQWK5MpmWKijEmmVlSckkmD TfQJpHPdqUgvZeXcnM1mCql8KVWd2QOQbLQG/kxMwvstbhVz5vAKztOg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40saye2p4p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 13:33:09 +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 475C42WX034972; Mon, 5 Aug 2024 13:33:08 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2173.outbound.protection.outlook.com [104.47.58.173]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 40sb07cq8s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 13:33:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DQOY8EjFuwbTT4ULK5fqkXe6vueYeWsMhYPgGNZs7KqcVnpDtp55eTpAMQKvfYO0dYuArIVtFqAK8r+i/iP6pPuWbllWUb63XAwCaz41w6gZaYgLNDHZAK15NI/TyT7bpKaM8ulHDQtfcwbDHgiirUp3t12zGe0T77Nj76lB7+Gq07ML5g/V3lKHhkbYq2HiYtBiAWf5mar358miJKp82xQQXaiFYEI3rvyjFSDXPSCyybzM69kR7ThxTZYEnnfdO0GF4xZ4NnUtI2ufIvrDiRAEvUZ7VpZxp1+KFRrj3yKCf21gyrcRih/EfiXSj4ssouOZPmAv9fwUhh51xaWIBg== 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=djWx+TaVu8tFoNOGSyvj/ebSrUXA51xEuax8aoQBj3A=; b=xue8QqH/Mamly2mJ1OunIK5x6dMsZzex2Vs5kPsnB5yBuU/joEeaV5yCAVhHsvl6JQjRfbmFg14H3IFsos5PWBkBNEju2ZGw0qxSVTOOW7eNzzPQhGjdSPqAzux5sdruz82K9A18+0TLxopnRcl9WgsrKIWtW9PSk2ht8iYmbsA1qbQLAVMjYCI1S756Ok0uXQQXtayksJsZdDgb3B0jc2nfP1VsbKf0wcncaHkdJ3rcvjeh7Zc6YKDNUh7JrBu5SzOSEi8kACFyEdHDXvL5cVIPDUHtXRkmPGuJko4y48x7Wd+4YFcM9v6lCS8IguuJg8JtfyVxO8kAo7jrUB+3wQ== 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=djWx+TaVu8tFoNOGSyvj/ebSrUXA51xEuax8aoQBj3A=; b=zaJYcurUT3vmzDYXAqCvqfunxbau35U0Mo4d8lA4lniDoRnoKVoili0s9oDn16GPREikNilimzeshyqUB6YKqbMwpFrHSSdB0YDkC7fypC5OLvQiWv8XXNxB3G5DYrBORhAFo46HBMEAT/GQtvXYwND/k9AoaeTI4ufuXpfnAKU= Received: from CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) by CY8PR10MB7196.namprd10.prod.outlook.com (2603:10b6:930:72::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 13:33:05 +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 13:33:05 +0000 From: Qing Zhao To: jakub@redhat.com Cc: gcc-patches@gcc.gnu.org, Qing Zhao Subject: [PATCH] Explicitly document that the "counted_by" attribute is only supported in C Date: Mon, 5 Aug 2024 13:33:01 +0000 Message-Id: <20240805133301.1649647-1-qing.zhao@oracle.com> X-Mailer: git-send-email 2.31.1 X-ClientProxiedBy: BYAPR05CA0046.namprd05.prod.outlook.com (2603:10b6:a03:74::23) To CY8PR10MB6538.namprd10.prod.outlook.com (2603:10b6:930:5a::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY8PR10MB6538:EE_|CY8PR10MB7196:EE_ X-MS-Office365-Filtering-Correlation-Id: 38514ee1-a5d4-4c02-7492-08dcb553230e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: Vu3hG561FjNsr2mmf0MZg4esLiyzetfzfHYksXTtIwNgLWTPCB/7EEEkX1t6MmLDwKeoryNo00iplRX5Xh5SXtgHDfdEzRXgdWau55hDoMARceCHoRsYbSSrcxSrZ6lNj/iSyaWibu0e0UPgoDkqem3mCkq8UQrEW9y7wR+ii8SEPmlqoWLvWdijR0vP1RAKtQNXO9lHGHNHg3u7zf0DTreB25VW3DSlSKLE4IryAllV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undaIMCdsMRFI7Q= 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)(376014)(366016)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VL8/E6MNxjJtlaA5vycRGZVbnLs5RjO7qT/JruSHd4WeRjAnTJT6Xxxt/baqPHLnEEoz/X1I5qkBPxYCLQKrtjzL4pNEf6uxU4RWLvT49gIcXqHZPVhLwXvadPOSaUjd3mVOaAJAFFrJm6gplMuuHm5wzD3RgyVJc6ixlu07r8BIca6p1YmJ37k3FoirqX2+BFezXWUYC3FHn1AfmCWlEgu6sifx+TLHJKulU/5m1b4Wx9DriJX6zAl/hRiKMUTSJVeerh7O+c0Ef0X1ke3pR6UZvFv6LnL37nQCW1q7zQY8DkRZ6/FiOlnLweMKhvhJWCUdFwW5MEEaCIcmDVdw6kyQpPEq8P53xk+r6A6xeiMMU22QMpW4xacmEPO1z7CUhi2bsBL024Zqgsufm0DLuhDaAACTARqoudfVpOUGU3vQhcRhOzl7TKzQQLEwxB+hyDRvpuCEcGq2w4VNN9C4YpWxxoaV+88m4uAWhPTS8Fy8FWbd09rrv5oV5q0jSlZohqsbZgxyw0xs5n3g6CUbraLIJiX97wh9gvqjIqYY1XHt/TxhbfMbyvtsdoStlBGidU1FyC0iCHiJWGTidmElMg5z6jnVFmy1vhmZFZtKCnOYo6bizROyHOtXrBzT1qIrP/oyqYv4ZpKFaAmEth+L+2BzWWeEaTwEOE51fGXv67tWnPxDRMWry/B6IvJwBz1k8mOn0zQkaTSTIl7xc76kHKkD1XURkGtAZpcAgFRlPy2XRJ12RaY1oCdVo/B8+0HZHd5I7DcfotdqEdzv12fToLUtsCKGlbLkigL4p2R0QRGCcVU1PzQfZUWSDILmfgpLDehknMPnCm/7AtsJMD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Nt9/azXtI61aCeVnI/DwbYrbr4BCVzoHvtP66jvtNkApQQESX+Cl9UDo3TcyLcFHWVGZB8kWX8XgFc2BHqERCLyrkUnH5NRCcYchUHYeqg4uGGtos2YDlCmrI29eLHN5kjbnk0VDUGrDdGgjuV0q/IEkymsMD5T7iwzanTAABnD2ScNBpB2Yco9AB3335gSDzd7NE4i5ui6hssFUcXqZSs/FtaGghpDpfCfM6G0daYT78bx+ASHEMe0ZQhLTVaEBryILVpD94/Wruntec4rcFs+nDUFByuBgWjv5SOgJIntamKYcnt8Qb5KJq2ehrXCSVeVUFjb7WFvZZhs4mGFL8VQVPBhToZ80hFWgYMbEJGDcW7fU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 38514ee1-a5d4-4c02-7492-08dcb553230e X-MS-Exchange-CrossTenant-AuthSource: CY8PR10MB6538.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 13:33:05.5650 (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: Lj9988LNsfKM19FpMfyp0UZZIL+Ag/DS3UxyOXvxH2Gpj/tVLxcvzsZ1zqkTkMeSA9vqZzqxFxh1rBLKS62qgQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR10MB7196 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_02,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=898 mlxscore=0 adultscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408050096 X-Proofpoint-ORIG-GUID: UGrvSwQD7Ti-nem62dO8Xsg8C_FB9Yv8 X-Proofpoint-GUID: UGrvSwQD7Ti-nem62dO8Xsg8C_FB9Yv8 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 As discussed in PR116016:https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116016#c48 We should explicitly document this limitation and issue error messages for C++. The "counted_by" attribute currently is only supported in C, mention this explicitly in documentation and also issue error when see "counted_by" attribute in C++. The patch has been bootstrappped and regression tested on both aarch64 and X86, no issue. Okay for committing? thanks. Qing gcc/c-family/ChangeLog: * c-attribs.cc (handle_counted_by_attribute): Issue error for C++. gcc/ChangeLog: * doc/extend.texi: Explicitly mentions counted_by is available only for C. gcc/testsuite/ChangeLog: * g++.dg/flex-array-counted-by.C: New test. --- gcc/c-family/c-attribs.cc | 9 ++++++++- gcc/doc/extend.texi | 1 + gcc/testsuite/g++.dg/flex-array-counted-by.C | 11 +++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/flex-array-counted-by.C diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 685f212683f..f936058800b 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -2859,8 +2859,15 @@ 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 ()) + { + error_at (DECL_SOURCE_LOCATION (decl), + "%qE attribute is not supported for C++", 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..f31f3bdb53d 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -7848,6 +7848,7 @@ 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 for C. 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/flex-array-counted-by.C b/gcc/testsuite/g++.dg/flex-array-counted-by.C new file mode 100644 index 00000000000..7f1a345615e --- /dev/null +++ b/gcc/testsuite/g++.dg/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 "-O2" } */ + +int size; +int x __attribute ((counted_by (size))); /* { dg-error "attribute is not supported for C\\+\\+" } */ + +struct trailing { + int count; + int field[] __attribute ((counted_by (count))); /* { dg-error "attribute is not supported for C\\+\\+" } */ +};