45 lines · cpp
1// RUN: %clang_cc1 -std=c++2a -emit-llvm -O0 -triple x86_64-unknown-linux-gnu -DNOATTR %s -o - | FileCheck %s2// RUN: %clang_cc1 -std=c++2a -emit-llvm -O0 -triple x86_64-unknown-linux-gnu %s -o - | FileCheck %s --check-prefix=CHECK-ATTR3// RUN: %clang_cc1 -std=c++2a -emit-llvm -O0 -triple x86_64-unknown-linux-gnu -DNOATTR -fc++-static-destructors=none %s -o - | FileCheck %s --check-prefix=CHECK-FLAG4// RUN: %clang_cc1 -std=c++2a -emit-llvm -O0 -triple x86_64-unknown-linux-gnu -DNOATTR -fc++-static-destructors=thread-local %s -o - | FileCheck %s --check-prefix=CHECK-FLAG5 6// Regression test for D54344. Class with no user-defined destructor7// that has an inherited member that has a non-trivial destructor8// and a non-default constructor will attempt to emit a destructor9// despite being marked as __attribute((no_destroy)) in which case10// it would trigger an assertion due to an incorrect assumption.11 12// This test is more reliable with asserts to work as without 13// the crash may (unlikely) could generate working but semantically14// incorrect code.15 16class a {17public:18 a();19 ~a();20};21class logger_base {22 a d;23};24class e : logger_base {};25#ifndef NOATTR26__attribute((no_destroy))27#endif28e g;29 30// In the absence of the attribute and flag, both ctor and dtor should31// be emitted, check for that.32// CHECK: @__cxx_global_var_init33// CHECK: @__cxa_atexit34 35// When attribute is enabled, the constructor should not be balanced36// by a destructor. Make sure we have the ctor but not the dtor37// registration.38// CHECK-ATTR: @__cxx_global_var_init39// CHECK-ATTR-NOT: @__cxa_atexit40 41// Same scenario except with global flag (-fno-c++-static-destructors)42// supressing it instead of the attribute. 43// CHECK-FLAG: @__cxx_global_var_init44// CHECK-FLAG-NOT: @__cxa_atexit45