Naomi Musgrave | 866af2d | 2015-09-03 23:02:30 +0000 | [diff] [blame] | 1 | // Test -fsanitize-memory-use-after-dtor |
Chandler Carruth | 93786da | 2016-12-23 00:23:01 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -O0 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-passes -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s |
| 3 | // RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-passes -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s |
Naomi Musgrave | 866af2d | 2015-09-03 23:02:30 +0000 | [diff] [blame] | 4 | |
| 5 | // 24 bytes total |
| 6 | struct Packed { |
| 7 | // Packed into 4 bytes |
| 8 | unsigned int a : 1; |
| 9 | unsigned int b : 1; |
| 10 | //unsigned int c : 1; |
| 11 | // Force alignment to next 4 bytes |
| 12 | unsigned int : 0; |
| 13 | unsigned int d : 1; |
| 14 | // Force alignment, 8 more bytes |
| 15 | double e = 5.0; |
| 16 | // 4 bytes |
| 17 | unsigned int f : 1; |
| 18 | ~Packed() {} |
| 19 | }; |
| 20 | Packed p; |
| 21 | |
| 22 | |
| 23 | // 1 byte total |
| 24 | struct Empty { |
| 25 | unsigned int : 0; |
| 26 | ~Empty() {} |
| 27 | }; |
| 28 | Empty e; |
| 29 | |
| 30 | |
| 31 | // 4 byte total |
| 32 | struct Simple { |
| 33 | unsigned int a : 1; |
| 34 | ~Simple() {} |
| 35 | }; |
| 36 | Simple s; |
| 37 | |
| 38 | |
| 39 | // 8 bytes total |
| 40 | struct Anon { |
| 41 | // 1 byte |
| 42 | unsigned int a : 1; |
| 43 | unsigned int b : 2; |
| 44 | // Force alignment to next byte |
| 45 | unsigned int : 0; |
| 46 | unsigned int c : 1; |
| 47 | ~Anon() {} |
| 48 | }; |
| 49 | Anon an; |
| 50 | |
| 51 | |
| 52 | struct CharStruct { |
| 53 | char c; |
| 54 | ~CharStruct(); |
| 55 | }; |
| 56 | |
| 57 | struct Adjacent { |
| 58 | CharStruct a; |
| 59 | int b : 1; |
| 60 | CharStruct c; |
| 61 | ~Adjacent() {} |
| 62 | }; |
| 63 | Adjacent ad; |
| 64 | |
| 65 | |
| 66 | // CHECK-LABEL: define {{.*}}PackedD2Ev |
| 67 | // CHECK: call void @__sanitizer_dtor_callback{{.*}}i64 17 |
| 68 | // CHECK: ret void |
| 69 | |
| 70 | // CHECK-LABEL: define {{.*}}EmptyD2Ev |
| 71 | // CHECK-NOT: call void @__sanitizer_dtor_callback{{.*}}i64 0 |
| 72 | // CHECK: ret void |
| 73 | |
| 74 | // CHECK-LABEL: define {{.*}}SimpleD2Ev |
| 75 | // CHECK: call void @__sanitizer_dtor_callback{{.*}}i64 1 |
| 76 | // CHECK: ret void |
| 77 | |
| 78 | // CHECK-LABEL: define {{.*}}AnonD2Ev |
| 79 | // CHECK: call void @__sanitizer_dtor_callback{{.*}}i64 5 |
| 80 | // CHECK: ret void |
| 81 | |
| 82 | // CHECK-LABEL: define {{.*}}AdjacentD2Ev |
| 83 | // CHECK: call void @__sanitizer_dtor_callback{{.*}}i64 1 |
| 84 | // CHECK: ret void |