]> git.proxmox.com Git - rustc.git/blob - src/libcompiler_builtins/compiler-rt/test/asan/TestCases/Darwin/scribble.cc
New upstream version 1.28.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / test / asan / TestCases / Darwin / scribble.cc
1 // RUN: %clang_asan -O2 %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck --check-prefix=CHECK-NOSCRIBBLE %s
3 // RUN: %env MallocScribble=1 MallocPreScribble=1 %run %t 2>&1 | FileCheck --check-prefix=CHECK-SCRIBBLE %s
4 // RUN: %env_asan_opts=max_free_fill_size=4096 %run %t 2>&1 | FileCheck --check-prefix=CHECK-SCRIBBLE %s
5
6 #include <stdint.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 struct Isa {
12 const char *class_name;
13 };
14
15 struct MyClass {
16 long padding;
17 Isa *isa;
18 long data;
19
20 void print_my_class_name();
21 };
22
23 __attribute__((no_sanitize("address")))
24 void MyClass::print_my_class_name() {
25 fprintf(stderr, "this = %p\n", this);
26 fprintf(stderr, "padding = 0x%lx\n", this->padding);
27 fprintf(stderr, "isa = %p\n", this->isa);
28
29 if ((uint32_t)(uintptr_t)this->isa != 0x55555555) {
30 fprintf(stderr, "class name: %s\n", this->isa->class_name);
31 }
32 }
33
34 int main() {
35 Isa *my_class_isa = (Isa *)malloc(sizeof(Isa));
36 memset(my_class_isa, 0x77, sizeof(Isa));
37 my_class_isa->class_name = "MyClass";
38
39 MyClass *my_object = (MyClass *)malloc(sizeof(MyClass));
40 memset(my_object, 0x88, sizeof(MyClass));
41 my_object->isa = my_class_isa;
42 my_object->data = 42;
43
44 my_object->print_my_class_name();
45 // CHECK-SCRIBBLE: class name: MyClass
46 // CHECK-NOSCRIBBLE: class name: MyClass
47
48 free(my_object);
49
50 my_object->print_my_class_name();
51 // CHECK-NOSCRIBBLE: class name: MyClass
52 // CHECK-SCRIBBLE: isa = {{(0x)?}}{{5555555555555555|55555555}}
53
54 fprintf(stderr, "okthxbai!\n");
55 // CHECK-SCRIBBLE: okthxbai!
56 // CHECK-NOSCRIBBLE: okthxbai!
57 free(my_class_isa);
58 }