[llvm-branch-commits] [compiler-rt] [TySan] Fixed false positive when accessing offset member variables (PR #95387)
Jeremy Morse via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Mon Nov 11 09:49:54 PST 2024
================
@@ -221,7 +221,24 @@ __tysan_check(void *addr, int size, tysan_type_descriptor *td, int flags) {
OldTDPtr -= i;
OldTD = *OldTDPtr;
- if (!isAliasingLegal(td, OldTD))
+ // When shadow memory is set for global objects, the entire object is tagged with the struct type
+ // This means that when you access a member variable, tysan reads that as you accessing a struct midway
+ // through, with 'i' being the offset
+ // Therefore, if you are accessing a struct, we need to find the member type. We can go through the
+ // members of the struct type and see if there is a member at the offset you are accessing the struct by.
+ // If there is indeed a member starting at offset 'i' in the struct, we should check aliasing legality
+ // with that type. If there isn't, we run alias checking on the struct with will give us the correct error.
+ tysan_type_descriptor *InternalMember = OldTD;
+ if (OldTD->Tag == TYSAN_STRUCT_TD) {
+ for (int j = 0; j < OldTD->Struct.MemberCount; j++) {
----------------
jmorse wrote:
Style guide says `++j`
https://github.com/llvm/llvm-project/pull/95387
More information about the llvm-branch-commits
mailing list