Debian Codegraph @

gcc/testsuite/g++.dg/tree-ssa/cxa_atexit-5.C

raw
1 /* { dg-do compile { target c++20 } } */
2 /* { dg-options "-O2 -fdump-tree-dce2-details -fdump-tree-optimized" } */
3 // { dg-require-effective-target cxa_atexit }
4 /* PR tree-optimization/19661 */
5
6 /* The call to axexit should be removed as constant_init::~constant_init is a pure/const function call
7 and there is no visible effect if constant_init::~constant_init() call does not happen. */
8 /* This takes until DCE2 as constant_init::~constant_init is not figured out being pure/const until late. */
9
10 extern "C" int puts(const char*);
11
12 struct A
13 {
14 constexpr A() { }
15 ~A() { puts("bye"); }
16 };
17
18 namespace
19 {
20 struct constant_init
21 {
22 union {
23 A obj;
24 };
25 constexpr constant_init() : obj() { }
26
27 ~constant_init() { /* do nothing, union member is not destroyed */ }
28 };
29
30
31 // Single-threaded fallback buffer.
32 constinit constant_init global;
33 }
34
35 extern "C" A* get() { return &global.obj; }
36
37 /* { dg-final { scan-tree-dump-times "Deleting : (?:__cxxabiv1::__cxa_atexit|__aeabiv1::__aeabi_atexit)" 1 "dce2" } } */
38 /* { dg-final { scan-tree-dump-not "(?:__cxa_atexit|__aeabi_atexit)" "optimized" } } */
39