| 1 |
// Test optimization pipelines do not interfere with AllocToken lowering, and we |
| 2 |
// pass on function attributes correctly. |
| 3 |
// |
| 4 |
// RUN: %clang_cc1 -fsanitize=alloc-token -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,DEFAULT |
| 5 |
// RUN: %clang_cc1 -O1 -fsanitize=alloc-token -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,DEFAULT |
| 6 |
// RUN: %clang_cc1 -O2 -fsanitize=alloc-token -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,DEFAULT |
| 7 |
// RUN: %clang_cc1 -fsanitize=alloc-token -fsanitize-alloc-token-fast-abi -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,FASTABI |
| 8 |
// RUN: %clang_cc1 -O1 -fsanitize=alloc-token -fsanitize-alloc-token-fast-abi -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,FASTABI |
| 9 |
// RUN: %clang_cc1 -O2 -fsanitize=alloc-token -fsanitize-alloc-token-fast-abi -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,FASTABI |
| 10 |
|
| 11 |
typedef __typeof(sizeof(int)) size_t; |
| 12 |
|
| 13 |
void *malloc(size_t size); |
| 14 |
|
| 15 |
// CHECK-LABEL: @test_malloc( |
| 16 |
// DEFAULT: call{{.*}} ptr @__alloc_token_malloc(i64 noundef 4, i64 2689373973731826898){{.*}} !alloc_token [[META_INT:![0-9]+]] |
| 17 |
// FASTABI: call{{.*}} ptr @__alloc_token_2689373973731826898_malloc(i64 noundef 4){{.*}} !alloc_token [[META_INT:![0-9]+]] |
| 18 |
void *test_malloc() { |
| 19 |
return malloc(sizeof(int)); |
| 20 |
} |
| 21 |
|
| 22 |
// CHECK-LABEL: @no_sanitize_malloc( |
| 23 |
// CHECK: call{{.*}} ptr @malloc(i64 noundef 4) |
| 24 |
void *no_sanitize_malloc(size_t size) __attribute__((no_sanitize("alloc-token"))) { |
| 25 |
return malloc(sizeof(int)); |
| 26 |
} |
| 27 |
|
| 28 |
// By default, we should not be touching malloc-attributed non-libcall |
| 29 |
// functions: there might be an arbitrary number of these, and a compatible |
| 30 |
// allocator will only implement standard allocation functions. |
| 31 |
void *nonstandard_malloc(size_t size) __attribute__((malloc)); |
| 32 |
// CHECK-LABEL: @test_nonlibcall_malloc( |
| 33 |
// CHECK-NOT: __alloc_token_ |
| 34 |
// CHECK: call{{.*}} ptr @nonstandard_malloc(i64 noundef 4){{.*}} !alloc_token [[META_INT]] |
| 35 |
void *test_nonlibcall_malloc() { |
| 36 |
return nonstandard_malloc(sizeof(int)); |
| 37 |
} |
| 38 |
|
| 39 |
// CHECK: [[META_INT]] = !{!"int", i1 false} |