blob: 821f1b032b61b9e9b5905326561f75913974e20d [file] [log] [blame]
Kostya Serebryany4ee69042014-08-26 02:29:59 +00001// 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
Filipe Cabecinhas0eb50082018-11-02 17:29:04 +00003// RUN: %clang_cc1 -triple x86_64-gnu-linux -emit-llvm -o - -fsanitize=address -fsanitize-address-poison-custom-array-cookie %s | FileCheck %s -check-prefix=ASAN-POISON-ALL-NEW-ARRAY
Kostya Serebryany4ee69042014-08-26 02:29:59 +00004
5typedef __typeof__(sizeof(0)) size_t;
6namespace std {
7 struct nothrow_t {};
8 std::nothrow_t nothrow;
9}
10void *operator new[](size_t, const std::nothrow_t &) throw();
Filipe Cabecinhas6f83fa92018-01-02 13:46:12 +000011void *operator new[](size_t, char *);
Filipe Cabecinhas4ba58172018-02-12 11:49:02 +000012void *operator new[](size_t, int, int);
Kostya Serebryany4ee69042014-08-26 02:29:59 +000013
14struct C {
15 int x;
16 ~C();
17};
18
19C *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
30C *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
41void CallDelete(C *c) {
42 delete [] c;
43}
44
45// PLAIN-LABEL: CallDelete
46// PLAIN-NOT: nosanitize
47// ASAN-LABEL: CallDelete
Kostya Serebryany4a9187a2014-08-29 01:01:32 +000048// ASAN-NOT: nosanitize
49// ASAN: call i64 @__asan_load_cxx_array_cookie
Kostya Serebryany4ee69042014-08-26 02:29:59 +000050// ASAN-NOT: nosanitize
51
52char Buffer[20];
53C *CallPlacementNew() {
54 return new (Buffer) C[20];
55}
56// ASAN-LABEL: CallPlacementNew
57// ASAN-NOT: __asan_poison_cxx_array_cookie
Filipe Cabecinhas4ba58172018-02-12 11:49:02 +000058
59C *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}