public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/115670] New: missed optimization - anonymous structures
@ 2024-06-26 20:07 federico at kircheis dot it
  2024-06-26 20:11 ` [Bug c++/115670] auto return type does not change the linkage for anonymous structs pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: federico at kircheis dot it @ 2024-06-26 20:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115670

            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 = 42;
} const a;


auto bar(){
    return a;
}
~~~~

GCC optimizes the code to 

~~~~
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 structure
(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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-06-30 11:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-26 20:07 [Bug c++/115670] New: missed optimization - anonymous structures federico at kircheis dot it
2024-06-26 20:11 ` [Bug c++/115670] auto return type does not change the linkage for anonymous structs pinskia at gcc dot gnu.org
2024-06-26 21:08 ` [Bug c++/115670] auto return type does not change the linkage for local structs pinskia at gcc dot gnu.org
2024-06-27 17:38 ` [Bug c++/115670] auto placeholder for return type should change the linkage of the function if the type becomes local linkage too federico at kircheis dot it
2024-06-27 17:42 ` federico at kircheis dot it
2024-06-27 20:28 ` pinskia at gcc dot gnu.org
2024-06-27 20:35 ` pinskia at gcc dot gnu.org
2024-06-30 11:12 ` federico at kircheis dot it

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).