[flang] Fix crash in HLFIR generation (#118399)
[llvm-project.git] / clang / test / CodeGen / address-sanitizer-and-array-cookie.cpp
blob821f1b032b61b9e9b5905326561f75913974e20d
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-custom-array-cookie %s | FileCheck %s -check-prefix=ASAN-POISON-ALL-NEW-ARRAY
5 typedef __typeof__(sizeof(0)) size_t;
6 namespace std {
7 struct nothrow_t {};
8 std::nothrow_t nothrow;
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);
14 struct C {
15 int x;
16 ~C();
19 C *CallNew() {
20 return new C[10];
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
30 C *CallNewNoThrow() {
31 return new (std::nothrow) C[10];
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
41 void CallDelete(C *c) {
42 delete [] c;
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
52 char Buffer[20];
53 C *CallPlacementNew() {
54 return new (Buffer) C[20];
56 // ASAN-LABEL: CallPlacementNew
57 // ASAN-NOT: __asan_poison_cxx_array_cookie
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];