File: attr-no-destroy-d54344.cpp

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (43 lines) | stat: -rw-r--r-- 1,603 bytes parent folder | download | duplicates (17)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// RUN: %clang_cc1 -std=c++2a -emit-llvm -O0 -triple x86_64-unknown-linux-gnu -DNOATTR  %s -o - | FileCheck %s
// RUN: %clang_cc1 -std=c++2a -emit-llvm -O0 -triple x86_64-unknown-linux-gnu %s -o - | FileCheck %s --check-prefix=CHECK-ATTR
// 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

// Regression test for D54344. Class with no user-defined destructor
// that has an inherited member that has a non-trivial destructor
// and a non-default constructor will attempt to emit a destructor
// despite being marked as __attribute((no_destroy)) in which case
// it would trigger an assertion due to an incorrect assumption.

// This test is more reliable with asserts to work as without 
// the crash may (unlikely) could generate working but semantically
// incorrect code.

class a {
public:
  a();
  ~a();
};
class logger_base {
  a d;
};
class e : logger_base {};
#ifndef NOATTR
__attribute((no_destroy))
#endif
e g;

// In the absence of the attribute and flag, both ctor and dtor should
// be emitted, check for that.
// CHECK: @__cxx_global_var_init
// CHECK: @__cxa_atexit

// When attribute is enabled, the constructor should not be balanced
// by a destructor. Make sure we have the ctor but not the dtor
// registration.
// CHECK-ATTR: @__cxx_global_var_init
// CHECK-ATTR-NOT: @__cxa_atexit

// Same scenario except with global flag (-fno-c++-static-destructors)
// supressing it instead of the attribute. 
// CHECK-FLAG: @__cxx_global_var_init
// CHECK-FLAG-NOT: @__cxa_atexit