-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[TySan] Add option to outline instrumentation #120582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gbMattN
merged 10 commits into
llvm:main
from
gbMattN:users/nagym/tysan-reduce-inlining
Oct 31, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
462e384
[TySan] Add option to outline instrumentation
812589c
[style] fixed the code style
gbMattN a2260ee
No longer print incorrect stack traces
gbMattN 2b8d9ea
Fix formatting
gbMattN aa2cbfe
Run instrumentation function twice if verification requested
gbMattN d47bbc0
Fixed opt tests
gbMattN f446595
Formatting
gbMattN bc12aed
Add test files and changes from review
gbMattN 63776bb
format new test
gbMattN ae5e495
spelling mistake
gbMattN File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // RUN: %clang_tysan -mllvm -tysan-outline-instrumentation=true -mllvm -tysan-verify-outlined-instrumentation=true %s -o %t && %run %t >%t.out.0 2>&1 | ||
| // RUN: FileCheck %s < %t.out.0 | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| void printInt(int *i) { printf("%d\n", *i); } | ||
|
|
||
| int main() { | ||
|
|
||
| float value = 5.0f; | ||
| printInt((int *)&value); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| // CHECK: ERROR: TypeSanitizer: type-aliasing-violation | ||
| // CHECK-NEXT: READ of size 4 at {{.*}} with type int accesses an existing object of type float | ||
| // CHECK-NEXT: {{#0 0x.* in printInt}} | ||
| // CHECK-EMPTY: | ||
| // CHECK-NEXT: ERROR: TypeSanitizer: type-aliasing-violation | ||
| // CHECK-NEXT: READ of size 4 at {{.*}} with type int accesses an existing object of type float | ||
| // CHECK-NEXT: {{#0 0x.* in printInt}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // RUN: %clang_tysan -mllvm -tysan-outline-instrumentation=true -O0 %s -o %t && %run %t >%t.out 2>&1 | ||
| // RUN: FileCheck %s < %t.out | ||
| // RUN: %clang_tysan -mllvm -tysan-outline-instrumentation=true -mllvm -tysan-verify-outlined-instrumentation=true -O0 %s -o %t && %run %t >%t.out 2>&1 | ||
| // RUN: FileCheck %s --check-prefixes='CHECK,CHECK-VERIFY' < %t.out | ||
|
|
||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
|
|
||
| struct X { | ||
| int i; | ||
| int j; | ||
| }; | ||
|
|
||
| int foo(struct X *p, struct X *q) { | ||
| q->j = 1; | ||
| p->i = 0; | ||
| // CHECK: ERROR: TypeSanitizer: type-aliasing-violation | ||
| // CHECK-NEXT: WRITE of size 4 at {{.*}} with type int (in X at offset 0) accesses an existing object of type int (in X at offset 4) | ||
| // CHECK-NEXT: {{#0 0x.* in foo .*struct-offset-outline.c:}}[[@LINE-3]] | ||
| // CHECK-VERIFY-EMPTY: | ||
| // CHECK-VERIFY-NEXT: ERROR: TypeSanitizer: type-aliasing-violation | ||
| // CHECK-VERIFY-NEXT: WRITE of size 4 at {{.*}} with type int (in X at offset 0) accesses an existing object of type int (in X at offset 4) | ||
| // CHECK-VERIFY-NEXT: {{#0 0x.* in foo .*struct-offset-outline.c:}}[[@LINE-7]] | ||
| return q->j; | ||
| } | ||
|
|
||
| int main() { | ||
| unsigned char *p = malloc(3 * sizeof(int)); | ||
| printf("%i\n", foo((struct X *)(p + sizeof(int)), (struct X *)p)); | ||
| } | ||
|
|
||
| // CHECK-NOT: ERROR: TypeSanitizer: type-aliasing-violation |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be an early exit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would skip the
else ifon line 374, so I don't think we can do that. If this is a major performance concern, I could split this into two RT functions sincesanitizeFunctionis known at compile time