1 // PR c++/16405
2 // { dg-options "-O2" }
3 // { dg-do run }
4
5 // There should be exactly one temporary generated for the code in "f"
6 // below when optimizing -- for the result of "b + c". We have no
7 // easy way of checking that directly, so we count the number of calls
8 // to "memcpy", which is used on (some?) targets to copy temporaries.
9 // If there is more than two calls (one for coping "*this" to "t", and
10 // one for copying the temporary to "a"), then there are too many
11 // temporaries.
12
13 int i;
14
15 extern "C"
memcpy(void * dest,const void * src,__SIZE_TYPE__ n)16 void *memcpy (void *dest, const void *src, __SIZE_TYPE__ n)
17 {
18 char *d = (char *) dest;
19 const char *s = (const char *) src;
20 while (n--)
21 d[n] = s[n];
22 ++i;
23 return dest;
24 }
25
26 struct T {
27 #ifdef __SPU__
28 /* SPU returns aggregates up to 1172 bytes in registers. */
29 int a[300];
30 #else
31 int a[128];
32 #endif
33 T &operator+=(T const &v) __attribute__((noinline));
34 T operator+(T const &v) const { T t = *this; t += v; return t; }
35 };
36
37 T &T::operator+=(T const &v) {
38 return *this;
39 }
40
41 T a, b, c;
42
f()43 void f() { a = b + c; }
44
main()45 int main () {
46 i = 0;
47 f();
48 if (i > 2)
49 return 1;
50 }
51