Home | History | Annotate | Download | only in CodeGenCXX
      1 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=i686-unknown-linux | FileCheck --check-prefix=CHECKGEN %s
      2 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=thumbv7-apple-ios6.0 -target-abi apcs-gnu | FileCheck --check-prefix=CHECKARM %s
      3 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=thumbv7-apple-ios5.0 -target-abi apcs-gnu | FileCheck --check-prefix=CHECKIOS5 %s
      4 //RUN: %clang_cc1 %s -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti | FileCheck --check-prefix=CHECKMS %s
      5 // FIXME: these tests crash on the bots when run with -triple=x86_64-pc-win32
      6 
      7 // Make sure we attach the 'returned' attribute to the 'this' parameter of
      8 // constructors and destructors which return this (and only these cases)
      9 
     10 class A {
     11 public:
     12   A();
     13   ~A();
     14 
     15 private:
     16   int x_;
     17 };
     18 
     19 class B : public A {
     20 public:
     21   B(int *i);
     22   ~B();
     23 
     24 private:
     25   int *i_;
     26 };
     27 
     28 B::B(int *i) : i_(i) { }
     29 B::~B() { }
     30 
     31 // CHECKGEN-LABEL: define void @_ZN1BC2EPi(%class.B* %this, i32* %i)
     32 // CHECKGEN-LABEL: define void @_ZN1BC1EPi(%class.B* %this, i32* %i)
     33 // CHECKGEN-LABEL: define void @_ZN1BD2Ev(%class.B* %this)
     34 // CHECKGEN-LABEL: define void @_ZN1BD1Ev(%class.B* %this)
     35 
     36 // CHECKARM-LABEL: define %class.B* @_ZN1BC2EPi(%class.B* returned %this, i32* %i)
     37 // CHECKARM-LABEL: define %class.B* @_ZN1BC1EPi(%class.B* returned %this, i32* %i)
     38 // CHECKARM-LABEL: define %class.B* @_ZN1BD2Ev(%class.B* returned %this)
     39 // CHECKARM-LABEL: define %class.B* @_ZN1BD1Ev(%class.B* returned %this)
     40 
     41 // CHECKIOS5-LABEL: define %class.B* @_ZN1BC2EPi(%class.B* %this, i32* %i)
     42 // CHECKIOS5-LABEL: define %class.B* @_ZN1BC1EPi(%class.B* %this, i32* %i)
     43 // CHECKIOS5-LABEL: define %class.B* @_ZN1BD2Ev(%class.B* %this)
     44 // CHECKIOS5-LABEL: define %class.B* @_ZN1BD1Ev(%class.B* %this)
     45 
     46 // CHECKMS-LABEL: define x86_thiscallcc %class.B* @"\01??0B@@QAE@PAH@Z"(%class.B* returned %this, i32* %i)
     47 // CHECKMS-LABEL: define x86_thiscallcc void @"\01??1B@@QAE@XZ"(%class.B* %this)
     48 
     49 class C : public A, public B {
     50 public:
     51   C(int *i, char *c);
     52   virtual ~C();
     53 private:
     54   char *c_;
     55 };
     56 
     57 C::C(int *i, char *c) : B(i), c_(c) { }
     58 C::~C() { }
     59 
     60 // CHECKGEN-LABEL: define void @_ZN1CC2EPiPc(%class.C* %this, i32* %i, i8* %c)
     61 // CHECKGEN-LABEL: define void @_ZN1CC1EPiPc(%class.C* %this, i32* %i, i8* %c)
     62 // CHECKGEN-LABEL: define void @_ZN1CD2Ev(%class.C* %this)
     63 // CHECKGEN-LABEL: define void @_ZN1CD1Ev(%class.C* %this)
     64 // CHECKGEN-LABEL: define void @_ZN1CD0Ev(%class.C* %this)
     65 
     66 // CHECKARM-LABEL: define %class.C* @_ZN1CC2EPiPc(%class.C* returned %this, i32* %i, i8* %c)
     67 // CHECKARM-LABEL: define %class.C* @_ZN1CC1EPiPc(%class.C* returned %this, i32* %i, i8* %c)
     68 // CHECKARM-LABEL: define %class.C* @_ZN1CD2Ev(%class.C* returned %this)
     69 // CHECKARM-LABEL: define %class.C* @_ZN1CD1Ev(%class.C* returned %this)
     70 // CHECKARM-LABEL: define void @_ZN1CD0Ev(%class.C* %this)
     71 
     72 // CHECKIOS5-LABEL: define %class.C* @_ZN1CC2EPiPc(%class.C* %this, i32* %i, i8* %c)
     73 // CHECKIOS5-LABEL: define %class.C* @_ZN1CC1EPiPc(%class.C* %this, i32* %i, i8* %c)
     74 // CHECKIOS5-LABEL: define %class.C* @_ZN1CD2Ev(%class.C* %this)
     75 // CHECKIOS5-LABEL: define %class.C* @_ZN1CD1Ev(%class.C* %this)
     76 // CHECKIOS5-LABEL: define void @_ZN1CD0Ev(%class.C* %this)
     77 
     78 // CHECKMS-LABEL: define x86_thiscallcc %class.C* @"\01??0C@@QAE@PAHPAD@Z"(%class.C* returned %this, i32* %i, i8* %c)
     79 // CHECKMS-LABEL: define x86_thiscallcc void @"\01??1C@@UAE@XZ"(%class.C* %this)
     80 
     81 class D : public virtual A {
     82 public:
     83   D();
     84   ~D();
     85 };
     86 
     87 D::D() { }
     88 D::~D() { }
     89 
     90 // CHECKGEN-LABEL: define void @_ZN1DC2Ev(%class.D* %this, i8** %vtt)
     91 // CHECKGEN-LABEL: define void @_ZN1DC1Ev(%class.D* %this)
     92 // CHECKGEN-LABEL: define void @_ZN1DD2Ev(%class.D* %this, i8** %vtt)
     93 // CHECKGEN-LABEL: define void @_ZN1DD1Ev(%class.D* %this)
     94 
     95 // CHECKARM-LABEL: define %class.D* @_ZN1DC2Ev(%class.D* returned %this, i8** %vtt)
     96 // CHECKARM-LABEL: define %class.D* @_ZN1DC1Ev(%class.D* returned %this)
     97 // CHECKARM-LABEL: define %class.D* @_ZN1DD2Ev(%class.D* returned %this, i8** %vtt)
     98 // CHECKARM-LABEL: define %class.D* @_ZN1DD1Ev(%class.D* returned %this)
     99 
    100 // CHECKIOS5-LABEL: define %class.D* @_ZN1DC2Ev(%class.D* %this, i8** %vtt)
    101 // CHECKIOS5-LABEL: define %class.D* @_ZN1DC1Ev(%class.D* %this)
    102 // CHECKIOS5-LABEL: define %class.D* @_ZN1DD2Ev(%class.D* %this, i8** %vtt)
    103 // CHECKIOS5-LABEL: define %class.D* @_ZN1DD1Ev(%class.D* %this)
    104 
    105 // CHECKMS-LABEL: define x86_thiscallcc %class.D* @"\01??0D@@QAE@XZ"(%class.D* returned %this, i32 %is_most_derived)
    106 // CHECKMS-LABEL: define x86_thiscallcc void @"\01??1D@@QAE@XZ"(%class.D* %this)
    107 
    108 class E {
    109 public:
    110   E();
    111   virtual ~E();
    112 };
    113 
    114 E* gete();
    115 
    116 void test_destructor() {
    117   const E& e1 = E();
    118   E* e2 = gete();
    119   e2->~E();
    120 }
    121 
    122 // CHECKARM-LABEL: define void @_Z15test_destructorv()
    123 
    124 // Verify that virtual calls to destructors are not marked with a 'returned'
    125 // this parameter at the call site...
    126 // CHECKARM: [[VFN:%.*]] = getelementptr inbounds %class.E* (%class.E*)**
    127 // CHECKARM: [[THUNK:%.*]] = load %class.E* (%class.E*)** [[VFN]]
    128 // CHECKARM: call %class.E* [[THUNK]](%class.E* %
    129 
    130 // ...but static calls create declarations with 'returned' this
    131 // CHECKARM: {{%.*}} = call %class.E* @_ZN1ED1Ev(%class.E* %
    132 
    133 // CHECKARM: declare %class.E* @_ZN1ED1Ev(%class.E* returned)
    134