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