| 1 |
// Test -fsanitize-memory-use-after-dtor |
| 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 -debug-info-kind=line-tables-only -o - %s | FileCheck %s --implicit-check-not="call void @__sanitizer_" |
| 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 -debug-info-kind=line-tables-only -o - %s | FileCheck %s --implicit-check-not="call void @__sanitizer_" |
| 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 |
// CHECK-LABEL: define {{.*}}PackedD2Ev |
| 66 |
// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}i64 17{{.*}}, !dbg ![[DI1:[0-9]+]] |
| 67 |
// CHECK: ret void |
| 68 |
|
| 69 |
// CHECK-LABEL: define {{.*}}EmptyD2Ev |
| 70 |
// CHECK: ret void |
| 71 |
|
| 72 |
// CHECK-LABEL: define {{.*}}SimpleD2Ev |
| 73 |
// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}i64 1{{.*}}, !dbg ![[DI2:[0-9]+]] |
| 74 |
// CHECK: ret void |
| 75 |
|
| 76 |
// CHECK-LABEL: define {{.*}}AnonD2Ev |
| 77 |
// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}i64 5{{.*}}, !dbg ![[DI3:[0-9]+]] |
| 78 |
// CHECK: ret void |
| 79 |
|
| 80 |
// CHECK-LABEL: define {{.*}}AdjacentD2Ev |
| 81 |
// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}i64 1{{.*}}, !dbg ![[DI4:[0-9]+]] |
| 82 |
// CHECK: ret void |
| 83 |
|
| 84 |
// CHECK-LABEL: !DIFile{{.*}}cpp |
| 85 |
|
| 86 |
// CHECK-DAG: ![[DI1]] = {{.*}}line: [[@LINE-78]] |
| 87 |
// CHECK-DAG: ![[DI2]] = {{.*}}line: [[@LINE-54]] |
| 88 |
// CHECK-DAG: ![[DI3]] = {{.*}}line: [[@LINE-46]] |
| 89 |
// CHECK-DAG: ![[DI4]] = {{.*}}line: [[@LINE-30]] |