1 // RUN: %clang_cc1 -std=c++2a -emit-llvm -O0 -triple x86_64-unknown-linux-gnu -DNOATTR  %s -o - | FileCheck %s
2 // RUN: %clang_cc1 -std=c++2a -emit-llvm -O0 -triple x86_64-unknown-linux-gnu %s -o - | FileCheck %s --check-prefix=CHECK-ATTR
3 // RUN: %clang_cc1 -std=c++2a -emit-llvm -O0 -triple x86_64-unknown-linux-gnu -DNOATTR -fno-c++-static-destructors %s -o - | FileCheck %s --check-prefix=CHECK-FLAG
4 
5 // Regression test for D54344. Class with no user-defined destructor
6 // that has an inherited member that has a non-trivial destructor
7 // and a non-default constructor will attempt to emit a destructor
8 // despite being marked as __attribute((no_destroy)) in which case
9 // it would trigger an assertion due to an incorrect assumption.
10 
11 // This test is more reliable with asserts to work as without
12 // the crash may (unlikely) could generate working but semantically
13 // incorrect code.
14 
15 class a {
16 public:
17   a();
18   ~a();
19 };
20 class logger_base {
21   a d;
22 };
23 class e : logger_base {};
24 #ifndef NOATTR
25 __attribute((no_destroy))
26 #endif
27 e g;
28 
29 // In the absence of the attribute and flag, both ctor and dtor should
30 // be emitted, check for that.
31 // CHECK: @__cxx_global_var_init
32 // CHECK: @__cxa_atexit
33 
34 // When attribute is enabled, the constructor should not be balanced
35 // by a destructor. Make sure we have the ctor but not the dtor
36 // registration.
37 // CHECK-ATTR: @__cxx_global_var_init
38 // CHECK-ATTR-NOT: @__cxa_atexit
39 
40 // Same scenario except with global flag (-fno-c++-static-destructors)
41 // supressing it instead of the attribute.
42 // CHECK-FLAG: @__cxx_global_var_init
43 // CHECK-FLAG-NOT: @__cxa_atexit
44