90 lines · cpp
1// Test -fsanitize-memory-use-after-dtor2// 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 total6struct Packed {7 // Packed into 4 bytes8 unsigned int a : 1;9 unsigned int b : 1;10 //unsigned int c : 1;11 // Force alignment to next 4 bytes12 unsigned int : 0;13 unsigned int d : 1;14 // Force alignment, 8 more bytes15 double e = 5.0;16 // 4 bytes17 unsigned int f : 1;18 ~Packed() {}19};20Packed p;21 22 23// 1 byte total24struct Empty {25 unsigned int : 0;26 ~Empty() {}27};28Empty e;29 30 31// 4 byte total32struct Simple {33 unsigned int a : 1;34 ~Simple() {}35};36Simple s;37 38 39// 8 bytes total40struct Anon {41 // 1 byte42 unsigned int a : 1;43 unsigned int b : 2;44 // Force alignment to next byte45 unsigned int : 0;46 unsigned int c : 1;47 ~Anon() {}48};49Anon an;50 51 52struct CharStruct {53 char c;54 ~CharStruct();55};56 57struct Adjacent {58 CharStruct a;59 int b : 1;60 CharStruct c;61 ~Adjacent() {}62};63Adjacent ad;64 65// CHECK-LABEL: define {{.*}}PackedD2Ev66// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}i64 17{{.*}}, !dbg ![[DI1:[0-9]+]]67// CHECK: ret void68 69// CHECK-LABEL: define {{.*}}EmptyD2Ev70// CHECK: ret void71 72// CHECK-LABEL: define {{.*}}SimpleD2Ev73// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}i64 1{{.*}}, !dbg ![[DI2:[0-9]+]]74// CHECK: ret void75 76// CHECK-LABEL: define {{.*}}AnonD2Ev77// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}i64 5{{.*}}, !dbg ![[DI3:[0-9]+]]78// CHECK: ret void79 80// CHECK-LABEL: define {{.*}}AdjacentD2Ev81// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}i64 1{{.*}}, !dbg ![[DI4:[0-9]+]]82// CHECK: ret void83 84// CHECK-LABEL: !DIFile{{.*}}cpp85 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]]90