From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 748E43871016; Wed, 26 Jun 2024 20:07:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 748E43871016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1719432423; bh=CjgYEHl+geEiPhQTm/vUM3oNPG6PEOWhryPWoqIFwNA=; h=From:To:Subject:Date:From; b=u/IaN0AGxATnlb5niPR/5Xj50FoN99RCsvq/RkcirdfNxrVbKAVUhHOZCTUgj8Oc0 ReZp9oUbAzckL87Mfxvy905aRcBL7iudAXx0yAdot6OvAK04V9drtiuWQ+XTPn3JJ0 j+rKGI8h9UxeUAX2QEUrq9WSlb35xH2FeFKQfhOI= From: "federico at kircheis dot it" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/115670] New: missed optimization - anonymous structures Date: Wed, 26 Jun 2024 20:07:02 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 15.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: federico at kircheis dot it X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D115670 Bug ID: 115670 Summary: missed optimization - anonymous structures Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: federico at kircheis dot it Target Milestone: --- Consider following code snippet ~~~~ struct { int i =3D 42; } const a; auto bar(){ return a; } ~~~~ GCC optimizes the code to=20 ~~~~ bar(): mov eax, 42 ret ~~~~ but the MSVC compiler can do even better even with /O0. It seems that it does not generate any code for the function bar at all! The root cause seems to be that if a function depends on an anonymous struc= ture (either the anonymous structure is part of the input parameters, like "auto bar(decltype(a)&){return 1;}", or the return value), then the compiler determines that if it is not used in the same translation unit, it cannot be used from other translation units. It would be nice if GCC would be able to do such optimization. I know that -Wunused-function helps to find those functions (and it catches= the example I gave), but I need to delete them from the source code, which might not be practical if integrating external/generated code.=