Skip to content

Commit 4d70fda

Browse files
committed
Removed false positive/segfault when accessing member of global for the first time
1 parent a08f79a commit 4d70fda

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

compiler-rt/lib/tysan/tysan.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,22 +227,26 @@ __tysan_check(void *addr, int size, tysan_type_descriptor *td, int flags) {
227227
int i = -((sptr)OldTD);
228228
OldTDPtr -= i;
229229
OldTD = *OldTDPtr;
230-
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.
230+
240231
tysan_type_descriptor *AccessedType = OldTD;
241-
if (OldTD->Tag == TYSAN_STRUCT_TD) {
242-
for (int j = 0; j < OldTD->Struct.MemberCount; ++j) {
243-
if (OldTD->Struct.Members[j].Offset == i) {
244-
AccessedType = OldTD->Struct.Members[j].Type;
245-
break;
232+
233+
// Only check if we are accessing members if the type exists
234+
if(OldTD != nullptr){
235+
// When shadow memory is set for global objects, the entire object is tagged
236+
// with the struct type This means that when you access a member variable,
237+
// tysan reads that as you accessing a struct midway through, with 'i' being
238+
// the offset Therefore, if you are accessing a struct, we need to find the
239+
// member type. We can go through the members of the struct type and see if
240+
// there is a member at the offset you are accessing the struct by. If there
241+
// is indeed a member starting at offset 'i' in the struct, we should check
242+
// aliasing legality with that type. If there isn't, we run alias checking
243+
// on the struct which will give us the correct error.
244+
if (OldTD->Tag == TYSAN_STRUCT_TD) {
245+
for (int j = 0; j < OldTD->Struct.MemberCount; ++j) {
246+
if (OldTD->Struct.Members[j].Offset == i) {
247+
AccessedType = OldTD->Struct.Members[j].Type;
248+
break;
249+
}
246250
}
247251
}
248252
}

0 commit comments

Comments
 (0)