[llvm] baea913 - [llvm-locstats] Avoid the locstats when no scope bytes coverage found

Djordje Todorovic via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 13 04:45:59 PST 2019


Author: Djordje Todorovic
Date: 2019-12-13T13:45:44+01:00
New Revision: baea913609f1f3ddbd6fc6faf593524921507628

URL: https://github.com/llvm/llvm-project/commit/baea913609f1f3ddbd6fc6faf593524921507628
DIFF: https://github.com/llvm/llvm-project/commit/baea913609f1f3ddbd6fc6faf593524921507628.diff

LOG: [llvm-locstats] Avoid the locstats when no scope bytes coverage found

If the total number of PC range bytes in each variable's enclosing scope
('scope bytes total') is 0, we will have division by zero.

Differential Revision: https://reviews.llvm.org/D71415

Added: 
    llvm/test/tools/llvm-locstats/no_scope_bytes.ll

Modified: 
    llvm/utils/llvm-locstats/llvm-locstats.py

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-locstats/no_scope_bytes.ll b/llvm/test/tools/llvm-locstats/no_scope_bytes.ll
new file mode 100644
index 000000000000..9c36b65e8ae6
--- /dev/null
+++ b/llvm/test/tools/llvm-locstats/no_scope_bytes.ll
@@ -0,0 +1,39 @@
+; UNSUPPORTED: system-windows
+; REQUIRES: x86-registered-target
+; RUN: llc %s -o %t0.o -filetype=obj
+; RUN: %llvm-locstats %t0.o | FileCheck %s --check-prefix=LOCSTATS
+;
+; LOCSTATS: No scope bytes found.
+;
+; This is based on the following reproducer:
+;
+; int fn() {
+;  return 0;
+; }
+;
+; ModuleID = 'test.c'
+source_filename = "test.c"
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+; Function Attrs: norecurse nounwind readnone uwtable
+define dso_local i32 @fn() local_unnamed_addr !dbg !7 {
+entry:
+  ret i32 0, !dbg !11
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 10.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
+!1 = !DIFile(filename: "test.c", directory: "/")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!6 = !{!"clang version 10.0.0"}
+!7 = distinct !DISubprogram(name: "fn", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !DILocation(line: 2, column: 3, scope: !7)

diff  --git a/llvm/utils/llvm-locstats/llvm-locstats.py b/llvm/utils/llvm-locstats/llvm-locstats.py
index 6c8017abd6fd..408513c31916 100755
--- a/llvm/utils/llvm-locstats/llvm-locstats.py
+++ b/llvm/utils/llvm-locstats/llvm-locstats.py
@@ -29,6 +29,10 @@ def locstats_output(
   variables_coverage_map
   ):
 
+  if scope_bytes == 0:
+    print ('No scope bytes found.')
+    sys.exit(0)
+
   pc_ranges_covered = int(ceil(scope_bytes_covered * 100.0)
               / scope_bytes)
   variables_coverage_per_map = {}


        


More information about the llvm-commits mailing list