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