brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · a8ce437 Raw
101 lines · cpp
1// RUN: %clang_cc1 %std_cxx11-14 -no-enable-noundef-analysis -triple armv7-none-eabi -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,PRE172// RUN: %clang_cc1 %std_cxx17- -no-enable-noundef-analysis -triple armv7-none-eabi -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,CXX173 4struct A { int x; A(int); ~A(); };5A f() { return A(0); }6// CHECK-LABEL: define{{.*}} void @_Z1fv7// CHECK: call {{.*}} @_ZN1AC1Ei8// CHECK-NEXT: ret void9 10// Verify that we do not elide copies when constructing a base class before C++17.11namespace no_elide_base {12  struct Base { 13    Base(const Base&);14    ~Base();15  };16 17  struct Other {18    operator Base() const;19  };20 21  struct Derived : public virtual Base { 22    Derived(const Other &O);23  };24 25  // CHECK: define {{.*}} @_ZN13no_elide_base7DerivedC1ERKNS_5OtherE(ptr {{[^,]*}} returned {{[^,]*}} %this, ptr nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %O) unnamed_addr26  Derived::Derived(const Other &O) 27    // CHECK: call {{.*}} @_ZNK13no_elide_base5OthercvNS_4BaseEEv28    // PRE17: call {{.*}} @_ZN13no_elide_base4BaseC2ERKS0_29    // PRE17: call {{.*}} @_ZN13no_elide_base4BaseD1Ev30    // CXX17-NOT: call31    : Base(O)32  {33    // CHECK: ret34  }35}36 37// PR8683.38 39namespace PR8683 {40 41struct A {42  A();43  A(const A&);44  A& operator=(const A&);45};46 47struct B {48  A a;49};50 51void f() {52  // Verify that we don't mark the copy constructor in this expression as elidable.53  // CHECK: call {{.*}} @_ZN6PR86831AC1ERKS0_54  A a = (B().a);55}56 57}58 59namespace PR12139 {60  struct A {61    A() : value(1) { }62    A(A const &, int value = 2) : value(value) { }63    int value;64 65    static A makeA() { A a; a.value = 2; return a; }66  };67 68  // CHECK-LABEL: define{{.*}} i32 @_ZN7PR121394testEv69  int test() {70    // CHECK: call void @_ZN7PR121391A5makeAEv71    // CHECK-NEXT: call ptr @_ZN7PR121391AC1ERKS0_i72    A a(A::makeA(), 3);73    // CHECK-NEXT: getelementptr inbounds74    // CHECK-NEXT: load75    // CHECK-NEXT: ret i3276    return a.value;77  }78}79 80namespace ElidableCallIsNotCopyCtor {81  struct A { A(const A&); };82  struct B : A {83    B(B&);84    B(A);85    B(int);86  };87  void f() {88    // Before C++17, we construct via B(int) then B(A). The B(A) construction is89    // elidable, but we don't have an AST representation for the case where we90    // must elide not only a constructor call but also some argument91    // conversions, so we don't elide it.92    // CHECK-LABEL: define{{.*}} void @_ZN25ElidableCallIsNotCopyCtor1fEv(93    // CHECK: call {{.*}} @_ZN25ElidableCallIsNotCopyCtor1BC1Ei(94    // PRE17: call {{.*}} @_ZN25ElidableCallIsNotCopyCtor1AC1ERKS0_(95    // PRE17: call {{.*}} @_ZN25ElidableCallIsNotCopyCtor1BC1ENS_1AE(96    // CXX17-NOT: call97    // CHECK: ret98    B b = 0;99  }100}101