From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx.kolabnow.com (mx.kolabnow.com [212.103.80.154]) by sourceware.org (Postfix) with ESMTPS id 0472E3858C39 for ; Wed, 3 Aug 2022 16:03:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0472E3858C39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=lambda.is Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=lambda.is Received: from localhost (unknown [127.0.0.1]) by mx.kolabnow.com (Postfix) with ESMTP id AD93512DB for ; Wed, 3 Aug 2022 18:03:07 +0200 (CEST) Authentication-Results: ext-mx-out002.mykolab.com (amavisd-new); dkim=pass (4096-bit key) reason="pass (just generated, assumed good)" header.d=kolabnow.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kolabnow.com; h= content-transfer-encoding:content-type:content-type:subject :subject:from:from:content-language:mime-version:date:date :message-id:received:received:received; s=dkim20160331; t= 1659542587; x=1661356988; bh=60NqqO2XFsHiSGbjerrrbjt8KIxXyDYqRsG FFFWllO0=; b=cLnIPTsCVueWxCREWS2M7qXU/qUNOgsMhtD5B9Yx0u0YHs5oLHE P+okGxA0rzUQBz+pPTbCLlJdjQI3CoIo3UyB1QRNFQhQ7brrGnlXCxtVJcSy4qHe cBpa6BSXdYw8Wt3+Xl12/EAlapIie95A8gtXKnmNhyXP9vKLWmHwB3PNU0b1ruO3 dVrWRtZIxf9J3cMcW07AYdhTfd3wCTlFXxZiBLIV/UQdgyIhT+be+si7NXet4DyR +lkOmzdpC9J+CCmLPnmkLOBeNstYratkZdyTdiEdnMo3nHjmc+20pdI8VxFrDQt3 kxVxPLnR9NLF6Kz4CIJBB4uwxKElam4UyxCWM54MOowRvDKJ5YzdmCCB4Fnyp7nz AdZ6bzzZJXROry7vZqo/brep+PN6Qmsxj0klps5P2s+SZLgCtKoci3ViGTsfZJwU odNuw+BYBH5z4jiAoJ0sNOmXk8gT7+zxWQVxNgGi2hCuktVM9aVtsVcJe+lgszny oz0VZRI5uewzSFfKw//aSezoewTeJDjkLt3prfTOk3AUtG+e1ZBUeitN2EKZYfNQ KVJdtrfgD221N03zFSDkDBJQt5y9pjSxUgp3kjSpP1BhGd5y+6t1Wmj45KkgGAbS dfhRVd5q7CwG2IvAK02HBHMRsiKdsHZBiudk0seYVTtELIIt+uj5mHCo= X-Virus-Scanned: amavisd-new at mykolab.com X-Spam-Score: -1.899 X-Spam-Level: X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 Received: from mx.kolabnow.com ([127.0.0.1]) by localhost (ext-mx-out002.mykolab.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uAz2k1_uIagd for ; Wed, 3 Aug 2022 18:03:07 +0200 (CEST) Received: from int-mx002.mykolab.com (unknown [10.9.13.2]) by mx.kolabnow.com (Postfix) with ESMTPS id 7E17C1140 for ; Wed, 3 Aug 2022 18:03:06 +0200 (CEST) Received: from ext-subm001.mykolab.com (unknown [10.9.6.1]) by int-mx002.mykolab.com (Postfix) with ESMTPS id 45E4136CA for ; Wed, 3 Aug 2022 18:03:06 +0200 (CEST) Message-ID: <3c93e70d-293e-2190-125b-f840c31d2087@lambda.is> Date: Wed, 3 Aug 2022 18:03:05 +0200 MIME-Version: 1.0 Content-Language: en-US From: =?UTF-8?Q?J=c3=b8rgen_Kvalsvik?= Subject: Should templates with multiple instantiations contribute to summaries in gcov? To: gcc@gcc.gnu.org Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Aug 2022 16:03:11 -0000 I have this program: #include template T add (T x, T y) { if (x > y) return x + y; else return x; } template T sub (T x, T y) { if (x > y) return x - y; else return x; } int main() { int i1 = 10; int i2 = 12; double d1 = 10.0; double d2 = 12.0; auto x = add(i1, i2); auto y = add(d1, d2); auto z = sub(i2, i1); printf ("%d %f %d\n", x, y, z); } add() is instantiated for int, double, and sub() is only instantiated for int. $ gcc -v gcc version 12.0.1 20220426 (experimental) (GCC) $ gcc --coverage demo.cc -o demo && ./demo $ gcov -mfb demo Function 'int sub(int, int)' Lines executed:75.00% of 4 Function 'double add(double, double)' No executable lines Function 'int add(int, int)' No executable lines Function 'main' Lines executed:100.00% of 10 File 'demo.cc' Lines executed:88.89% of 18 Branches executed:100.00% of 2 Taken at least once:50.00% of 2 Calls executed:100.00% of 4 Creating 'demo.cc.gcov' Lines executed:88.89% of 18 So it reports lines and branches accurately for templates with a single instantiation, but nothing when there are multiple. When you look at the .gcov file however the branches are reported for all the instantiations: double add(double, double): function double add(double, double) called 1 returned 100% blocks executed 75% 1: 4:T add (T x, T y) { 1: 5: if (x > y) branch 0 taken 0% (fallthrough) branch 1 taken 100% #####: 6: return x + y; -: 7: else 1: 8: return x; -: 9:} Skimming gcov.cc I found accumulate_line_info. By applying this patch the file summary includes all instantiations: diff --git a/gcc/gcov.cc b/gcc/gcov.cc index 04bbc774eec..c0ee9d1cd3f 100644 --- a/gcc/gcov.cc +++ b/gcc/gcov.cc @@ -2952,7 +2952,7 @@ accumulate_line_counts (source_info *src) it2 != fn->lines.end (); it2++) { line_info *line = &(*it2); - accumulate_line_info (line, src, false); + accumulate_line_info (line, src, true); } } File 'demo.cc' Lines executed:84.62% of 26 Branches executed:100.00% of 6 Taken at least once:50.00% of 6 Calls executed:100.00% of 4 Creating 'demo.cc.gcov' It doesn't fix the function summaries however: Function 'int add(int, int)' No executable lines Looking through the changelog it looks like this was introduced to work with destructors/C++ clones https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48463 Is there a non-obvious downside to look into groups in order to have templates count towards file- and function summaries? Any subtle interactions at play? Is this a bug? Thanks, Jørgen