-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[AllocToken, Clang] Infer type hints from sizeof expressions and casts #156841
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
base: users/melver/spr/main.alloctoken-clang-infer-type-hints-from-sizeof-expressions-and-casts
Are you sure you want to change the base?
Changes from all commits
a2e11fc
1bc3905
2ca9c72
465097f
f7d3204
4284a8a
fa5f672
ce655c3
ce53f3d
cb42dcf
bac3951
81d45c4
20b5a41
6f8d25b
45a77f2
90a394b
3fee412
adcaf3a
e533ccc
64b8cf9
3e49b6e
e613813
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ typedef __typeof(sizeof(int)) size_t; | |
void *malloc(size_t size); | ||
|
||
// CHECK-LABEL: @test_malloc( | ||
// CHECK: call{{.*}} ptr @__alloc_token_malloc(i64 noundef 4, i64 0) | ||
// CHECK: call{{.*}} ptr @__alloc_token_malloc(i64 noundef 4, i64 2689373973731826898){{.*}} !alloc_token [[META_INT:![0-9]+]] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Use a regex instead of hard-coding the token here and in alloc-token-nonlibcalls.c? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're using a stable hash, so this should always be the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just figured that at this level (Clang test), we don't care so much about the exact number, just that there is a number. LLVM tests can have expectations about the exact hash. But I don't feel particularly strongly about this. |
||
void *test_malloc() { | ||
return malloc(sizeof(int)); | ||
} | ||
|
@@ -20,3 +20,15 @@ void *test_malloc() { | |
void *no_sanitize_malloc(size_t size) __attribute__((no_sanitize("alloc-token"))) { | ||
return malloc(sizeof(int)); | ||
} | ||
|
||
// By default, we should not be touching malloc-attributed non-libcall | ||
// functions: there might be an arbitrary number of these, and a compatible | ||
// allocator will only implement standard allocation functions. | ||
void *nonstandard_malloc(size_t size) __attribute__((malloc)); | ||
// CHECK-LABEL: @test_nonlibcall_malloc( | ||
// CHECK: call{{.*}} ptr @nonstandard_malloc(i64 noundef 4){{.*}} !alloc_token [[META_INT]] | ||
void *test_nonlibcall_malloc() { | ||
return nonstandard_malloc(sizeof(int)); | ||
} | ||
|
||
// CHECK: [[META_INT]] = !{!"int", i1 false} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// RUN: %clang_cc1 -fsanitize=alloc-token -fsanitize-alloc-token-extended -triple x86_64-linux-gnu -emit-llvm -disable-llvm-passes %s -o - | FileCheck --check-prefixes=CHECK,CHECK-CODEGEN %s | ||
// RUN: %clang_cc1 -fsanitize=alloc-token -fsanitize-alloc-token-extended -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefixes=CHECK,CHECK-LOWER %s | ||
// RUN: %clang_cc1 -O -fsanitize=alloc-token -fsanitize-alloc-token-extended -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefixes=CHECK,CHECK-LOWER %s | ||
|
||
typedef __typeof(sizeof(int)) size_t; | ||
typedef size_t gfp_t; | ||
|
||
void *custom_malloc(size_t size) __attribute__((malloc)); | ||
void *__kmalloc(size_t size, gfp_t flags) __attribute__((alloc_size(1))); | ||
|
||
void *sink; | ||
|
||
// CHECK-LABEL: @test_nonlibcall_alloc( | ||
// CHECK-CODEGEN: call noalias ptr @custom_malloc(i64 noundef 4){{.*}} !alloc_token [[META_INT:![0-9]+]] | ||
// CHECK-CODEGEN: call ptr @__kmalloc(i64 noundef 4, i64 noundef 0){{.*}} !alloc_token [[META_INT]] | ||
// CHECK-LOWER: call{{.*}} noalias ptr @__alloc_token_custom_malloc(i64 noundef 4, i64 2689373973731826898){{.*}} !alloc_token [[META_INT:![0-9]+]] | ||
// CHECK-LOWER: call{{.*}} ptr @__alloc_token___kmalloc(i64 noundef 4, i64 noundef 0, i64 2689373973731826898){{.*}} !alloc_token [[META_INT]] | ||
void test_nonlibcall_alloc() { | ||
sink = custom_malloc(sizeof(int)); | ||
sink = __kmalloc(sizeof(int), 0); | ||
} | ||
|
||
// CHECK: [[META_INT]] = !{!"int", i1 false} |
Uh oh!
There was an error while loading. Please reload this page.