Skip to content

Commit a08f79a

Browse files
committed
[style] Tidied up comments, formatting, and polished test
1 parent 579f4bd commit a08f79a

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

compiler-rt/lib/tysan/tysan.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,24 +228,26 @@ __tysan_check(void *addr, int size, tysan_type_descriptor *td, int flags) {
228228
OldTDPtr -= i;
229229
OldTD = *OldTDPtr;
230230

231-
// When shadow memory is set for global objects, the entire object is tagged with the struct type
232-
// This means that when you access a member variable, tysan reads that as you accessing a struct midway
233-
// through, with 'i' being the offset
234-
// Therefore, if you are accessing a struct, we need to find the member type. We can go through the
235-
// members of the struct type and see if there is a member at the offset you are accessing the struct by.
236-
// If there is indeed a member starting at offset 'i' in the struct, we should check aliasing legality
237-
// with that type. If there isn't, we run alias checking on the struct with will give us the correct error.
238-
tysan_type_descriptor *InternalMember = OldTD;
231+
// When shadow memory is set for global objects, the entire object is tagged
232+
// with the struct type This means that when you access a member variable,
233+
// tysan reads that as you accessing a struct midway through, with 'i' being
234+
// the offset Therefore, if you are accessing a struct, we need to find the
235+
// member type. We can go through the members of the struct type and see if
236+
// there is a member at the offset you are accessing the struct by. If there
237+
// is indeed a member starting at offset 'i' in the struct, we should check
238+
// aliasing legality with that type. If there isn't, we run alias checking
239+
// on the struct which will give us the correct error.
240+
tysan_type_descriptor *AccessedType = OldTD;
239241
if (OldTD->Tag == TYSAN_STRUCT_TD) {
240-
for (int j = 0; j < OldTD->Struct.MemberCount; j++) {
242+
for (int j = 0; j < OldTD->Struct.MemberCount; ++j) {
241243
if (OldTD->Struct.Members[j].Offset == i) {
242-
InternalMember = OldTD->Struct.Members[j].Type;
244+
AccessedType = OldTD->Struct.Members[j].Type;
243245
break;
244246
}
245247
}
246248
}
247249

248-
if (!isAliasingLegal(td, InternalMember, i))
250+
if (!isAliasingLegal(td, AccessedType, i))
249251
reportError(addr, size, td, OldTD, AccessStr,
250252
"accesses part of an existing object", -i, pc, bp, sp);
251253

compiler-rt/test/tysan/global-struct-members.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_tysan -O0 %s -o %t && %run %t >%t.out 2>&1
2-
// RUN: FileCheck %s < %t.out
2+
// RUN: FileCheck %s --implicit-check-not ERROR < %t.out
33

44
#include <stdio.h>
55

@@ -15,7 +15,6 @@ int main() {
1515
x.c = 3;
1616

1717
printf("%d %d %d\n", x.a, x.b, x.c);
18-
// CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation
1918

2019
for (size_t i = 0; i < 2; i++) {
2120
xArray[i].a = 1;
@@ -26,6 +25,6 @@ int main() {
2625
struct X *xPtr = (struct X *)&(xArray[0].c);
2726
xPtr->a = 1;
2827
// CHECK: ERROR: TypeSanitizer: type-aliasing-violation
29-
// CHECK: WRITE of size 4 at {{.*}} with type int (in X at offset 0) accesses an existing object of type int (in X at offset 8)
30-
// CHECK: {{#0 0x.* in main .*struct-members.c:}}[[@LINE-3]]
28+
// CHECK-NEXT: WRITE of size 4 at {{.*}} with type int (in X at offset 0) accesses an existing object of type int (in X at offset 8)
29+
// CHECK-NEXT: #0 0x{{.*}} in main {{.*}}struct-members.c:[[@LINE-3]]
3130
}

0 commit comments

Comments
 (0)