From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E6121385840B; Wed, 2 Nov 2022 13:09:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E6121385840B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667394582; bh=Oe+U+AH3jznfJlDXYGiW5QGQ2BTvusB2hvkmoNBPnfw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Y7/y+To80mzlJWmvk/5qP95R76utkRv2Wpc3V/8y1LZTYBed8QAlDQH/Ne/dWMG7A fYcnkRs+4HFTGAIj/8ZT97oGWVacJ2wiuCjb5xr+H1RaAEor6TB8LD3nV+Mavernna Eti4IitVQW7WgavWngOIb86IJtzccjrBgm8p+J24= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107500] Useless atexit entry for ~constant_init in eh_globals.cc Date: Wed, 02 Nov 2022 13:09:42 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: 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=3D107500 --- Comment #7 from Jonathan Wakely --- (In reply to R. Diez from comment #5) > First of all, GCC seems unable to generate an empty routine or destructor, > or at least flag it as being effectively empty. The caller should then > realise that it is empty, so it is not worth generating an atexit call for > it. The object has a user-provided destructor, which is necessary for the immortalization trick to work. Being user-provided means it's non-trivial a= nd that means the destructor must be run. To destroy a gobal object, atexit it used. Now if the compiler can tell that the destructor actually has no side effec= ts, it's unobservable whether the atexit call ever happens. But that takes non-trivial analysis of the destructor body and hard-coded knowledge that atexit has no *other* observable side effects except registering the destru= ctor This all requires special case handling in the compiler, not just "turn on = -Os and all the code gets removed".=