Home | History | Annotate | Download | only in CodeGenCXX
      1 // RUN: %clang_cc1 -Wno-unused-value -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;
      9   A (int j) : i(j) {printf("this = %p A(%d)\n", this, j);}
     10   A (const A &j) : i(j.i) {printf("this = %p const A&(%d)\n", this, i);}
     11   A& operator= (const A &j) { i = j.i; abort(); return *this; }
     12   ~A() { printf("this = %p ~A(%d)\n", this, i); }
     13 };
     14 
     15 struct B
     16 {
     17   int i;
     18   B (const A& a) { i = a.i; }
     19   B() {printf("this = %p B()\n", this);}
     20   B (const B &j) : i(j.i) {printf("this = %p const B&(%d)\n", this, i);}
     21   ~B() { printf("this = %p ~B(%d)\n", this, i); }
     22 };
     23 
     24 A foo(int j)
     25 {
     26   return ({ j ? A(1) : A(0); });
     27 }
     28 
     29 
     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 
     40 void foo3()
     41 {
     42   const A &b = ({ A a(1); a; });
     43   if (b.i != 1)
     44     abort();
     45 }
     46 
     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 
     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];
     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