[PATCH] D22020: [esan|cfrag] Handle binaries built with -esan-small-binary

Qin Zhao via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 5 14:46:40 PDT 2016


zhaoqin created this revision.
zhaoqin added a reviewer: aizatsky.
zhaoqin added subscribers: vitalybuka, zhaoqin, kcc, eugenis, bruening, llvm-commits.
Herald added a subscriber: kubabrecka.

Handles binaries built with -esan-small-binary and print less
information.

Updates test struct-simple.cpp.

http://reviews.llvm.org/D22020

Files:
  lib/esan/cache_frag.cpp
  test/esan/TestCases/struct-simple.cpp

Index: test/esan/TestCases/struct-simple.cpp
===================================================================
--- test/esan/TestCases/struct-simple.cpp
+++ test/esan/TestCases/struct-simple.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_esan_frag -O0 %s -DPART1 -c -o %t-part1.o 2>&1
+// RUN: %clang_esan_frag -O0 %s -DPART1 -mllvm -esan-small-binary -c -o %t-part1.o 2>&1
 // RUN: %clang_esan_frag -O0 %s -DPART2 -c -o %t-part2.o 2>&1
 // RUN: %clang_esan_frag -O0 %s -DMAIN -c -o %t-main.o 2>&1
 // RUN: %clang_esan_frag -O0 %t-part1.o %t-part2.o %t-main.o -o %t 2>&1
@@ -163,8 +163,8 @@
   // CHECK-NEXT:  Unregister struct.S#2#11#11:    2 fields
   // CHECK-NEXT:   {{.*}} struct S
   // CHECK-NEXT:   {{.*}}  size = 8, count = 2, ratio = 2, array access = 0
-  // CHECK-NEXT:   {{.*}}  # 0: offset = 0, size = 4, count = 2, type = i32
-  // CHECK-NEXT:   {{.*}}  # 1: offset = 4, size = 4, count = 0, type = i32
+  // CHECK-NEXT:   {{.*}}  # 0: count = 2
+  // CHECK-NEXT:   {{.*}}  # 1: count = 0
   // CHECK-NEXT:  Unregister struct.D#3#11#11#11: 3 fields
   // CHECK-NEXT:   {{.*}} struct D
   // CHECK-NEXT:   {{.*}}  size = 12, count = 2, ratio = 2, array access = 0
@@ -178,27 +178,27 @@
   // CHECK-NEXT:  Unregister struct.A#2#11#11:    2 fields
   // CHECK-NEXT:   {{.*}} struct A
   // CHECK-NEXT:   {{.*}}  size = 8, count = 2049, ratio = 2048, array access = 0
-  // CHECK-NEXT:   {{.*}}  # 0: offset = 0, size = 4, count = 2048, type = i32
-  // CHECK-NEXT:   {{.*}}  # 1: offset = 4, size = 4, count = 1, type = i32
+  // CHECK-NEXT:   {{.*}}  # 0: count = 2048
+  // CHECK-NEXT:   {{.*}}  # 1: count = 1
   // CHECK-NEXT:  Unregister struct.B#2#3#2:      2 fields
   // CHECK-NEXT:   {{.*}} struct B
   // CHECK-NEXT:   {{.*}}  size = 16, count = 2097153, ratio = 2097152, array access = 0
-  // CHECK-NEXT:   {{.*}}  # 0: offset = 0, size = 4, count = 1, type = float
-  // CHECK-NEXT:   {{.*}}  # 1: offset = 8, size = 8, count = 2097152, type = double
+  // CHECK-NEXT:   {{.*}}  # 0: count = 1
+  // CHECK-NEXT:   {{.*}}  # 1: count = 2097152
   // CHECK-NEXT:  Unregister union.U#1#3:         1 fields
   // CHECK-NEXT:  Duplicated struct.S#2#11#11:    2 fields
   // CHECK-NEXT:  Unregister struct.D#3#14#11#11: 3 fields
   // CHECK-NEXT:  {{.*}} struct D
   // CHECK-NEXT:  {{.*}}  size = 128, count = 2097153, ratio = 2097153, array access = 0
-  // CHECK-NEXT:  {{.*}}  # 0: offset = 0, size = 4, count = 1, type = i32
-  // CHECK-NEXT:  {{.*}}  # 1: offset = 4, size = 4, count = 0, type = i32
-  // CHECK-NEXT:  {{.*}}  # 2: offset = 8, size = 120, count = 2097152, type = [10 x %struct.anon]
+  // CHECK-NEXT:  {{.*}}  # 0: count = 1
+  // CHECK-NEXT:  {{.*}}  # 1: count = 0
+  // CHECK-NEXT:  {{.*}}  # 2: count = 2097152
   // CHECK-NEXT:  Unregister struct.anon#3#11#11#11: 3 fields
   // CHECK-NEXT:  {{.*}} struct anon
   // CHECK-NEXT:  {{.*}}  size = 12, count = 2097152, ratio = 4194304, array access = 2097152
-  // CHECK-NEXT:  {{.*}}  # 0: offset = 0, size = 4, count = 0, type = i32
-  // CHECK-NEXT:  {{.*}}  # 1: offset = 4, size = 4, count = 2097152, type = i32
-  // CHECK-NEXT:  {{.*}}  # 2: offset = 8, size = 4, count = 0, type = i32
+  // CHECK-NEXT:  {{.*}}  # 0: count = 0
+  // CHECK-NEXT:  {{.*}}  # 1: count = 2097152
+  // CHECK-NEXT:  {{.*}}  # 2: count = 0
   // CHECK-NEXT: {{.*}}EfficiencySanitizer: total struct field access count = 6293518
 }
 #endif // MAIN
Index: lib/esan/cache_frag.cpp
===================================================================
--- lib/esan/cache_frag.cpp
+++ lib/esan/cache_frag.cpp
@@ -99,10 +99,17 @@
   Report("  %s %.*s\n", type, end - start, start);
   Report("   size = %u, count = %llu, ratio = %llu, array access = %llu\n",
          Struct->Size, Handle->Count, Handle->Ratio, *Struct->ArrayCounter);
-  for (u32 i = 0; i < Struct->NumFields; ++i) {
-    Report("   #%2u: offset = %u,\t size = %u,\t count = %llu,\t type = %.*s\n",
-           i, Struct->FieldOffsets[i], Struct->FieldSize[i],
-           Struct->FieldCounters[i], TypePrintLimit, Struct->FieldTypeNames[i]);
+  if (Struct->FieldSize == nullptr) {
+    for (u32 i = 0; i < Struct->NumFields; ++i) {
+      Report("   #%2u: count = %llu\n", i, Struct->FieldCounters[i]);
+    }
+  } else {
+    for (u32 i = 0; i < Struct->NumFields; ++i) {
+      Report("   #%2u: offset = %u,\t size = %u,"
+             "\t count = %llu,\t type = %.*s\n",
+             i, Struct->FieldOffsets[i], Struct->FieldSize[i],
+             Struct->FieldCounters[i], TypePrintLimit, Struct->FieldTypeNames[i]);
+    }
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22020.62795.patch
Type: text/x-patch
Size: 4570 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160705/a884128a/attachment.bin>


More information about the llvm-commits mailing list