]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/CodeGen/address-sanitizer-and-array-cookie.cpp
Vendor import of clang trunk r338150:
[FreeBSD/FreeBSD.git] / test / CodeGen / address-sanitizer-and-array-cookie.cpp
1 // RUN: %clang_cc1 -triple x86_64-gnu-linux -emit-llvm -o - %s | FileCheck %s -check-prefix=PLAIN
2 // RUN: %clang_cc1 -triple x86_64-gnu-linux -emit-llvm -o - -fsanitize=address %s | FileCheck %s -check-prefix=ASAN
3 // RUN: %clang_cc1 -triple x86_64-gnu-linux -emit-llvm -o - -fsanitize=address -fsanitize-address-poison-class-member-array-new-cookie %s | FileCheck %s -check-prefix=ASAN-POISON-ALL-NEW-ARRAY
4
5 typedef __typeof__(sizeof(0)) size_t;
6 namespace std {
7   struct nothrow_t {};
8   std::nothrow_t nothrow;
9 }
10 void *operator new[](size_t, const std::nothrow_t &) throw();
11 void *operator new[](size_t, char *);
12 void *operator new[](size_t, int, int);
13
14 struct C {
15   int x;
16   ~C();
17 };
18
19 C *CallNew() {
20   return new C[10];
21 }
22 // PLAIN-LABEL: CallNew
23 // PLAIN-NOT: nosanitize
24 // PLAIN-NOT: __asan_poison_cxx_array_cookie
25 // ASAN-LABEL: CallNew
26 // ASAN: store{{.*}}nosanitize
27 // ASAN-NOT: nosanitize
28 // ASAN: call void @__asan_poison_cxx_array_cookie
29
30 C *CallNewNoThrow() {
31   return new (std::nothrow) C[10];
32 }
33 // PLAIN-LABEL: CallNewNoThrow
34 // PLAIN-NOT: nosanitize
35 // PLAIN-NOT: __asan_poison_cxx_array_cookie
36 // ASAN-LABEL: CallNewNoThrow
37 // ASAN: store{{.*}}nosanitize
38 // ASAN-NOT: nosanitize
39 // ASAN: call void @__asan_poison_cxx_array_cookie
40
41 void CallDelete(C *c) {
42   delete [] c;
43 }
44
45 // PLAIN-LABEL: CallDelete
46 // PLAIN-NOT: nosanitize
47 // ASAN-LABEL: CallDelete
48 // ASAN-NOT: nosanitize
49 // ASAN: call i64 @__asan_load_cxx_array_cookie
50 // ASAN-NOT: nosanitize
51
52 char Buffer[20];
53 C *CallPlacementNew() {
54   return new (Buffer) C[20];
55 }
56 // ASAN-LABEL: CallPlacementNew
57 // ASAN-NOT: __asan_poison_cxx_array_cookie
58
59 C *CallNewWithArgs() {
60 // ASAN-LABEL: CallNewWithArgs
61 // ASAN-NOT: call void @__asan_poison_cxx_array_cookie
62 // ASAN-POISON-ALL-NEW-ARRAY: call void @__asan_poison_cxx_array_cookie
63   return new (123, 456) C[20];
64 }