76 lines · cpp
1// Test -fsanitize-memory-use-after-dtor2// RUN: %clang_cc1 -fsanitize=memory -fsanitize-memory-use-after-dtor -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 4// Sanitizing dtor is emitted in dtor for every class, and only5// poisons once.6 7struct Simple {8 int x;9 ~Simple() {}10};11Simple s;12// Simple internal member is poisoned by compiler-generated dtor13// CHECK-LABEL: define {{.*}}SimpleD1Ev14// CHECK: call void {{.*}}SimpleD2Ev15// CHECK: ret void16 17struct Inlined {18 int y;19 inline ~Inlined() {}20};21Inlined i;22// Simple internal member is poisoned by compiler-generated dtor23// CHECK-LABEL: define {{.*}}InlinedD1Ev24// CHECK: call void {{.*}}InlinedD2Ev25// CHECK: ret void26 27struct Defaulted_Trivial {28 ~Defaulted_Trivial() = default;29};30void create_def_trivial() {31 Defaulted_Trivial def_trivial;32}33// The compiler is explicitly signalled to handle object cleanup.34// No complex member attributes. Compiler destroys inline, so35// no destructor defined.36// CHECK-LABEL: define {{.*}}create_def_trivial37// CHECK-NOT: call {{.*}}Defaulted_Trivial38// CHECK: ret void39 40struct Defaulted_Non_Trivial {41 Simple s;42 ~Defaulted_Non_Trivial() = default;43};44Defaulted_Non_Trivial def_non_trivial;45// Explicitly compiler-generated dtor poisons object.46// By including a Simple member in the struct, the compiler is47// forced to generate a non-trivial destructor.48// CHECK-LABEL: define {{.*}}Defaulted_Non_TrivialD1Ev49// CHECK: call void {{.*}}Defaulted_Non_TrivialD250// CHECK: ret void51 52 53// Note: ordering is important. In the emitted bytecode, these54// second dtors defined after the first. Explicitly checked here55// to confirm that all invoked dtors have member poisoning56// instrumentation inserted.57// CHECK-LABEL: define {{.*}}SimpleD2Ev58// CHECK-NOT: store i{{[0-9]+}} 0, {{.*}}@__msan_param_tls59// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, !dbg ![[DI1:[0-9]+]]60// CHECK: ret void61 62// CHECK-LABEL: define {{.*}}InlinedD2Ev63// CHECK-NOT: store i{{[0-9]+}} 0, {{.*}}@__msan_param_tls64// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, !dbg ![[DI2:[0-9]+]]65// CHECK: ret void66 67// CHECK-LABEL: define {{.*}}Defaulted_Non_TrivialD2Ev68// CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, !dbg ![[DI3:[0-9]+]]69// CHECK: ret void70 71// CHECK-LABEL: !DIFile{{.*}}cpp72 73// CHECK-DAG: ![[DI1]] = {{.*}}line: [[@LINE-65]]74// CHECK-DAG: ![[DI2]] = {{.*}}line: [[@LINE-56]]75// CHECK-DAG: ![[DI3]] = {{.*}}line: [[@LINE-34]]76