Skip to content

Commit 11e21b7

Browse files
committed
Added comments to explain why we treat offsets in shadow memory opposite te to other accesses
1 parent 0f309d6 commit 11e21b7

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

compiler-rt/lib/tysan/tysan.cpp

+16-10
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ static tysan_type_descriptor *getRootTD(tysan_type_descriptor *TD) {
102102
return RootTD;
103103
}
104104

105+
// Walk up TDA to see if it reaches TDB
105106
bool walkAliasTree(tysan_type_descriptor *TDA, tysan_type_descriptor *TDB,
106107
uptr OffsetA, uptr OffsetB) {
107108
do {
@@ -158,24 +159,29 @@ static bool isAliasingLegalUp(tysan_type_descriptor *TDA,
158159
return walkAliasTree(TDA, TDB, OffsetA, OffsetB);
159160
}
160161

161-
static bool isAliasingLegalWithOffset(tysan_type_descriptor *AccessTD,
162-
tysan_type_descriptor *ShadowTD,
163-
int OffsetInShadow) {
162+
static bool isAliasingLegalWithOffset(tysan_type_descriptor *TDA,
163+
tysan_type_descriptor *TDB,
164+
int OffsetB) {
164165
// This is handled in the other cases
165-
if (OffsetInShadow == 0)
166+
if (OffsetB == 0)
166167
return false;
167168

168169
// You can't have an offset into a member
169-
if (ShadowTD->Tag == TYSAN_MEMBER_TD)
170+
if (TDB->Tag == TYSAN_MEMBER_TD)
170171
return false;
171172

172-
int OffsetInAccess = 0;
173-
if (AccessTD->Tag == TYSAN_MEMBER_TD) {
174-
OffsetInAccess = AccessTD->Member.Offset;
175-
AccessTD = AccessTD->Member.Base;
173+
int OffsetA = 0;
174+
if (TDA->Tag == TYSAN_MEMBER_TD) {
175+
OffsetA = TDA->Member.Offset;
176+
TDA = TDA->Member.Base;
176177
}
177178

178-
return walkAliasTree(ShadowTD, AccessTD, OffsetInShadow, OffsetInAccess);
179+
// Since the access was partially inside TDB (the shadow), it can be assumed
180+
// that we are accessing a member in an object. This means that rather than
181+
// walk up the scalar access TDA to reach an object, we should walk up the
182+
// object TBD to reach the scalar we are accessing it with. The offsets will
183+
// still be checked at the end to make sure this alias is legal.
184+
return walkAliasTree(TDB, TDA, OffsetB, OffsetA);
179185
}
180186

181187
static bool isAliasingLegal(tysan_type_descriptor *TDA,

0 commit comments

Comments
 (0)