1 // Test -fsanitize-memory-use-after-dtor
2 // 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_"
4 // Sanitizing dtor is emitted in dtor for every class, and only
12 // Simple internal member is poisoned by compiler-generated dtor
13 // CHECK-LABEL: define {{.*}}SimpleD1Ev
14 // CHECK: call void {{.*}}SimpleD2Ev
22 // Simple internal member is poisoned by compiler-generated dtor
23 // CHECK-LABEL: define {{.*}}InlinedD1Ev
24 // CHECK: call void {{.*}}InlinedD2Ev
27 struct Defaulted_Trivial
{
28 ~Defaulted_Trivial() = default;
30 void create_def_trivial() {
31 Defaulted_Trivial def_trivial
;
33 // The compiler is explicitly signalled to handle object cleanup.
34 // No complex member attributes. Compiler destroys inline, so
35 // no destructor defined.
36 // CHECK-LABEL: define {{.*}}create_def_trivial
37 // CHECK-NOT: call {{.*}}Defaulted_Trivial
40 struct Defaulted_Non_Trivial
{
42 ~Defaulted_Non_Trivial() = default;
44 Defaulted_Non_Trivial def_non_trivial
;
45 // Explicitly compiler-generated dtor poisons object.
46 // By including a Simple member in the struct, the compiler is
47 // forced to generate a non-trivial destructor.
48 // CHECK-LABEL: define {{.*}}Defaulted_Non_TrivialD1Ev
49 // CHECK: call void {{.*}}Defaulted_Non_TrivialD2
53 // Note: ordering is important. In the emitted bytecode, these
54 // second dtors defined after the first. Explicitly checked here
55 // to confirm that all invoked dtors have member poisoning
56 // instrumentation inserted.
57 // CHECK-LABEL: define {{.*}}SimpleD2Ev
58 // CHECK-NOT: store i{{[0-9]+}} 0, {{.*}}@__msan_param_tls
59 // CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, !dbg ![[DI1:[0-9]+]]
62 // CHECK-LABEL: define {{.*}}InlinedD2Ev
63 // CHECK-NOT: store i{{[0-9]+}} 0, {{.*}}@__msan_param_tls
64 // CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, !dbg ![[DI2:[0-9]+]]
67 // CHECK-LABEL: define {{.*}}Defaulted_Non_TrivialD2Ev
68 // CHECK: call void @__sanitizer_dtor_callback_fields({{.*}}, !dbg ![[DI3:[0-9]+]]
71 // CHECK-LABEL: !DIFile{{.*}}cpp
73 // CHECK-DAG: ![[DI1]] = {{.*}}line: [[@LINE-65]]
74 // CHECK-DAG: ![[DI2]] = {{.*}}line: [[@LINE-56]]
75 // CHECK-DAG: ![[DI3]] = {{.*}}line: [[@LINE-34]]