Skip to content

Commit a4a7220

Browse files
committedJun 10, 2016
[esan|cfrag] Add the struct field offset array in StructInfo
Summary: Adds the struct field offset array in the struct StructInfo. Prints struct size and field offset info in the report. Reviewers: aizatsky Subscribers: vitalybuka, zhaoqin, kcc, eugenis, bruening, llvm-commits, kubabrecka Differential Revision: http://reviews.llvm.org/D21191 llvm-svn: 272363
1 parent 0b96aa7 commit a4a7220

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed
 

‎compiler-rt/lib/esan/cache_frag.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ namespace __esan {
2626
// This should be kept consistent with LLVM's EfficiencySanitizer StructInfo.
2727
struct StructInfo {
2828
const char *StructName;
29+
u32 Size;
2930
u32 NumFields;
31+
u32 *FieldOffsets;
3032
u64 *FieldCounters;
3133
const char **FieldTypeNames;
3234
};
@@ -89,9 +91,11 @@ static void reportStructCounter(StructHashMap::Handle &Handle) {
8991
end = strchr(start, '#');
9092
CHECK(end != nullptr);
9193
Report(" %s %.*s\n", type, end - start, start);
92-
Report(" count = %llu, ratio = %llu\n", Handle->Count, Handle->Ratio);
94+
Report(" size = %u, count = %llu, ratio = %llu\n",
95+
Struct->Size, Handle->Count, Handle->Ratio);
9396
for (u32 i = 0; i < Struct->NumFields; ++i) {
94-
Report(" #%2u: count = %llu,\t type = %s\n", i, Struct->FieldCounters[i],
97+
Report(" #%2u: offset = %u,\t count = %llu,\t type = %s\n", i,
98+
Struct->FieldOffsets[i], Struct->FieldCounters[i],
9599
Struct->FieldTypeNames[i]);
96100
}
97101
}

‎compiler-rt/test/esan/TestCases/struct-simple.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -142,48 +142,48 @@ int main(int argc, char **argv) {
142142
// CHECK-NEXT: in esan::processCacheFragCompilationUnitExit: {{.*}}struct-simple.cpp with 5 class(es)/struct(s)
143143
// CHECK-NEXT: Unregister class.C#3#14#13#13: 3 fields
144144
// CHECK-NEXT: {{.*}} class C
145-
// CHECK-NEXT: {{.*}} count = 5, ratio = 3
146-
// CHECK-NEXT: {{.*}} # 0: count = 2, type = %struct.anon = type { i32, i32 }
147-
// CHECK-NEXT: {{.*}} # 1: count = 2, type = %union.anon = type { double }
148-
// CHECK-NEXT: {{.*}} # 2: count = 1, type = [10 x i8]
145+
// CHECK-NEXT: {{.*}} size = 32, count = 5, ratio = 3
146+
// CHECK-NEXT: {{.*}} # 0: offset = 0, count = 2, type = %struct.anon = type { i32, i32 }
147+
// CHECK-NEXT: {{.*}} # 1: offset = 8, count = 2, type = %union.anon = type { double }
148+
// CHECK-NEXT: {{.*}} # 2: offset = 16, count = 1, type = [10 x i8]
149149
// CHECK-NEXT: Unregister struct.anon#2#11#11: 2 fields
150150
// CHECK-NEXT: {{.*}} struct anon
151-
// CHECK-NEXT: {{.*}} count = 2, ratio = 1
152-
// CHECK-NEXT: {{.*}} # 0: count = 1, type = i32
153-
// CHECK-NEXT: {{.*}} # 1: count = 1, type = i32
151+
// CHECK-NEXT: {{.*}} size = 8, count = 2, ratio = 1
152+
// CHECK-NEXT: {{.*}} # 0: offset = 0, count = 1, type = i32
153+
// CHECK-NEXT: {{.*}} # 1: offset = 4, count = 1, type = i32
154154
// CHECK-NEXT: Unregister union.anon#1#3: 1 fields
155155
// CHECK-NEXT: Unregister struct.S#2#11#11: 2 fields
156156
// CHECK-NEXT: {{.*}} struct S
157-
// CHECK-NEXT: {{.*}} count = 2, ratio = 2
158-
// CHECK-NEXT: {{.*}} # 0: count = 2, type = i32
159-
// CHECK-NEXT: {{.*}} # 1: count = 0, type = i32
157+
// CHECK-NEXT: {{.*}} size = 8, count = 2, ratio = 2
158+
// CHECK-NEXT: {{.*}} # 0: offset = 0, count = 2, type = i32
159+
// CHECK-NEXT: {{.*}} # 1: offset = 4, count = 0, type = i32
160160
// CHECK-NEXT: Unregister struct.D#3#11#11#11: 3 fields
161161
// CHECK-NEXT: {{.*}} struct D
162-
// CHECK-NEXT: {{.*}} count = 2, ratio = 2
163-
// CHECK-NEXT: {{.*}} # 0: count = 1, type = i32
164-
// CHECK-NEXT: {{.*}} # 1: count = 1, type = i32
165-
// CHECK-NEXT: {{.*}} # 2: count = 0, type = i32
162+
// CHECK-NEXT: {{.*}} size = 12, count = 2, ratio = 2
163+
// CHECK-NEXT: {{.*}} # 0: offset = 0, count = 1, type = i32
164+
// CHECK-NEXT: {{.*}} # 1: offset = 4, count = 1, type = i32
165+
// CHECK-NEXT: {{.*}} # 2: offset = 8, count = 0, type = i32
166166
// CHECK-NEXT: in esan::processCompilationUnitExit
167167
// CHECK-NEXT: in esan::processCacheFragCompilationUnitExit: {{.*}}struct-simple.cpp with 0 class(es)/struct(s)
168168
// CHECK-NEXT: in esan::processCompilationUnitExit
169169
// CHECK-NEXT: in esan::processCacheFragCompilationUnitExit: {{.*}}struct-simple.cpp with 5 class(es)/struct(s)
170170
// CHECK-NEXT: Unregister struct.A#2#11#11: 2 fields
171171
// CHECK-NEXT: {{.*}} struct A
172-
// CHECK-NEXT: {{.*}} count = 2049, ratio = 2048
173-
// CHECK-NEXT: {{.*}} # 0: count = 2048, type = i32
174-
// CHECK-NEXT: {{.*}} # 1: count = 1, type = i32
172+
// CHECK-NEXT: {{.*}} size = 8, count = 2049, ratio = 2048
173+
// CHECK-NEXT: {{.*}} # 0: offset = 0, count = 2048, type = i32
174+
// CHECK-NEXT: {{.*}} # 1: offset = 4, count = 1, type = i32
175175
// CHECK-NEXT: Unregister struct.B#2#3#2: 2 fields
176176
// CHECK-NEXT: {{.*}} struct B
177-
// CHECK-NEXT: {{.*}} count = 2097153, ratio = 2097152
178-
// CHECK-NEXT: {{.*}} # 0: count = 1, type = float
179-
// CHECK-NEXT: {{.*}} # 1: count = 2097152, type = double
177+
// CHECK-NEXT: {{.*}} size = 16, count = 2097153, ratio = 2097152
178+
// CHECK-NEXT: {{.*}} # 0: offset = 0, count = 1, type = float
179+
// CHECK-NEXT: {{.*}} # 1: offset = 8, count = 2097152, type = double
180180
// CHECK-NEXT: Unregister union.U#1#3: 1 fields
181181
// CHECK-NEXT: Duplicated struct.S#2#11#11: 2 fields
182182
// CHECK-NEXT: Unregister struct.D#2#11#11: 2 fields
183183
// CHECK-NEXT: {{.*}} struct D
184-
// CHECK-NEXT: {{.*}} count = 1, ratio = 1
185-
// CHECK-NEXT: {{.*}} # 0: count = 1, type = i32
186-
// CHECK-NEXT: {{.*}} # 1: count = 0, type = i32
184+
// CHECK-NEXT: {{.*}} size = 8, count = 1, ratio = 1
185+
// CHECK-NEXT: {{.*}} # 0: offset = 0, count = 1, type = i32
186+
// CHECK-NEXT: {{.*}} # 1: offset = 4, count = 0, type = i32
187187
// CHECK-NEXT: {{.*}}EfficiencySanitizer: total struct field access count = 2099214
188188
}
189189
#endif // MAIN

0 commit comments

Comments
 (0)
Please sign in to comment.