Message ID | 20240417184441.339037-1-cupertino.miranda@oracle.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 88DAB385841D for <patchwork@sourceware.org>; Wed, 17 Apr 2024 18:45:22 +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 DCE5F3858408 for <gcc-patches@gcc.gnu.org>; Wed, 17 Apr 2024 18:44:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCE5F3858408 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 DCE5F3858408 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=1713379493; cv=pass; b=OPzhpGFt16gaxkQWsMAWkM/iI15ueBhTRp0Cno8+wgJ2vdhsjHmU5cdJ6WJHXrOZEOLOfBpvLoZ38MKSEG/ezv3PY9VWzmtBnfwwROp+iL1lvzULr+RCaRexqTe74k+CpsyZ89YDF7Ir5186xtEo7T7wN2WEsy4t2lXUYcHKkAA= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1713379493; c=relaxed/simple; bh=51ucd4e+7ZUhYh8H/ZS8zuZNqrxP/hNpRV0kh8gZMDo=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=ubheVjpoIwSaYSHW4EFMtYI710dFq4m/EzGnoQX1mQ4Scak+SIbZRtmnd3CKN6mnE3vAOKEedQiylEKH5k81Nx1c0Fq4DgSY4isOjf1RzHZud7qyIY/iE4vtSZ5qDv1Yvr7Xjgi664/pLTXK0q/7jopDAiwF5PToxPuNB1uaDtI= 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.17.1.19/8.17.1.19) with ESMTP id 43HHiVQl006061 for <gcc-patches@gcc.gnu.org>; Wed, 17 Apr 2024 18:44:51 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=+RMfRtm58IrhG5jea0gDW+zPcXZPCu6WxrZliMABr84=; b=CtEVvZfavDmZ4LTy+OdxuF/UBnTnO3UtbNwsqx5i0q6luORZ0FsdjlBd8W0w7/j7kh0D 47vU1qxSravaHRJNC2yGDANp6tNrhIAWPAeMyq1EdqRs+9JUXkTVZbSIb6WVM2mAGurh i7UlZ1x65dvikgtfsVcfGPkXJnzj8/lYoPArdgb8YjNJk0QeCZvqcsrhsrARXWagdAKH SSJg/NsE/bj/d90AAidUtLJGBYmcelGL6/4zcr0mXoBj+1Eg0K5bsjtC5wZNCM4yTIcI b1A9QI7h97LlImbNBI43AoIqfVLNqUC5jGGjetqd/QPe99YqmSw02yegMUNY8MZ5v9X9 bw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xfhxbrhpf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for <gcc-patches@gcc.gnu.org>; Wed, 17 Apr 2024 18:44:50 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43HIdJJV014525 for <gcc-patches@gcc.gnu.org>; Wed, 17 Apr 2024 18:44:49 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3xfggfhey9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for <gcc-patches@gcc.gnu.org>; Wed, 17 Apr 2024 18:44:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Kl/wQBNHrpFIieI8sIHqGG3a46EmGjPCfeWHbH+0H+iRyMe3XhdaqQWFZftP286brdVKqxJJX1i7mP0vtiQySuFJf7WdYrehHINDGG//lg9hDzNPgAnMmf6+0mQih5f0yFSNbf9qBHEASq+gWnOO4IQ8udI2PHkt+AU1h5iaf56shx7j7ZYGqi0c8Q01NSEj50q+ZznJYX8xmCB6fv+7RUsf7DTEy/+eMlFROvWC56zmjyZXUw2141aaoh38885uPQENfuuimnRwRXN7FthqjZj4+cvkrtv34UyqxQHNl8c5HAfloNyiGhGBexowSesiwJLd2N44pW2u1V1X1xKAdg== 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=+RMfRtm58IrhG5jea0gDW+zPcXZPCu6WxrZliMABr84=; b=gsh/ZVpD8AcLASdbiBCuirfNED8WioeiBcSEs20AunUHYvpa6UHkfrOxi9LtBZbCjvWUbeGjYYcbtW8SeWsySvJdiInYArWz2YwZB6L8uQVk56HaOvkQXYXKKi6EIoYM2mCvZGObV5olXuOQ2S3Dp4pmeiBUNSRpcDDmFB7HMe1+USTYbV0TbaH0uL+cuhCO+WQApReQvKvouTfdgseMKWNT6HsaaVvBtrnUspEsZDbeyzN/Fl6GRyDLR1R9pIsiri0ixMzR+fbgbZ+muEUzYipr6TaggLDFH2kutUegwq+0jd3oDjz4/sm2j9eq8bqqDZ/0MBCTNgDiFp9HjWeKRg== 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=+RMfRtm58IrhG5jea0gDW+zPcXZPCu6WxrZliMABr84=; b=j3EiXUfI0ozyG8aJNbcur6eG7rudomcvzoqe81rH/w+AdvNbm2mh+hVzd9MA/+tsLO2BbVXOYRqVtL7Ptz3o9AEa9Hr/7AVRn6BNv1Z8vgZhE/IM0Ap3RBptFcJVC/qLU9qrktS1p4rpVxGlmlJAf9DwfJKVGR5IReoT6e3m63Q= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by BN0PR10MB4856.namprd10.prod.outlook.com (2603:10b6:408:12b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7452.50; Wed, 17 Apr 2024 18:44:47 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c%4]) with mapi id 15.20.7472.037; Wed, 17 Apr 2024 18:44:47 +0000 From: Cupertino Miranda <cupertino.miranda@oracle.com> To: gcc-patches@gcc.gnu.org Cc: jose.marchesi@oracle.com, david.faust@oracle.com, elena.zannoni@oracle.com, Cupertino Miranda <cupertino.miranda@oracle.com> Subject: [PATCH v2] bpf: remove huge memory waste with string allocation. Date: Wed, 17 Apr 2024 19:44:41 +0100 Message-Id: <20240417184441.339037-1-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: LO4P265CA0263.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:37c::12) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|BN0PR10MB4856:EE_ X-MS-Office365-Filtering-Correlation-Id: 8a90e05a-96a3-46d8-2024-08dc5f0e74b7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ifGZiuD/eYVs9YRIz5SILqEAu3QlnaGHuWo6QveFKUXzC1tIIPSFx88WM0JM5c1uhRzi6fhMioNAry/BynHlUjWPqqsplqwouvGH4JQfU6GmscJ92gBLRHlQhMiWGa5szaZNWV5+QY+Ll9/PYxnjXo1iOudJIx3SJivm+h1S2pf+BIKDZp19QtZ6xS41WIxerNqoKFtb2+UOQT+sp8EJWPVwNUYj+yt9jSlhEytC2S6nupHk+5/m2JGOa8Z4n0BELMRWq/kKMGr6h/2fnVj62SMjK64NWQqX5x08BiJwemKplDTG+VG7JAdBk9RQBS8EojKIjSUOjfTox0/6okfPP0dzI/ZtKoE+2l8euJt3rXHYSbqEK3VxSzztUmc1u369N35Z261+mCkyVrZM8eqU3Vy22UQ8vxsV6fKVfRnwK9b5hD+1oE/thuC0ktpz3t1pM5k5bk7BCcP/UyI1YaMVGFyhX+yDay4a/EeFW1cb9wjLZQi5Y24A1QYtgD497SQRAh4qw/9IoXVjuh+mQCM2+Nkv0n2Zjxr8i1ankfHEb645F/Q3k8fZEOWvt4jXhOXHAk5fa8c5/gMkKrXTmos+fU1Ly31+0bxM0TW9BelTjt/4MXAqDUSUoWUaIiE/7UCsblVOwjRaaw8wybZqm4VMjsIRAJCGapYtfgmGq1ShyHU= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR10MB4382.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: Ktm8O68NsCy/FG2n4kPJxjh+SwIUBUK/h1m5Hni/PXPt+UKswOAIGhtuXz9fjIDGzm6xgin8jvYldwq0KSV9a5eu/u14IoUX+q754l5m1soWRV7ljbVLgb4ohu5LOnmARjASOWmI5/Kn4A9/9S69j5qIUijOmwPoSknMMjMKzXZJiqWCSeM7Q+sahq47nZaxOhHljLlaZWK6FxWa2ZW0W2fJmXySdLZEvvSCACVSsOy7JSCZBNc/5P36mCCac23RcGlUTHjnSTCAElqscufx2w637qgpMSfkpG83F40RAhlL8qpcIX5CI+WVOHsDtAjFxU/aP/JngfUzH4PSZLHO5nf8GFzxk3XeBdrXyVWzS6cvBnlSOdYRQ7qi6Y4noAElfB+yjq9f73YCgS0sXyWXsw9QLsnNIm/M0a+NgauTcM2+xv3Tv8fZclXOuUTr+lDqXFEky4tQSvPNPomzbzuMDnGCPcG0fz8QUDCQlIKs2WfOIvjWwTAsGs1mSp2ulayPqSqvIW5ZzDLEKjWjcjnAhQWyFg+xjptUGykWeOQprPfW6FvN2MHKhFV6tkMnxyyfBwdzLZBpMnJsuyRdCqryr8xrHb69NmLL6gqeTtpzsR+YbDppz1UlTGwMDiv9enBUAf6P6cd9jeP4MO9qfQZxA4e26OPXNQ69eGEZvLlL+d6I0pVd8WAqlHP16DqQKUqXX17ASOq68P+bVwZ8ceHoWFysqdwjoq0KIY4n2tScL8tAqQNqqccZHorMeDhI9XsXbWBMUnCNlU7P04zrfIkLHEThoAw4gZsDcCjPaQzm68IO0ODACJBtfGb+rUWvFAWMpCpP5VYgihxFi6woMOn50OKONSDqPRm3wgoQED1zZZh5doT3OnXeTky+F0/119QCt6rvBipMVGHK1SPEB3C8ID/h0nkpFtpum8lypRcrpbqHAyp1BF5WKfEVmm480z9ZIa11+EB2S9fvIAgPZkM8Y5encAiyUet8ptjuzaPOm5gPyuugpRHLAilYzKnOZeG9c43OS5opZSVE8TzK14vXGAniaNmB2x8/4uX7Aq587LDM7nmeIaeWdt5xbNKA055KHomemhRmHLGem5cAK5lLJZQ/GnymSpv6oz9WlYbTriijmcNAzwSWHFJ9mbaXeM3pKHLxnohd8d7xZx4mWuIQZjTIaKoau3aEHCUNKRhU6fji5L7h3Ty1jncri7hTPgXyZRbFTOnw4jJqDP71d2EBYhNH84Lbhp0tg6s7WKNSc0NAf1ed2PzipRghRWlDPGhrQO/twomw5nyd4Xn1oV4N2pF47pfzGEXVrquHDMJno/XslhzkDzefeFosALwQmtSTKG17Rh6R1GnSV8CwneDmPORTxDQfuUKUaUsvhT9v5N9TfhFRa0cm1tkCrpSxsgMb4oL8CqT8KQGSxjvsjFqB2UmwvgLiwZFq2ENvRPOdvS6N7x+zCNeYrYokNupKzTd00gKrIGTyncQRMiogJ0YohxwR8wrSwlxvDP4BtmGMmDYtCSTcuNI/oMD3+YhueYl2dkvfA6qBB0PSrE/gEiM0Fd2mGleMxTCOXoaux645vAjrjeL1Qbngo6nNkRlMmhU8p0bvAX6FFZ4P9e6W6JrsYtuiF3r8Fl/xC4ABLx2lhY0= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: VlzoTGdkgJK1prJ2BhockjY9VjNGlYCB6aTBNiMuiUgQDDqWAMbgqHQfTyIWHA9TDgBxYQ2s1W2MYrag+y9lpujgiXIEdYLq1TLxefQlEDQodbjQ3cqZ0xWTZpbfBU9dISVgrMDXjNarXS5ZZNjlLFzDmp5wST/i0V12/PzlT87RKhHut88r81cOM1uBKUoDTUy3TGVoyWVB3/oWRaiT3SsgyfZ35yPNej/yx9qGiQPdTSc0r0E/ak18rg0ocvpDq3DDdXY7fsuqLKyyaOX8wfSZ1qLTjzPRL6Wh57po3q2H3RNI+1tIcoqix4tYUEneGWTBXsohNzsaa/9lBunzrbj6HLP2ThQ/7hess33FGJfEVOD/jd5qlarIabZGGUhC5ID/Yy1zKBcFIkHrIkwrBmDy7eCNtkvDp27fmW9mnq6rSviO7plNXsl6x3cecEtkL3GYsNpLio5N6CVMEXS0xTNzMnHufuP6VkIMmtsHqp3A8RQd/kYvNc30w9vVUvrfmP/ZjXfNk9dEBEGxtlO52/w3L/cphcym6vvxBLOFNpOJI8Zb8JGO1gHpdQcyJFDAaUnf8bASga4CryzL53o2GgowmwpRAWKx0VodY7ZneQM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a90e05a-96a3-46d8-2024-08dc5f0e74b7 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Apr 2024 18:44:47.4068 (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: DcbmUOANtQjgKsR72mvRNczkwPj2x8dR/gJP4uqlezyHVbz6aadvnHbEJ9aemF+1ae23rUHKZQxdx3vt+YqQjlw0kpLuIra9WIsZtwzTbpk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB4856 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-17_16,2024-04-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 bulkscore=0 spamscore=0 malwarescore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404170133 X-Proofpoint-ORIG-GUID: 9brS_eQyAZLsjmYhb0ShqFQshCG_KO1D X-Proofpoint-GUID: 9brS_eQyAZLsjmYhb0ShqFQshCG_KO1D X-Spam-Status: No, score=-12.8 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org |
Series |
[v2] bpf: remove huge memory waste with string allocation.
|
|
Checks
Context | Check | Description |
---|---|---|
linaro-tcwg-bot/tcwg_gcc_build--master-arm | success | Testing passed |
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 | success | Testing passed |
linaro-tcwg-bot/tcwg_gcc_check--master-arm | success | Testing passed |
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 | success | Testing passed |
Commit Message
Cupertino Miranda
April 17, 2024, 6:44 p.m. UTC
The BPF backend was allocating an unnecessarily large string when constructing CO-RE relocations for enum types. gcc/ChangeLog: * config/bpf/core-builtins.cc (process_enum_value): Correct string allocation. --- gcc/config/bpf/core-builtins.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
Comments
On 4/17/24 11:44, Cupertino Miranda wrote: > The BPF backend was allocating an unnecessarily large string when > constructing CO-RE relocations for enum types. > > gcc/ChangeLog: > * config/bpf/core-builtins.cc (process_enum_value): Correct > string allocation. > --- > gcc/config/bpf/core-builtins.cc | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc > index e03e986e2c1..beb039ea6e0 100644 > --- a/gcc/config/bpf/core-builtins.cc > +++ b/gcc/config/bpf/core-builtins.cc > @@ -870,12 +870,14 @@ process_enum_value (struct cr_builtins *data) > unsigned int index = 0; > for (tree l = TYPE_VALUES (type); l; l = TREE_CHAIN (l)) > { > + gcc_assert (index < (1 << 16)); Since the index here is computed from the TREE node and not BTF, is it somehow already enforced that this code won't be run if the enum can't be represented in BTF? If not, I don't think the assert is a good idea. The TREE node could be an enum too large for BTF, but not too large for gcc. So the assert will cause an ICE for something that is a representation limit (in BTF and by extension .BTF.ext i.e. CO-RE) rather than a compiler bug. IMO an error or warning makes more sense here, something like: if (index >= (1 << 16)) { bpf_error ("enumerator in CO-RE relocation cannot be represented"); break; } WDYT? > if (TREE_VALUE (l) == expr) > { > - char *tmp = (char *) ggc_alloc_atomic ((index / 10) + 1); > - sprintf (tmp, "%d", index); > - ret.str = (const char *) tmp; > - > + /* Index can only be a value up to 2^16. Should always fit > + in 6 chars. */ > + char tmp[6]; > + sprintf (tmp, "%u", index); > + ret.str = CONST_CAST (char *, ggc_strdup(tmp)); > break; > } > index++;
diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc index e03e986e2c1..beb039ea6e0 100644 --- a/gcc/config/bpf/core-builtins.cc +++ b/gcc/config/bpf/core-builtins.cc @@ -870,12 +870,14 @@ process_enum_value (struct cr_builtins *data) unsigned int index = 0; for (tree l = TYPE_VALUES (type); l; l = TREE_CHAIN (l)) { + gcc_assert (index < (1 << 16)); if (TREE_VALUE (l) == expr) { - char *tmp = (char *) ggc_alloc_atomic ((index / 10) + 1); - sprintf (tmp, "%d", index); - ret.str = (const char *) tmp; - + /* Index can only be a value up to 2^16. Should always fit + in 6 chars. */ + char tmp[6]; + sprintf (tmp, "%u", index); + ret.str = CONST_CAST (char *, ggc_strdup(tmp)); break; } index++;