From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0B7F03856DCD; Wed, 2 Nov 2022 15:53:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B7F03856DCD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667404400; bh=2KuvRywz/si24urRuC1eBnfoaLxaZIcCVK85IfBhdG8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YefU2247edsvYonifpisaTxjKxc+olUR1C2uavsfTeR/Fy7VhsvuGYf0Qg4z4qipj n36kVumYlv9SJz1FjtvEE2zzPhBjDnfnFdG0gxovkiItMiJoofqAAxk/oKnmNDfhAc CfeX2XQixUJ+VL6lwlpauVb7CfsHkBH35snfhwyw= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/19661] unnecessary atexit calls emitted for static objects with empty destructors Date: Wed, 02 Nov 2022 15:53:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 3.4.2 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cf_reconfirmed_on Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D19661 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed|2006-02-05 21:10:26 |2022-11-2 --- Comment #12 from Jonathan Wakely --- Reduced from the code in libstdc++: extern "C" int puts(const char*); struct A { constexpr A() { } ~A() { puts("bye"); } }; namespace { struct constant_init { union { A obj; }; constexpr constant_init() : obj() { } ~constant_init() { /* do nothing, union member is not destroyed */ } }; // Single-threaded fallback buffer. constinit constant_init global; } extern "C" A* get() { return &global.obj; } With -std=3Dc++20 -Os GCC emits a call to atexit: (anonymous namespace)::constant_init::~constant_init() [base object destructor]: ret get: mov eax, OFFSET FLAT:_ZN12_GLOBAL__N_16globalE ret _GLOBAL__sub_I_get: mov edx, OFFSET FLAT:__dso_handle mov esi, OFFSET FLAT:_ZN12_GLOBAL__N_16globalE mov edi, OFFSET FLAT:_ZN12_GLOBAL__N_113constant_initD1Ev jmp __cxa_atexit With the same options, Clang doesn't: get: # @get lea rax, [rip + (anonymous namespace)::global] ret=