Home | History | Annotate | Download | only in CodeGenCXX
      1 // RUN: %clang_cc1 -triple i386-unknown-unknown -std=c++11 -S -emit-llvm -o - %s -Wno-address-of-temporary | FileCheck %s
      2 
      3 // CHECK: @[[THREE_NULL_MEMPTRS:.*]] = private constant [3 x i32] [i32 -1, i32 -1, i32 -1]
      4 
      5 struct A { int a[1]; };
      6 typedef A x[];
      7 int f() {
      8   x{{{1}}};
      9   // CHECK-LABEL: define i32 @_Z1fv
     10   // CHECK: store i32 1
     11   // (It's okay if the output changes here, as long as we don't crash.)
     12   return 0;
     13 }
     14 
     15 namespace ValueInitArrayOfMemPtr {
     16   struct S {};
     17   typedef int (S::*p);
     18   typedef p a[3];
     19   void f(const a &);
     20 
     21   struct Agg1 {
     22     int n;
     23     p x;
     24   };
     25 
     26   struct Agg2 {
     27     int n;
     28     a x;
     29   };
     30 
     31   struct S1 {
     32     p x;
     33     S1();
     34   };
     35 
     36   // CHECK-LABEL: define void @_ZN22ValueInitArrayOfMemPtr1fEi
     37   void f(int n) {
     38     Agg1 a = { n };
     39     // CHECK: store i32 -1,
     40 
     41     Agg2 b = { n };
     42     // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %{{.*}}, i8* bitcast ([3 x i32]* @[[THREE_NULL_MEMPTRS]] to i8*), i32 12, i32 4, i1 false)
     43   }
     44 
     45   // CHECK-LABEL: define void @_ZN22ValueInitArrayOfMemPtr1gEv
     46   void g() {
     47     // CHECK: store i32 -1,
     48     f(a{});
     49   }
     50 }
     51 
     52 namespace array_dtor {
     53   struct S { S(); ~S(); };
     54   using T = S[3];
     55   void f(const T &);
     56   void f(T *);
     57   // CHECK-LABEL: define void @_ZN10array_dtor1gEv(
     58   void g() {
     59     // CHECK: %[[ARRAY:.*]] = alloca [3 x
     60     // CHECK: br
     61 
     62     // Construct loop.
     63     // CHECK: call void @_ZN10array_dtor1SC1Ev(
     64     // CHECK: br i1
     65 
     66     // CHECK: call void @_ZN10array_dtor1fERA3_KNS_1SE(
     67     // CHECK: br
     68 
     69     // Destruct loop.
     70     // CHECK: call void @_ZN10array_dtor1SD1Ev(
     71     // CHECK: br i1
     72     f(T{});
     73 
     74     // CHECK: ret void
     75   }
     76   // CHECK-LABEL: define void @_ZN10array_dtor1hEv(
     77   void h() {
     78     // CHECK: %[[ARRAY:.*]] = alloca [3 x
     79     // CHECK: br
     80 
     81     // CHECK: call void @_ZN10array_dtor1SC1Ev(
     82     // CHECK: br i1
     83     T &&t = T{};
     84 
     85     // CHECK: call void @_ZN10array_dtor1fERA3_KNS_1SE(
     86     // CHECK: br
     87     f(t);
     88 
     89     // CHECK: call void @_ZN10array_dtor1SD1Ev(
     90     // CHECK: br i1
     91 
     92     // CHECK: ret void
     93   }
     94   // CHECK-LABEL: define void @_ZN10array_dtor1iEv(
     95   void i() {
     96     // CHECK: %[[ARRAY:.*]] = alloca [3 x
     97     // CHECK: br
     98 
     99     // CHECK: call void @_ZN10array_dtor1SC1Ev(
    100     // CHECK: br i1
    101 
    102     // CHECK: call void @_ZN10array_dtor1fEPA3_NS_1SE(
    103     // CHECK: br
    104 
    105     // CHECK: call void @_ZN10array_dtor1SD1Ev(
    106     // CHECK: br i1
    107     f(&T{});
    108 
    109     // CHECK: ret void
    110   }
    111 }
    112