public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/45115]  New: attribute((pure)) does not work when returning structs
@ 2010-07-28 19:45 marco at technoboredom dot net
  2010-07-28 19:48 ` [Bug tree-optimization/45115] pure functions returning structs are not optimized pinskia at gcc dot gnu dot org
  2010-07-28 20:05 ` rguenth at gcc dot gnu dot org
  0 siblings, 2 replies; 6+ messages in thread
From: marco at technoboredom dot net @ 2010-07-28 19:45 UTC (permalink / raw)
  To: gcc-bugs

compiling this with 'gcc -O3 -S x.c'

-------- x.c -----------
#define PURE __attribute__((pure))

struct res {int u; };
extern struct res calc_1() PURE; 
extern int        calc_2() PURE;

int fun_1() 
{
        return calc_1().u+calc_1().u;
}
int fun_2() 
{
        return calc_2()+calc_2();
}
--------------------

yields code which calls calc_2() *once* in fun_2() but calls calc_1() *twice*
in fun_1(). Obviously, fun_1 misses an optimization.

Tested on gcc 4.4.3 (Ubuntu 10.04), gcc 4.5.0/4.4.4/4.3.5 (MacPorts)


-- 
           Summary: attribute((pure)) does not work when returning structs
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: marco at technoboredom dot net
  GCC host triplet: x86_64-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45115


^ permalink raw reply	[flat|nested] 6+ messages in thread
[parent not found: <bug-45115-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2024-04-09  7:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-07-28 19:45 [Bug c/45115] New: attribute((pure)) does not work when returning structs marco at technoboredom dot net
2010-07-28 19:48 ` [Bug tree-optimization/45115] pure functions returning structs are not optimized pinskia at gcc dot gnu dot org
2010-07-28 20:05 ` rguenth at gcc dot gnu dot org
     [not found] <bug-45115-4@http.gcc.gnu.org/bugzilla/>
2023-02-02  9:43 ` pinskia at gcc dot gnu.org
2023-02-02 10:15 ` redi at gcc dot gnu.org
2024-04-09  7:06 ` pinskia at gcc dot gnu.org

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).