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