brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.1 KiB · f191599 Raw
239 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 %s -emit-llvm -o %t2// RUN: FileCheck %s < %t3// RUN: FileCheck -check-prefix=CHECK-PR10720 %s < %t4 5extern "C" int printf(...);6 7struct M {8  M() { printf("M()\n"); }9  M(int i) { iM = i; printf("M(%d)\n", i); }10  int iM;11  void MPR() {printf("iM = %d\n", iM); };12};13 14struct P {15  P() { printf("P()\n"); }16  P(int i) { iP = i; printf("P(%d)\n", i); }17  int iP;18  void PPR() {printf("iP = %d\n", iP); };19};20 21struct Q {22  Q() { printf("Q()\n"); }23  Q(int i) { iQ = i; printf("Q(%d)\n", i); }24  int iQ;25  void QPR() {printf("iQ = %d\n", iQ); };26};27 28struct N : M , P, Q {29  N() : f1(1.314), P(2000), ld(00.1234+f1), M(1000), Q(3000),30        d1(3.4567), i1(1234), m1(100) { printf("N()\n"); }31  M m1;32  M m2;33  float f1;34  int i1;35  float d1;36  void PR() {37    printf("f1 = %f d1 = %f i1 = %d ld = %f \n", f1,d1,i1, ld); 38    MPR();39    PPR();40    QPR();41    printf("iQ = %d\n", iQ);42    printf("iP = %d\n", iP);43    printf("iM = %d\n", iM);44    // FIXME. We don't yet support this syntax.45    // printf("iQ = %d\n", (*this).iQ);46    printf("iQ = %d\n", this->iQ);47    printf("iP = %d\n", this->iP);48    printf("iM = %d\n", this->iM);49  }50  float ld;51  float ff;52  M arr_m[3];53  P arr_p[1][3];54  Q arr_q[2][3][4];55};56 57int main() {58  M m1;59 60  N n1;61  n1.PR();62}63 64// PR582665template <class T> struct A {66  A() {}67  A(int) {}68  A(const A&) {}69  ~A() {}70  operator int() {return 0;}71};72 73// CHECK-LABEL: define{{.*}} void @_Z1fv()74void f() {75  // CHECK: call void @_ZN1AIsEC1Ei76  A<short> a4 = 97;77 78  // CHECK-NEXT: store i32 1779  int i = 17;80 81  // CHECK-NEXT: call void @_ZN1AIsED1Ev82  // CHECK-NOT: call void @_ZN1AIsED1Ev83  // CHECK: ret void84}85 86// Make sure we initialize the vtable pointer if it's required by a87// base initializer.88namespace InitVTable {89  struct A { A(int); };90  struct B : A {91    virtual int foo();92    B();93    B(int);94  };95 96  // CHECK-LABEL: define{{.*}} void @_ZN10InitVTable1BC2Ev(ptr {{[^,]*}} %this) unnamed_addr97  // CHECK: store ptr getelementptr inbounds inrange(-16, 8) ({ [3 x ptr] }, ptr @_ZTVN10InitVTable1BE, i32 0, i32 0, i32 2), ptr [[THIS:%.*]],98  // CHECK:      [[VTBL:%.*]] = load ptr, ptr {{%.*}}99  // CHECK-NEXT: [[FNP:%.*]] = getelementptr inbounds ptr, ptr [[VTBL]], i64 0100  // CHECK-NEXT: [[FN:%.*]] = load ptr, ptr [[FNP]]101  // CHECK-NEXT: [[ARG:%.*]] = call noundef i32 [[FN]](ptr {{[^,]*}} [[THIS]])102  // CHECK-NEXT: call void @_ZN10InitVTable1AC2Ei(ptr {{[^,]*}} {{%.*}}, i32 noundef [[ARG]])103  // CHECK-NEXT: store ptr getelementptr inbounds inrange(-16, 8) ({ [3 x ptr] }, ptr @_ZTVN10InitVTable1BE, i32 0, i32 0, i32 2), ptr [[THIS]]104  // CHECK-NEXT: ret void105  B::B() : A(foo()) {}106 107  // CHECK-LABEL: define{{.*}} void @_ZN10InitVTable1BC2Ei(ptr {{[^,]*}} %this, i32 noundef %x) unnamed_addr108  // CHECK:      [[ARG:%.*]] = add nsw i32 {{%.*}}, 5109  // CHECK-NEXT: call void @_ZN10InitVTable1AC2Ei(ptr {{[^,]*}} {{%.*}}, i32 noundef [[ARG]])110  // CHECK-NEXT: store ptr getelementptr inbounds inrange(-16, 8) ({ [3 x ptr] }, ptr @_ZTVN10InitVTable1BE, i32 0, i32 0, i32 2), ptr {{%.*}}111  // CHECK-NEXT: ret void112  B::B(int x) : A(x + 5) {}113}114 115namespace rdar9694300 {116  struct X {117    int x;118  };119 120  // CHECK-LABEL: define{{.*}} void @_ZN11rdar96943001fEv121  void f() {122    // CHECK: alloca123    X x;124    // CHECK-NEXT: [[I:%.*]] = alloca i32125    // CHECK-NEXT: store i32 17, ptr [[I]]126    int i = 17;127    // CHECK-NEXT: ret void128  }129}130 131// Check that we emit a zero initialization step for list-value-initialization132// which calls a trivial default constructor.133namespace PR13273 {134  struct U {135    int t;136    U() = default;137  };138 139  struct S : U {140    S() = default;141  };142 143  // CHECK: define {{.*}}@_ZN7PR132731fEv(144  int f() {145    // CHECK-NOT: }146    // CHECK: llvm.memset{{.*}}i8 0147    return (new S{})->t;148  }149}150 151template<typename T>152struct X {153  X(const X &);154 155  T *start;156  T *end;157};158 159template<typename T> struct X;160 161// Make sure that the instantiated constructor initializes start and162// end properly.163// CHECK-LABEL: define linkonce_odr void @_ZN1XIiEC2ERKS0_(ptr {{[^,]*}} %this, ptr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %other) unnamed_addr164// CHECK: {{store.*null}}165// CHECK: {{store.*null}}166// CHECK: ret167template<typename T>168X<T>::X(const X &other) : start(0), end(0) { }169 170X<int> get_X(X<int> x) { return x; }171 172namespace PR10720 {173  struct X { 174    X(const X&); 175    X(X&&); 176    X& operator=(const X&);177    X& operator=(X&&);178    ~X(); 179  };180 181  struct pair2 {182    X second[4];183 184    // CHECK-PR10720: define linkonce_odr {{.*}} @_ZN7PR107205pair2aSERKS0_185    // CHECK-PR10720: load186    // CHECK-PR10720: icmp ne187    // CHECK-PR10720-NEXT: br i1188    // CHECK-PR10720: call {{.*}} @_ZN7PR107201XaSERKS0_189    // CHECK-PR10720: ret190    pair2 &operator=(const pair2&) = default;191 192    // CHECK-PR10720: define linkonce_odr {{.*}} @_ZN7PR107205pair2aSEOS0_193    // CHECK-PR10720: load194    // CHECK-PR10720: icmp ne195    // CHECK-PR10720-NEXT: br i1196    // CHECK-PR10720: call {{.*}} @_ZN7PR107201XaSEOS0_197    // CHECK-PR10720: ret198    pair2 &operator=(pair2&&) = default;199 200    // CHECK-PR10720-LABEL: define linkonce_odr void @_ZN7PR107204pairC2ERKS0_201    // CHECK-PR10720-NOT: ret202    // CHECK-PR10720: call void @llvm.memcpy203    // CHECK-PR10720-NEXT: ret void204 205    // CHECK-PR10720-LABEL: define linkonce_odr void @_ZN7PR107205pair2C2ERKS0_206    // CHECK-PR10720-NOT: ret207    // CHECK-PR10720: call void @_ZN7PR107201XC1ERKS0_208    // CHECK-PR10720: icmp eq209    // CHECK-PR10720-NEXT: br i1210    // CHECK-PR10720: ret void211 212    // CHECK-PR10720-LABEL: define linkonce_odr void @_ZN7PR107205pair2C2EOS0_213    // CHECK-PR10720-NOT: ret214    // CHECK-PR10720: load215    // CHECK-PR10720: call void @_ZN7PR107201XC1EOS0_216    // CHECK-PR10720: icmp eq217    // CHECK-PR10720-NEXT: br i1218    // CHECK-PR10720: ret void219    pair2(pair2&&) = default;220 221    pair2(const pair2&) = default;222  };223 224  struct pair : X { // Make the copy constructor non-trivial, so we actually generate it.225    int second[4];226    pair(const pair&) = default;227  };228 229  void foo(const pair &x, const pair2 &x2) {230    pair y(x);231    pair2 y2(x2);232    pair2 y2m(static_cast<pair2&&>(y2));233 234    y2 = x2;235    y2m = static_cast<pair2&&>(y2);236  }237 238}239