Index: test/CodeGenCXX/sanitize-dtor-callback.cpp =================================================================== --- test/CodeGenCXX/sanitize-dtor-callback.cpp +++ test/CodeGenCXX/sanitize-dtor-callback.cpp @@ -1,6 +1,6 @@ // Test -fsanitize-memory-use-after-dtor -// RUN: %clang_cc1 -fsanitize=memory -fsanitize-memory-use-after-dtor -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s -// RUN: %clang_cc1 -fsanitize=memory -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s -check-prefix=NO_DTOR_CHECK +// RUN: %clang_cc1 -fsanitize=memory -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -fsanitize=memory -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s -check-prefix=NO-DTOR-CHECK struct Simple { ~Simple() {} @@ -12,6 +12,61 @@ // CHECK: ret void // Compiling without the flag does not generate member-poisoning dtor -// NO_DTOR_CHECK-LABEL: @_ZN6SimpleD2Ev -// NO_DTOR_CHECK-NOT: call void @sanitizer_dtor_callback -// NO_DTOR_CHECK: ret void +// NO-DTOR-CHECK-LABEL: @_ZN6SimpleD2Ev +// NO-DTOR-CHECK-NOT: call void @__sanitizer_dtor_callback +// NO-DTOR-CHECK: ret void + + +struct Inlined { + inline ~Inlined() {} +}; +Inlined in; +// Dtor that is inlined where invoked poisons object +// CHECK-LABEL: @_ZN7InlinedD2Ev +// CHECK: call void @__sanitizer_dtor_callback +// CHECK: ret void + +// Compiling without the flag does not generate member-poisoning dtor +// NO-DTOR-CHECK-LABEL: @_ZN7InlinedD2Ev +// NO-DTOR-CHECK-NOT: call void @__sanitizer_dtor_callback +// NO-DTOR-CHECK: ret void + +struct Defaulted_Trivial { + ~Defaulted_Trivial() = default; +}; +void create_def_trivial() { + Defaulted_Trivial def_trivial; +} +// The compiler is explicitly signalled to handle object cleanup. +// No complex member attributes ensures that the compiler destroys +// the memory inline. +// The destructor poisoning does not handle defaulted dtors. +// CHECK-LABEL: define void @_Z18create_def_trivialv() +// CHECK-NOT: call void @_[A-Z]+[0-9]+(Defaulted_TrivialD2Ev) +// CHECK-NOT: call void @__sanitizer_dtor_callback +// CHECK: ret void + +// Compiling without the flag does not generate member-poisoning dtor +// NO-DTOR-CHECK-LABEL: define void @_Z18create_def_trivialv() +// NO-DTOR-CHECK-NOT: call void @__sanitizer_dtor_callback +// NO-DTOR-CHECK: ret void + + +struct Defaulted_Non_Trivial { + Simple s; + ~Defaulted_Non_Trivial() = default; +}; +Defaulted_Non_Trivial def_non_trivial; +// Explicitly compiler-generated dtor poisons object. +// By including a Simple member in the struct, the compiler is +// forced to generate a non-trivial destructor.. +// CHECK-LABEL: define linkonce_odr void @_ZN21Defaulted_Non_TrivialD2Ev +// CHECK-DAG: call void @_ZN6SimpleD1Ev +// CHECK-DAG: call void @__sanitizer_dtor_callback +// CHECK: ret void + +// Compiling without the flag does not generate member-poisoning dtor +// NO-DTOR-CHECK-LABEL: define linkonce_odr void @_ZN21Defaulted_Non_TrivialD2Ev +// NO-DTOR-CHECK-DAG: call void @_ZN6SimpleD1Ev +// NO-DTOR-CHECK-NOT: call void @__sanitizer_dtor_callback +// NO-DTOR-CHECK: ret void