-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[AllocToken, Clang] Implement TypeHashPointerSplit mode #156840
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
Open
melver
wants to merge
22
commits into
users/melver/spr/main.alloctoken-clang-implement-typehashpointersplit-mode
Choose a base branch
from
users/melver/spr/alloctoken-clang-implement-typehashpointersplit-mode
base: users/melver/spr/main.alloctoken-clang-implement-typehashpointersplit-mode
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b689546
[𝘀𝗽𝗿] initial version
melver cb3d52d
fixup! Insert AllocToken into index.rst
melver 33d18b2
fixup! Switch to fixed MD
melver 14c7544
fixup! fix for incomplete types
melver 7f70661
fixup!
melver 1358f5a
fixup! address reviewer comments
melver 3b64919
fixup! address reviewer comments round 2
melver b0e9549
fixup! use update_test_checks.py for opt tests
melver ebab546
fixup! do not strip _
melver fb160db
fixup! address some comments
melver 8281324
fixup! address more comments
melver 2fa07d7
rebase
melver 9979bca
fixup! address comments
melver ca51a2b
fixup!
melver 0cebd94
fixup! switch clang tests back to manually written
melver fecfe67
rebase
melver fa2bb2c
rebase
melver 6f6aa54
rebase
melver 6ed5fe6
rebase
melver 346e06d
rebase
melver 45fb47d
rebase
melver 6225eb5
rebase
melver 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
Some comments aren't visible on the classic Files Changed page.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
// Check -fsanitize=alloc-token TypeHashPointerSplit mode with only 2 | ||
// tokens so we effectively only test the contains-pointer logic. | ||
// | ||
// RUN: %clang_cc1 -fsanitize=alloc-token -falloc-token-max=2 -triple x86_64-linux-gnu -std=c++20 -emit-llvm %s -o - | FileCheck %s | ||
// RUN: %clang_cc1 -O -fsanitize=alloc-token -falloc-token-max=2 -triple x86_64-linux-gnu -std=c++20 -emit-llvm %s -o - | FileCheck %s | ||
|
||
#include "../Analysis/Inputs/system-header-simulator-cxx.h" | ||
|
||
typedef __UINTPTR_TYPE__ uintptr_t; | ||
|
||
extern "C" { | ||
void *malloc(size_t size); | ||
} | ||
|
||
// CHECK-LABEL: @_Z15test_malloc_intv( | ||
void *test_malloc_int() { | ||
// CHECK: call{{.*}} ptr @__alloc_token_malloc(i64 noundef 4, i64 0) | ||
melver marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
int *a = (int *)malloc(sizeof(int)); | ||
*a = 42; | ||
return a; | ||
} | ||
|
||
// CHECK-LABEL: @_Z15test_malloc_ptrv( | ||
int **test_malloc_ptr() { | ||
// FIXME: This should not be token ID 0! | ||
// CHECK: call{{.*}} ptr @__alloc_token_malloc(i64 noundef 8, i64 0) | ||
int **a = (int **)malloc(sizeof(int*)); | ||
*a = nullptr; | ||
return a; | ||
} | ||
|
||
// CHECK-LABEL: @_Z12test_new_intv( | ||
int *test_new_int() { | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 4, i64 0){{.*}} !alloc_token_hint | ||
return new int; | ||
} | ||
|
||
// CHECK-LABEL: @_Z20test_new_ulong_arrayv( | ||
unsigned long *test_new_ulong_array() { | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znam(i64 noundef 80, i64 0){{.*}} !alloc_token_hint | ||
return new unsigned long[10]; | ||
} | ||
|
||
// CHECK-LABEL: @_Z12test_new_ptrv( | ||
int **test_new_ptr() { | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 8, i64 1){{.*}} !alloc_token_hint | ||
return new int*; | ||
} | ||
|
||
// CHECK-LABEL: @_Z18test_new_ptr_arrayv( | ||
int **test_new_ptr_array() { | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znam(i64 noundef 80, i64 1){{.*}} !alloc_token_hint | ||
return new int*[10]; | ||
} | ||
|
||
struct ContainsPtr { | ||
int a; | ||
char *buf; | ||
}; | ||
|
||
// CHECK-LABEL: @_Z27test_malloc_struct_with_ptrv( | ||
ContainsPtr *test_malloc_struct_with_ptr() { | ||
// FIXME: This should not be token ID 0! | ||
// CHECK: call{{.*}} ptr @__alloc_token_malloc(i64 noundef 16, i64 0) | ||
ContainsPtr *c = (ContainsPtr *)malloc(sizeof(ContainsPtr)); | ||
return c; | ||
} | ||
|
||
// CHECK-LABEL: @_Z33test_malloc_struct_array_with_ptrv( | ||
ContainsPtr *test_malloc_struct_array_with_ptr() { | ||
// FIXME: This should not be token ID 0! | ||
// CHECK: call{{.*}} ptr @__alloc_token_malloc(i64 noundef 160, i64 0) | ||
ContainsPtr *c = (ContainsPtr *)malloc(10 * sizeof(ContainsPtr)); | ||
return c; | ||
} | ||
|
||
// CHECK-LABEL: @_Z32test_operatornew_struct_with_ptrv( | ||
ContainsPtr *test_operatornew_struct_with_ptr() { | ||
// FIXME: This should not be token ID 0! | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 16, i64 0) | ||
ContainsPtr *c = (ContainsPtr *)__builtin_operator_new(sizeof(ContainsPtr)); | ||
return c; | ||
} | ||
|
||
// CHECK-LABEL: @_Z38test_operatornew_struct_array_with_ptrv( | ||
ContainsPtr *test_operatornew_struct_array_with_ptr() { | ||
// FIXME: This should not be token ID 0! | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 160, i64 0) | ||
ContainsPtr *c = (ContainsPtr *)__builtin_operator_new(10 * sizeof(ContainsPtr)); | ||
return c; | ||
} | ||
|
||
// CHECK-LABEL: @_Z33test_operatornew_struct_with_ptr2v( | ||
ContainsPtr *test_operatornew_struct_with_ptr2() { | ||
// FIXME: This should not be token ID 0! | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 16, i64 0) | ||
ContainsPtr *c = (ContainsPtr *)__builtin_operator_new(sizeof(*c)); | ||
return c; | ||
} | ||
|
||
// CHECK-LABEL: @_Z39test_operatornew_struct_array_with_ptr2v( | ||
ContainsPtr *test_operatornew_struct_array_with_ptr2() { | ||
// FIXME: This should not be token ID 0! | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 160, i64 0) | ||
ContainsPtr *c = (ContainsPtr *)__builtin_operator_new(10 * sizeof(*c)); | ||
return c; | ||
} | ||
|
||
// CHECK-LABEL: @_Z24test_new_struct_with_ptrv( | ||
ContainsPtr *test_new_struct_with_ptr() { | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 16, i64 1){{.*}} !alloc_token_hint | ||
return new ContainsPtr; | ||
} | ||
|
||
// CHECK-LABEL: @_Z30test_new_struct_array_with_ptrv( | ||
ContainsPtr *test_new_struct_array_with_ptr() { | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znam(i64 noundef 160, i64 1){{.*}} !alloc_token_hint | ||
return new ContainsPtr[10]; | ||
} | ||
|
||
class TestClass { | ||
public: | ||
void Foo(); | ||
~TestClass(); | ||
int data[16]; | ||
}; | ||
|
||
// CHECK-LABEL: @_Z14test_new_classv( | ||
TestClass *test_new_class() { | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 64, i64 0){{.*}} !alloc_token_hint | ||
return new TestClass(); | ||
} | ||
|
||
// CHECK-LABEL: @_Z20test_new_class_arrayv( | ||
TestClass *test_new_class_array() { | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znam(i64 noundef 648, i64 0){{.*}} !alloc_token_hint | ||
return new TestClass[10]; | ||
} | ||
|
||
// Test that we detect that virtual classes have implicit vtable pointer. | ||
class VirtualTestClass { | ||
public: | ||
virtual void Foo(); | ||
virtual ~VirtualTestClass(); | ||
int data[16]; | ||
}; | ||
|
||
// CHECK-LABEL: @_Z22test_new_virtual_classv( | ||
VirtualTestClass *test_new_virtual_class() { | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 72, i64 1){{.*}} !alloc_token_hint | ||
return new VirtualTestClass(); | ||
} | ||
|
||
// CHECK-LABEL: @_Z28test_new_virtual_class_arrayv( | ||
VirtualTestClass *test_new_virtual_class_array() { | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znam(i64 noundef 728, i64 1){{.*}} !alloc_token_hint | ||
return new VirtualTestClass[10]; | ||
} | ||
|
||
// uintptr_t is treated as a pointer. | ||
struct MyStructUintptr { | ||
int a; | ||
uintptr_t ptr; | ||
}; | ||
|
||
// CHECK-LABEL: @_Z18test_uintptr_isptrv( | ||
MyStructUintptr *test_uintptr_isptr() { | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 16, i64 1) | ||
return new MyStructUintptr; | ||
} | ||
|
||
using uptr = uintptr_t; | ||
// CHECK-LABEL: @_Z19test_uintptr_isptr2v( | ||
uptr *test_uintptr_isptr2() { | ||
// CHECK: call {{.*}} ptr @__alloc_token_Znwm(i64 noundef 8, i64 1) | ||
return new uptr; | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.