1 // RUN: %clang_cc1 -Wno-unused-value -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
2 // rdar: //8540501
3 extern "C" int printf(...);
4 extern "C" void abort();
5
6 struct A
7 {
8 int i;
AA9 A (int j) : i(j) {printf("this = %p A(%d)\n", this, j);}
AA10 A (const A &j) : i(j.i) {printf("this = %p const A&(%d)\n", this, i);}
operator =A11 A& operator= (const A &j) { i = j.i; abort(); return *this; }
~AA12 ~A() { printf("this = %p ~A(%d)\n", this, i); }
13 };
14
15 struct B
16 {
17 int i;
BB18 B (const A& a) { i = a.i; }
BB19 B() {printf("this = %p B()\n", this);}
BB20 B (const B &j) : i(j.i) {printf("this = %p const B&(%d)\n", this, i);}
~BB21 ~B() { printf("this = %p ~B(%d)\n", this, i); }
22 };
23
foo(int j)24 A foo(int j)
25 {
26 return ({ j ? A(1) : A(0); });
27 }
28
29
foo2()30 void foo2()
31 {
32 A b = ({ A a(1); A a1(2); A a2(3); a1; a2; a; });
33 if (b.i != 1)
34 abort();
35 A c = ({ A a(1); A a1(2); A a2(3); a1; a2; a; A a3(4); a2; a3; });
36 if (c.i != 4)
37 abort();
38 }
39
foo3()40 void foo3()
41 {
42 const A &b = ({ A a(1); a; });
43 if (b.i != 1)
44 abort();
45 }
46
foo4()47 void foo4()
48 {
49 // CHECK: call {{.*}} @_ZN1AC1Ei
50 // CHECK: call {{.*}} @_ZN1AC1ERKS_
51 // CHECK: call {{.*}} @_ZN1AD1Ev
52 // CHECK: call {{.*}} @_ZN1BC1ERK1A
53 // CHECK: call {{.*}} @_ZN1AD1Ev
54 const B &b = ({ A a(1); a; });
55 if (b.i != 1)
56 abort();
57 }
58
main()59 int main()
60 {
61 foo2();
62 foo3();
63 foo4();
64 return foo(1).i-1;
65 }
66
67 // rdar: // 8600553
68 int a[128];
foo5()69 int* foo5() {
70 // CHECK-NOT: memcpy
71 // Check that array-to-pointer conversion occurs in a
72 // statement-expression.
73 return (({ a; }));
74 }
75
76 // <rdar://problem/14074868>
77 // Make sure this doesn't crash.
foo5(bool b)78 int foo5(bool b) {
79 int y = 0;
80 y = ({ A a(1); if (b) goto G; a.i; });
81 G: return y;
82 }
83