brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · 3a4a93c Raw
110 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-darwin10 -emit-llvm -o - %s | FileCheck %s2 3 4struct Spacer { int x; };5struct A { double array[2]; };6struct B : Spacer, A { };7 8B &getB();9 10// CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z4getAv()11// CHECK: call noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z4getBv()12// CHECK-NEXT: getelementptr inbounds i8, ptr13// CHECK-NEXT: ret ptr14A &&getA() { return static_cast<A&&>(getB()); }15 16int &getIntLValue();17int &&getIntXValue();18int getIntPRValue();19 20// CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z2f0v()21// CHECK: call noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z12getIntLValuev()22// CHECK-NEXT: ret ptr23int &&f0() { return static_cast<int&&>(getIntLValue()); }24 25// CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z2f1v()26// CHECK: call noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z12getIntXValuev()27// CHECK-NEXT: ret ptr28int &&f1() { return static_cast<int&&>(getIntXValue()); }29 30// CHECK-LABEL: define{{.*}} nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_Z2f2v31// CHECK: call noundef i32 @_Z13getIntPRValuev()32// CHECK-NEXT: store i32 {{.*}}, ptr33// CHECK-NEXT: ret ptr34int &&f2() { return static_cast<int&&>(getIntPRValue()); }35 36bool ok;37 38class C39{40   int* state_;41 42   C(const C&) = delete;43   C& operator=(const C&) = delete;44public:45  C(int state) : state_(new int(state)) { }46  47  C(C&& a) {48    state_ = a.state_; 49    a.state_ = 0;50  }51 52  ~C() {53    delete state_; 54    state_ = 0;55  }56};57 58C test();59 60// CHECK-LABEL: define{{.*}} void @_Z15elide_copy_initv61void elide_copy_init() {62  ok = false;63  // CHECK: call void @_Z4testv64  C a = test();65  // CHECK-NEXT: call void @_ZN1CD1Ev66  // CHECK-NEXT: ret void67}68 69// CHECK-LABEL: define{{.*}} void @_Z16test_move_returnv70C test_move_return() {71  // CHECK: call void @_ZN1CC1Ei72  C a1(3);73  // CHECK: call void @_ZN1CC1Ei74  C a2(4);75  if (ok)76    // CHECK: call void @_ZN1CC1EOS_77    return a1;78  // CHECK: call void @_ZN1CC1EOS_79  return a2;80  // CHECK: call void @_ZN1CD1Ev81  // CHECK: call void @_ZN1CD1Ev82  //CHECK:  ret void83}84 85// PR10800: don't crash86namespace test1 {87  int &&move(int&);88 89  struct A { A(int); };90  struct B {91    A a;92    B(int i);93  };94 95  // CHECK-LABEL:    define{{.*}} void @_ZN5test11BC2Ei(96  // CHECK:      [[T0:%.*]] = call noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN5test14moveERi(97  // CHECK-NEXT: [[T1:%.*]] = load i32, ptr [[T0]]98  // CHECK-NEXT: call void @_ZN5test11AC1Ei({{.*}}, i32 noundef [[T1]])99  // CHECK-NEXT: ret void100  B::B(int i) : a(move(i)) {}101}102 103// PR11009104struct MoveConvertible {105  operator int&& () const;106};107void moveConstruct() {108  (void)(int)MoveConvertible();109}110