xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/address-sanitizer-and-array-cookie.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-gnu-linux -emit-llvm -o - %s | FileCheck %s -check-prefix=PLAIN
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-gnu-linux -emit-llvm -o - -fsanitize=address %s | FileCheck %s -check-prefix=ASAN
3*0a6a1f1dSLionel Sambuc 
4*0a6a1f1dSLionel Sambuc typedef __typeof__(sizeof(0)) size_t;
5*0a6a1f1dSLionel Sambuc namespace std {
6*0a6a1f1dSLionel Sambuc   struct nothrow_t {};
7*0a6a1f1dSLionel Sambuc   std::nothrow_t nothrow;
8*0a6a1f1dSLionel Sambuc }
9*0a6a1f1dSLionel Sambuc void *operator new[](size_t, const std::nothrow_t &) throw();
10*0a6a1f1dSLionel Sambuc void *operator new[](size_t, char *);
11*0a6a1f1dSLionel Sambuc 
12*0a6a1f1dSLionel Sambuc struct C {
13*0a6a1f1dSLionel Sambuc   int x;
14*0a6a1f1dSLionel Sambuc   ~C();
15*0a6a1f1dSLionel Sambuc };
16*0a6a1f1dSLionel Sambuc 
CallNew()17*0a6a1f1dSLionel Sambuc C *CallNew() {
18*0a6a1f1dSLionel Sambuc   return new C[10];
19*0a6a1f1dSLionel Sambuc }
20*0a6a1f1dSLionel Sambuc // PLAIN-LABEL: CallNew
21*0a6a1f1dSLionel Sambuc // PLAIN-NOT: nosanitize
22*0a6a1f1dSLionel Sambuc // PLAIN-NOT: __asan_poison_cxx_array_cookie
23*0a6a1f1dSLionel Sambuc // ASAN-LABEL: CallNew
24*0a6a1f1dSLionel Sambuc // ASAN: store{{.*}}nosanitize
25*0a6a1f1dSLionel Sambuc // ASAN-NOT: nosanitize
26*0a6a1f1dSLionel Sambuc // ASAN: call void @__asan_poison_cxx_array_cookie
27*0a6a1f1dSLionel Sambuc 
CallNewNoThrow()28*0a6a1f1dSLionel Sambuc C *CallNewNoThrow() {
29*0a6a1f1dSLionel Sambuc   return new (std::nothrow) C[10];
30*0a6a1f1dSLionel Sambuc }
31*0a6a1f1dSLionel Sambuc // PLAIN-LABEL: CallNewNoThrow
32*0a6a1f1dSLionel Sambuc // PLAIN-NOT: nosanitize
33*0a6a1f1dSLionel Sambuc // PLAIN-NOT: __asan_poison_cxx_array_cookie
34*0a6a1f1dSLionel Sambuc // ASAN-LABEL: CallNewNoThrow
35*0a6a1f1dSLionel Sambuc // ASAN: store{{.*}}nosanitize
36*0a6a1f1dSLionel Sambuc // ASAN-NOT: nosanitize
37*0a6a1f1dSLionel Sambuc // ASAN: call void @__asan_poison_cxx_array_cookie
38*0a6a1f1dSLionel Sambuc 
CallDelete(C * c)39*0a6a1f1dSLionel Sambuc void CallDelete(C *c) {
40*0a6a1f1dSLionel Sambuc   delete [] c;
41*0a6a1f1dSLionel Sambuc }
42*0a6a1f1dSLionel Sambuc 
43*0a6a1f1dSLionel Sambuc // PLAIN-LABEL: CallDelete
44*0a6a1f1dSLionel Sambuc // PLAIN-NOT: nosanitize
45*0a6a1f1dSLionel Sambuc // ASAN-LABEL: CallDelete
46*0a6a1f1dSLionel Sambuc // ASAN-NOT: nosanitize
47*0a6a1f1dSLionel Sambuc // ASAN: call i64 @__asan_load_cxx_array_cookie
48*0a6a1f1dSLionel Sambuc // ASAN-NOT: nosanitize
49*0a6a1f1dSLionel Sambuc 
50*0a6a1f1dSLionel Sambuc char Buffer[20];
CallPlacementNew()51*0a6a1f1dSLionel Sambuc C *CallPlacementNew() {
52*0a6a1f1dSLionel Sambuc   return new (Buffer) C[20];
53*0a6a1f1dSLionel Sambuc }
54*0a6a1f1dSLionel Sambuc // ASAN-LABEL: CallPlacementNew
55*0a6a1f1dSLionel Sambuc // ASAN-NOT: __asan_poison_cxx_array_cookie
56