From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CT7HEG+V12pjDTsAWB0awg (envelope-from ) for ; Tue, 20 Oct 2026 12:23:11 -0400 Received: by simark.ca (Postfix, from userid 112) id 417671E050; Tue, 20 Oct 2026 12:23:11 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A0E1D1E04D for ; Tue, 20 Oct 2026 12:23:10 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CFCBE4CCCA34 for ; Tue, 20 Oct 2026 16:23:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CFCBE4CCCA34 Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 3275A4A9C01C for ; Tue, 20 Oct 2026 16:21:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3275A4A9C01C Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3275A4A9C01C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=158.69.221.121 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792513264; cv=none; b=wHMF26CODmbyhV2SqbzM3IghKaW9GLVm+5s+9K5ikGcKi9dSJWZqUL1XcUszvSQGbWFHXI1WNh844pz9nlk0HGeaXdzTgEPuskCbPBUqLLmuqlCbwwljguT8xH/UeIR+RLugzbwdi3TXf4Bkfl9sG0R5EF9vnGw/yAZksD/dzAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1792513264; c=relaxed/simple; bh=7bxNE0XdiBi36k2WrFwNyQRKVNKbiAU0ILSRUf34k9o=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=dqo43yyaTIVZifejFoz5fuOV7wkCpLUP0UHG+jDVvV4Z08BvYrUm/DwA/iq8D2xMkwfJItGsZapbwGbfBkyYAQJ+x9PfjR7D5DAgxAVu2fhGpaa+zQp/1C9Hp4FTufDDLFKZfrZCPv3bAyO6qBVkuy/KvVau0RWH+nrvIk7nMdg= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3275A4A9C01C Received: by simark.ca (Postfix) id 7D6AA1E09E; Tue, 20 Oct 2026 12:21:00 -0400 (EDT) From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 06/13] gdb: check exact results in the canonicalize selftest Date: Tue, 20 Oct 2026 12:17:28 -0400 Message-ID: <20261020162054.2140671-7-simon.marchi@efficios.com> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261020162054.2140671-1-simon.marchi@efficios.com> References: <20261020162054.2140671-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org The canonicalize selftest uses should_be_the_same, which canonicalizes two names and checks that the results are equal. This doesn't check what the canonical form actually is: both names going through the same wrong conversion would still pass. Replace should_be_the_same with should_canonicalize_to, which canonicalizes a name and compares the result to an expected string. Convert the existing tests: each name that was passed to should_be_the_same is now checked against the canonical form. Change-Id: Iaaa4712255a4d140b8a9756ccca062f4dc251f13 --- gdb/cp-name-parser.c | 59 ++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/gdb/cp-name-parser.c b/gdb/cp-name-parser.c index 710ffafcfc13..8012d6cc0a20 100644 --- a/gdb/cp-name-parser.c +++ b/gdb/cp-name-parser.c @@ -1023,18 +1023,19 @@ cpname_yylex (cp_name_parser_YYSTYPE *lvalp, #if GDB_SELF_TEST +/* Check that canonicalizing NAME gives EXPECTED. */ + static void -should_be_the_same (const char *one, const char *two) +should_canonicalize_to (const char *name, const char *expected) { - gdb::unique_xmalloc_ptr cpone = cp_canonicalize_string (one); - gdb::unique_xmalloc_ptr cptwo = cp_canonicalize_string (two); + gdb::unique_xmalloc_ptr canon = cp_canonicalize_string (name); + const char *result = canon != nullptr ? canon.get () : name; - if (cpone != nullptr) - one = cpone.get (); - if (cptwo != nullptr) - two = cptwo.get (); + if (!streq (result, expected)) + debug_printf ("canonicalize: \"%s\" gave \"%s\", expected \"%s\"\n", + name, result, expected); - SELF_CHECK (streq (one, two)); + SELF_CHECK (streq (result, expected)); } static void @@ -1047,30 +1048,34 @@ should_parse (const char *name) static void canonicalize_tests () { - should_be_the_same ("short int", "short"); - should_be_the_same ("int short", "short"); + should_canonicalize_to ("short int", "short"); + should_canonicalize_to ("int short", "short"); - should_be_the_same ("C<(char) 1>::m()", "C<(char) '\\001'>::m()"); - should_be_the_same ("x::y::z<1>", "x::y::z<0x01>"); - should_be_the_same ("x::y::z<1>", "x::y::z<01>"); - should_be_the_same ("x::y::z<(unsigned long long) 1>", "x::y::z<01ull>"); - should_be_the_same ("x::y::z<0b111>", "x::y::z<7>"); - should_be_the_same ("x::y::z<0b111>", "x::y::z<0t7>"); - should_be_the_same ("x::y::z<0b111>", "x::y::z<0D7>"); + should_canonicalize_to ("C<(char) 1>::m()", "C<(char)1>::m()"); + should_canonicalize_to ("C<(char) '\\001'>::m()", "C<(char)1>::m()"); + should_canonicalize_to ("x::y::z<0x01>", "x::y::z<1>"); + should_canonicalize_to ("x::y::z<01>", "x::y::z<1>"); + should_canonicalize_to ("x::y::z<(unsigned long long) 1>", "x::y::z<1ull>"); + should_canonicalize_to ("x::y::z<01ull>", "x::y::z<1ull>"); + should_canonicalize_to ("x::y::z<0b111>", "x::y::z<7>"); + should_canonicalize_to ("x::y::z<0t7>", "x::y::z<7>"); + should_canonicalize_to ("x::y::z<0D7>", "x::y::z<7>"); - should_be_the_same ("x::y::z<0xff'ff>", "x::y::z<65535>"); + should_canonicalize_to ("x::y::z<0xff'ff>", "x::y::z<65535>"); - should_be_the_same ("something", "something< void() >"); - should_be_the_same ("something", "something"); + should_canonicalize_to ("something< void() >", "something"); + should_canonicalize_to ("something", "something"); - should_be_the_same ("Foozle::fogey > (Empty)", - "Foozle::fogey> (Empty)"); + should_canonicalize_to ("Foozle::fogey > (Empty)", + "Foozle::fogey >(Empty)"); + should_canonicalize_to ("Foozle::fogey> (Empty)", + "Foozle::fogey >(Empty)"); - should_be_the_same ("something :: operator new [ ]", - "something::operator new[]"); - should_be_the_same ("something :: operator new", - "something::operator new"); - should_be_the_same ("operator()", "operator ()"); + should_canonicalize_to ("something :: operator new [ ]", + "something::operator new[]"); + should_canonicalize_to ("something :: operator new", + "something::operator new"); + should_canonicalize_to ("operator ()", "operator()"); } /* Test the C++ name parser's handling of some inputs. */ -- 2.56.0