From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id D1157385841D for ; Fri, 5 Nov 2021 17:25:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D1157385841D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 920A6212C2 for ; Fri, 5 Nov 2021 17:25:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1636133111; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nrAVx126ZgXfNCwHUIphlLgbXmQZru9nTSRwUia0qWY=; b=AT81cTe4dLkm7Dl5iTQY2YoHo4weDFGAeiKC8FDBy6Xkz0qzJyYRSmm9ue3LEHr3hvzKRf +I+43+IigPEnb3r0BsCvDlXUrPseNuQOJa0YrCHUS22R1Qe67A5tW9Z7kJ9TbL43EWLb0c as+4fB7zgdc+PMDUVl+Oq5zNorx+4TE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1636133111; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nrAVx126ZgXfNCwHUIphlLgbXmQZru9nTSRwUia0qWY=; b=m+sW+E+bbWDmRYE0ir869aCmVB2CEVtA2fpCy1BUviGezlN+CcTK1xvMOnCvhMtK/8JVju t8SdzZxXLhsQ43BQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 8240A14013 for ; Fri, 5 Nov 2021 17:25:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id TCK/HvdohWHYXQAAMHmgww (envelope-from ) for ; Fri, 05 Nov 2021 17:25:11 +0000 Message-ID: <51aaa2bc-f5d7-761e-79cb-c3fb9b395f1a@suse.cz> Date: Fri, 5 Nov 2021 18:25:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] gcov-profile: Fix -fcompare-debug with -fprofile-generate [PR100520] To: gcc-patches@gcc.gnu.org Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Nov 2021 17:25:14 -0000 Hello. This strips .gk from aux_base_name in coverage.c. Do you like the implementation of endswith, or do we have the functionality somewhere? Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin PR gcov-profile/100520 gcc/ChangeLog: * coverage.c (coverage_compute_profile_id): Strip .gk when compare debug is used. * system.h (endswith): New function. gcc/testsuite/ChangeLog: * gcc.dg/pr100520.c: New test. --- gcc/coverage.c | 7 +++++-- gcc/system.h | 13 +++++++++++++ gcc/testsuite/gcc.dg/pr100520.c | 5 +++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr100520.c diff --git a/gcc/coverage.c b/gcc/coverage.c index 4467f1eaa5c..4daa3f9fc30 100644 --- a/gcc/coverage.c +++ b/gcc/coverage.c @@ -571,8 +571,11 @@ coverage_compute_profile_id (struct cgraph_node *n) if (!use_name_only && first_global_object_name) chksum = coverage_checksum_string (chksum, first_global_object_name); - chksum = coverage_checksum_string - (chksum, aux_base_name); + char *base_name = xstrdup (aux_base_name); + if (endswith (base_name, ".gk")) + base_name[strlen (base_name) - 3] = '\0'; + chksum = coverage_checksum_string (chksum, base_name); + free (base_name); } /* Non-negative integers are hopefully small enough to fit in all targets. diff --git a/gcc/system.h b/gcc/system.h index adde3e264b6..4ac656c9c3c 100644 --- a/gcc/system.h +++ b/gcc/system.h @@ -1305,4 +1305,17 @@ startswith (const char *str, const char *prefix) return strncmp (str, prefix, strlen (prefix)) == 0; } +/* Return true if STR string ends with SUFFIX. */ + +static inline bool +endswith (const char *str, const char *suffix) +{ + size_t str_len = strlen (str); + size_t suffix_len = strlen (suffix); + if (str_len < suffix_len) + return false; + + return memcmp (str + str_len - suffix_len, suffix, suffix_len) == 0; +} + #endif /* ! GCC_SYSTEM_H */ diff --git a/gcc/testsuite/gcc.dg/pr100520.c b/gcc/testsuite/gcc.dg/pr100520.c new file mode 100644 index 00000000000..60f79c2b888 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr100520.c @@ -0,0 +1,5 @@ +/* PR gcov-profile/100520 */ +/* { dg-do compile } */ +/* { dg-options "-fcompare-debug -fprofile-generate" } */ + +static int f() {} -- 2.33.1