Skip to content

Commit 65f1e1f

Browse files
author
Matthew Nagy
committed
[TySan] Fix struct access with different bases
1 parent 733b3ed commit 65f1e1f

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

compiler-rt/lib/tysan/tysan.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ static bool isAliasingLegalUp(tysan_type_descriptor *TDA,
128128
break;
129129
}
130130

131+
//You can't have negative offset, you must be partially inside the last type
132+
if (TDA->Struct.Members[Idx].Offset > OffsetA)
133+
Idx -=1;
134+
131135
OffsetA -= TDA->Struct.Members[Idx].Offset;
132136
TDA = TDA->Struct.Members[Idx].Type;
133137
} else {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %clangxx_tysan -O0 %s -o %t && %run %t >%t.out 2>&1
2+
// RUN: FileCheck %s < %t.out
3+
4+
#include <stdio.h>
5+
6+
struct inner {
7+
char buffer;
8+
int i;
9+
};
10+
11+
void init_inner(inner *iPtr) {
12+
iPtr->i = 0;
13+
}
14+
15+
struct outer {
16+
inner foo;
17+
char buffer;
18+
};
19+
20+
int main(void) {
21+
outer *l = new outer();
22+
23+
init_inner(&l->foo);
24+
25+
int access_offsets_with_different_base = l->foo.i;
26+
printf("%d\n", access_offsets_with_different_base);
27+
28+
return 0;
29+
}
30+
31+
// CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation

0 commit comments

Comments
 (0)