From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id B9C8C3858CDB for ; Sun, 21 Apr 2024 17:00:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B9C8C3858CDB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B9C8C3858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718811; cv=none; b=IkYBCu+bu/QSfQQF9GxkJsYKtMNazUuLiEr7n664k/drhM55AwBAsWVKZZNHSMRYOqQLVPkNs68DyC57nsgY3B3srEJ9XfDr1tbLoWI8euFpLmJpK/crm3dODbSumyNq3W5oCeM0qkojBU4XTVoavpNEkkuSEF/TDSmCoVGpcvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713718811; c=relaxed/simple; bh=SSgoKKki7ZchFUGwoO95hqydUNFpl1xK18Cyr5QBEBw=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=BmALAAabOMz8s8xehmC7mRk8esjK3PP9Mh8LPU3fBCGZWCiwY83k1kNXNLXgecAR6eMqLphx2HsC6Nx415lFUcuxDuohJorNPf692k/WQxxEJoy5Mz1qP1SpLvTmcuoMRxFZBHWbw1Al40tUB3335BkUacVISV2dJldQn8vWoto= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6010a.ext.cloudfilter.net ([10.0.30.248]) by cmsmtp with ESMTPS id yDljrxPcePM1hyaXsr0bYg; Sun, 21 Apr 2024 17:00:04 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id yaXrrYqd4F4XpyaXsrsxcx; Sun, 21 Apr 2024 17:00:04 +0000 X-Authority-Analysis: v=2.4 cv=UpZlNfwB c=1 sm=1 tr=0 ts=66254614 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=raytVjVEu-sA:10 a=Qbun_eYptAEA:10 a=CCpqsmhAAAAA:8 a=82lU6H3CqPhDl4Y7wgwA:9 a=QEXdDO2ut3YA:10 a=ul9cdbp4aOFLsgKbc677:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=To:In-Reply-To:References:Message-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:Subject:Date:From:Sender:Reply-To:Cc:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=tP7PFHG5YvheY7CBpDWR2TLOWxOOowuyXlh0o+siIGw=; b=vDtN9zMDhNX6pzzIfUfOYkrKG2 ICdbASrqH89f36asWsWjK/OJbzBq1QYMd6IngeWN51sTz5CTxqYkxRyVUBMEt6NpPolckekfIZhMF 4mb6kfHK34oWqdP/IPTh+6M3B; Received: from 97-122-86-252.hlrn.qwest.net ([97.122.86.252]:53968 helo=[192.168.0.21]) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1ryaXr-003wVC-25 for gdb-patches@sourceware.org; Sun, 21 Apr 2024 11:00:03 -0600 From: Tom Tromey Date: Sun, 21 Apr 2024 11:00:05 -0600 Subject: [PATCH 05/10] Fix C++ name canonicalizations of character literals MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240421-canon-fixes-v1-5-4dc4791d270d@tromey.com> References: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> In-Reply-To: <20240421-canon-fixes-v1-0-4dc4791d270d@tromey.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.13.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.86.252 X-Source-L: No X-Exim-ID: 1ryaXr-003wVC-25 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-86-252.hlrn.qwest.net ([192.168.0.21]) [97.122.86.252]:53968 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfB82lPRIgjYiXQ+H9gbVYauPXaVDFB2PXkn2oZw9nIL+9s4ccICYxT5cgsEVPic4t9fAUeBoOz8zh2qMtZry85JwLcrQ2/bSIZHSA5/mQ4JDdzDNAbu6 nHh515x8LOJTFDMRLqSiOExmveJomqoKoy9YMGXPFrxvs170rs8BbEHtXHzhd/hujLLhi02sIMGOulei8P+HLhniPyazL9mDco4= X-Spam-Status: No, score=-3021.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,JMQ_SPF_NEUTRAL,SPF_HELO_NONE,SPF_PASS,TXREP,T_FILL_THIS_FORM_SHORT autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The names "void C<(char)1>::m()" and "void C<'\001'>::m()" should canonicalize to the same string, but currently they do not -- the former remains unchanged and the latter is transformed to "void C<(char)'\001'>::m()". This patch fixes the bug and also adds some unit tests. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=16843 --- gdb/cp-name-parser.y | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index 6003ed0b01e..6590194545f 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -44,6 +44,7 @@ #include "cp-support.h" #include "c-support.h" #include "parser-defs.h" +#include "gdbsupport/selftest.h" #define GDB_YY_REMAP_PREFIX cpname #include "yy-remap.h" @@ -1514,6 +1515,7 @@ yylex (YYSTYPE *lvalp, cpname_state *state) int c; int namelen; const char *tokstart; + char *copy; retry: state->prev_lexptr = state->lexptr; @@ -1544,6 +1546,10 @@ yylex (YYSTYPE *lvalp, cpname_state *state) return ERROR; } + /* We over-allocate here, but it doesn't really matter . */ + copy = (char *) obstack_alloc (&state->demangle_info->obstack, 30); + xsnprintf (copy, 30, "%d", c); + c = *state->lexptr++; if (c != '\'') { @@ -1551,15 +1557,10 @@ yylex (YYSTYPE *lvalp, cpname_state *state) return ERROR; } - /* FIXME: We should refer to a canonical form of the character, - presumably the same one that appears in manglings - the decimal - representation. But if that isn't in our input then we have to - allocate memory for it somewhere. */ lvalp->comp = state->fill_comp (DEMANGLE_COMPONENT_LITERAL, state->make_builtin_type ("char"), - state->make_name (tokstart, - state->lexptr - tokstart)); + state->make_name (copy, strlen (copy))); return INT; @@ -1970,3 +1971,39 @@ cp_demangled_name_to_comp (const char *demangled_name, return result; } + +#if GDB_SELF_TEST + +static void +should_be_the_same (const char *one, const char *two) +{ + gdb::unique_xmalloc_ptr cpone = cp_canonicalize_string (one); + gdb::unique_xmalloc_ptr cptwo = cp_canonicalize_string (two); + + if (cpone != nullptr) + one = cpone.get (); + if (cptwo != nullptr) + two = cptwo.get (); + + SELF_CHECK (strcmp (one, two) == 0); +} + +static void +canonicalize_tests () +{ + should_be_the_same ("short int", "short"); + should_be_the_same ("int short", "short"); + + should_be_the_same ("C<(char) 1>::m()", "C<(char) '\\001'>::m()"); +} + +#endif + +void _initialize_cp_name_parser (); +void +_initialize_cp_name_parser () +{ +#if GDB_SELF_TEST + selftests::register_test ("canonicalize", canonicalize_tests); +#endif +} -- 2.44.0