@@ -221,7 +221,24 @@ __tysan_check(void *addr, int size, tysan_type_descriptor *td, int flags) {
221
221
OldTDPtr -= i;
222
222
OldTD = *OldTDPtr;
223
223
224
- if (!isAliasingLegal (td, OldTD))
224
+ // When shadow memory is set for global objects, the entire object is tagged with the struct type
225
+ // This means that when you access a member variable, tysan reads that as you accessing a struct midway
226
+ // through, with 'i' being the offset
227
+ // Therefore, if you are accessing a struct, we need to find the member type. We can go through the
228
+ // members of the struct type and see if there is a member at the offset you are accessing the struct by.
229
+ // If there is indeed a member starting at offset 'i' in the struct, we should check aliasing legality
230
+ // with that type. If there isn't, we run alias checking on the struct with will give us the correct error.
231
+ tysan_type_descriptor *InternalMember = OldTD;
232
+ if (OldTD->Tag == TYSAN_STRUCT_TD) {
233
+ for (int j = 0 ; j < OldTD->Struct .MemberCount ; j++) {
234
+ if (OldTD->Struct .Members [j].Offset == i) {
235
+ InternalMember = OldTD->Struct .Members [j].Type ;
236
+ break ;
237
+ }
238
+ }
239
+ }
240
+
241
+ if (!isAliasingLegal (td, InternalMember))
225
242
reportError (addr, size, td, OldTD, AccessStr,
226
243
" accesses part of an existing object" , -i, pc, bp, sp);
227
244
0 commit comments