From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 80644386EC59 for ; Tue, 22 Sep 2020 07:18:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 80644386EC59 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mliska@suse.cz X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id E4092AB54 for ; Tue, 22 Sep 2020 07:19:01 +0000 (UTC) From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Subject: [PATCH] gcov: fix streaming corruption To: gcc-patches@gcc.gnu.org Message-ID: <1a8e6630-b4c5-62b2-2eff-76251288701d@suse.cz> Date: Tue, 22 Sep 2020 09:18:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Tue, 22 Sep 2020 07:18:27 -0000 As mentioned in the PR, line number equal to 0 is a bogus. Moreover, it messes up GCNO file format where we use 0 as a separator. I'm thus suggesting to start lines with at least 1. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. I'll install the patch if there are no comments. Thanks, Martin gcc/ChangeLog: PR gcov-profile/97069 * profile.c (branch_prob): Line number must be at least 1. gcc/testsuite/ChangeLog: PR gcov-profile/97069 * g++.dg/gcov/pr97069.C: New test. --- gcc/profile.c | 6 +++--- gcc/testsuite/g++.dg/gcov/pr97069.C | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/gcov/pr97069.C diff --git a/gcc/profile.c b/gcc/profile.c index fe8963cc9e9..45409591629 100644 --- a/gcc/profile.c +++ b/gcc/profile.c @@ -1375,7 +1375,7 @@ branch_prob (bool thunk) seen_locations.add (loc); expanded_location curr_location = expand_location (loc); output_location (&streamed_locations, curr_location.file, - curr_location.line, &offset, bb); + MAX (1, curr_location.line), &offset, bb); } for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) @@ -1386,7 +1386,7 @@ branch_prob (bool thunk) { seen_locations.add (loc); output_location (&streamed_locations, gimple_filename (stmt), - gimple_lineno (stmt), &offset, bb); + MAX (1, gimple_lineno (stmt)), &offset, bb); } } @@ -1401,7 +1401,7 @@ branch_prob (bool thunk) { expanded_location curr_location = expand_location (loc); output_location (&streamed_locations, curr_location.file, - curr_location.line, &offset, bb); + MAX (1, curr_location.line), &offset, bb); } if (offset) diff --git a/gcc/testsuite/g++.dg/gcov/pr97069.C b/gcc/testsuite/g++.dg/gcov/pr97069.C new file mode 100644 index 00000000000..040e336662a --- /dev/null +++ b/gcc/testsuite/g++.dg/gcov/pr97069.C @@ -0,0 +1,20 @@ +// PR gcov-profile/97069 +// { dg-options "--coverage" } +// { dg-do run { target native } } + +# 0 "pr97069.C" +# 0 "" +# 0 "" +# 1 "/usr/include/stdc-predef.h" 1 3 4 +# 0 "" 2 +# 1 "pr97069.C" +int main() +{ + return 0; +} +# 0 "pr97069.C" +void zero_line_directive() +{ +} + +// { dg-final { run-gcov pr97069.C } } -- 2.28.0