From 17d25e30441243cffa8e80f71fe4ec461eaa7371 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Fri, 29 Apr 2016 01:31:49 +0000 Subject: [PATCH] [llvm-cov] Don't emit 'nan%' in reports git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267971 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/tools/llvm-cov/prevent_false_instantiations.h | 6 ++++-- tools/llvm-cov/CoverageSummaryInfo.h | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/test/tools/llvm-cov/prevent_false_instantiations.h b/test/tools/llvm-cov/prevent_false_instantiations.h index 667ebde6d16..a8c72076d16 100644 --- a/test/tools/llvm-cov/prevent_false_instantiations.h +++ b/test/tools/llvm-cov/prevent_false_instantiations.h @@ -1,9 +1,11 @@ // Checks that function instantiations don't go to a wrong file. -// CHECK-NOT: {{_Z5func[1,2]v}} +// INSTANTIATION-NOT: {{_Z5func[1,2]v}} +// NAN-NOT: 0{{[ \t]+}}nan%{{[ \t]+}}0{{[ \t]+}}nan% // RUN: llvm-profdata merge %S/Inputs/prevent_false_instantiations.proftext -o %t.profdata -// RUN: llvm-cov show %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %t.profdata -filename-equivalence %s | FileCheck %s +// RUN: llvm-cov show %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %t.profdata -filename-equivalence %s | FileCheck %s -check-prefix=INSTANTIATION +// RUN: llvm-cov report %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %t.profdata | FileCheck %s -check-prefix=NAN #define DO_SOMETHING() \ do { \ diff --git a/tools/llvm-cov/CoverageSummaryInfo.h b/tools/llvm-cov/CoverageSummaryInfo.h index c393b00d32a..a8902042403 100644 --- a/tools/llvm-cov/CoverageSummaryInfo.h +++ b/tools/llvm-cov/CoverageSummaryInfo.h @@ -47,6 +47,8 @@ struct RegionCoverageInfo { bool isFullyCovered() const { return Covered == NumRegions; } double getPercentCovered() const { + if (NumRegions == 0) + return 0.0; return double(Covered) / double(NumRegions) * 100.0; } }; @@ -83,6 +85,8 @@ struct LineCoverageInfo { bool isFullyCovered() const { return Covered == (NumLines - NonCodeLines); } double getPercentCovered() const { + if (NumLines - NonCodeLines == 0) + return 0.0; return double(Covered) / double(NumLines - NonCodeLines) * 100.0; } }; @@ -109,6 +113,8 @@ struct FunctionCoverageInfo { bool isFullyCovered() const { return Executed == NumFunctions; } double getPercentCovered() const { + if (NumFunctions == 0) + return 0.0; return double(Executed) / double(NumFunctions) * 100.0; } };