summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGenCXX/cxx0x-initializer-array.cpp
blob: 3144e941ef4276a19e9878a93b6605e772edd0c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// RUN: %clang_cc1 -triple i386-unknown-unknown -std=c++11 -S -emit-llvm -o - %s -Wno-address-of-temporary | FileCheck %s

// CHECK: @[[THREE_NULL_MEMPTRS:.*]] = private constant [3 x i32] [i32 -1, i32 -1, i32 -1]

struct A { int a[1]; };
typedef A x[];
int f() {
  x{{{1}}};
  // CHECK: define i32 @_Z1fv
  // CHECK: store i32 1
  // (It's okay if the output changes here, as long as we don't crash.)
  return 0;
}

namespace ValueInitArrayOfMemPtr {
  struct S {};
  typedef int (S::*p);
  typedef p a[3];
  void f(const a &);

  struct Agg1 {
    int n;
    p x;
  };

  struct Agg2 {
    int n;
    a x;
  };

  struct S1 {
    p x;
    S1();
  };

  // CHECK: define void @_ZN22ValueInitArrayOfMemPtr1fEi
  void f(int n) {
    Agg1 a = { n };
    // CHECK: store i32 -1,

    Agg2 b = { n };
    // 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)
  }

  // CHECK: define void @_ZN22ValueInitArrayOfMemPtr1gEv
  void g() {
    // CHECK: store i32 -1,
    f(a{});
  }
}

namespace array_dtor {
  struct S { S(); ~S(); };
  using T = S[3];
  void f(const T &);
  void f(T *);
  // CHECK: define void @_ZN10array_dtor1gEv(
  void g() {
    // CHECK: %[[ARRAY:.*]] = alloca [3 x
    // CHECK: br

    // Construct loop.
    // CHECK: call void @_ZN10array_dtor1SC1Ev(
    // CHECK: br i1

    // CHECK: call void @_ZN10array_dtor1fERA3_KNS_1SE(
    // CHECK: br

    // Destruct loop.
    // CHECK: call void @_ZN10array_dtor1SD1Ev(
    // CHECK: br i1
    f(T{});

    // CHECK: ret void
  }
  // CHECK: define void @_ZN10array_dtor1hEv(
  void h() {
    // CHECK: %[[ARRAY:.*]] = alloca [3 x
    // CHECK: br

    // CHECK: call void @_ZN10array_dtor1SC1Ev(
    // CHECK: br i1
    T &&t = T{};

    // CHECK: call void @_ZN10array_dtor1fERA3_KNS_1SE(
    // CHECK: br
    f(t);

    // CHECK: call void @_ZN10array_dtor1SD1Ev(
    // CHECK: br i1

    // CHECK: ret void
  }
  // CHECK: define void @_ZN10array_dtor1iEv(
  void i() {
    // CHECK: %[[ARRAY:.*]] = alloca [3 x
    // CHECK: br

    // CHECK: call void @_ZN10array_dtor1SC1Ev(
    // CHECK: br i1

    // CHECK: call void @_ZN10array_dtor1fEPA3_NS_1SE(
    // CHECK: br

    // CHECK: call void @_ZN10array_dtor1SD1Ev(
    // CHECK: br i1
    f(&T{});

    // CHECK: ret void
  }
}
OpenPOWER on IntegriCloud