Home | History | Annotate | Download | only in CodeGenCXX
      1 // REQUIRES: x86-registered-target,x86-64-registered-target
      2 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -S %s -o %t-64.s
      3 // RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s
      4 // RUN: %clang_cc1 -triple i386-apple-darwin -std=c++11 -S %s -o %t-32.s
      5 // RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s
      6 
      7 extern "C" int printf(...);
      8 extern "C" void exit(int);
      9 
     10 struct A {
     11   A (const A&) { printf("A::A(const A&)\n"); }
     12   A() {};
     13   ~A() { printf("A::~A()\n"); }
     14 };
     15 
     16 struct B : public A {
     17   B() {};
     18   B(const B& Other) : A(Other) { printf("B::B(const B&)\n"); }
     19   ~B() { printf("B::~B()\n"); }
     20 };
     21 
     22 struct C : public B {
     23   C() {};
     24   C(const C& Other) : B(Other) { printf("C::C(const C&)\n"); }
     25   ~C() { printf("C::~C()\n"); }
     26 };
     27 
     28 struct X {
     29 	operator B&() {printf("X::operator B&()\n"); return b; }
     30 	operator C&() {printf("X::operator C&()\n"); return c; }
     31  	X (const X&) { printf("X::X(const X&)\n"); }
     32  	X () { printf("X::X()\n"); }
     33  	~X () { printf("X::~X()\n"); }
     34 	B b;
     35 	C c;
     36 };
     37 
     38 void f(A) {
     39   printf("f(A)\n");
     40 }
     41 
     42 
     43 void func(X x)
     44 {
     45   f (x);
     46 }
     47 
     48 int main()
     49 {
     50     X x;
     51     func(x);
     52 }
     53 
     54 struct Base;
     55 
     56 struct Root {
     57   operator Base&() { exit(1); }
     58 };
     59 
     60 struct Derived;
     61 
     62 struct Base : Root {
     63   Base(const Base&) { printf("Base::(const Base&)\n"); }
     64   Base() { printf("Base::Base()\n"); }
     65   operator Derived&() { exit(1); }
     66 };
     67 
     68 struct Derived : Base {
     69 };
     70 
     71 void foo(Base) {}
     72 
     73 void test(Derived bb)
     74 {
     75 	// CHECK-LP64-NOT: callq    __ZN4BasecvR7DerivedEv
     76 	// CHECK-LP32-NOT: callq    L__ZN4BasecvR7DerivedEv
     77         foo(bb);
     78 }
     79 // CHECK-LP64: callq    __ZN1XcvR1BEv
     80 // CHECK-LP64: callq    __ZN1AC1ERKS_
     81 
     82 // CHECK-LP32: calll     L__ZN1XcvR1BEv
     83 // CHECK-LP32: calll     L__ZN1AC1ERKS_
     84 
     85 
     86