blob: c47c83180906b912b97e7b7d56e8e8a96737d3a2 [file] [log] [blame]
Galina Kistanova0ccb31c2011-06-03 22:24:54 +00001// REQUIRES: x86-registered-target,x86-64-registered-target
Daniel Dunbara5728872009-12-15 20:14:24 +00002// RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++0x -S %s -o %t-64.s
Daniel Dunbar4fcfde42009-11-08 01:45:36 +00003// RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s
Daniel Dunbara5728872009-12-15 20:14:24 +00004// RUN: %clang_cc1 -triple i386-apple-darwin -std=c++0x -S %s -o %t-32.s
Daniel Dunbar4fcfde42009-11-08 01:45:36 +00005// RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s
Fariborz Jahanian93034ca2009-10-16 19:20:59 +00006
7extern "C" int printf(...);
Fariborz Jahanian3759a032009-10-19 19:18:20 +00008extern "C" void exit(int);
Fariborz Jahanian93034ca2009-10-16 19:20:59 +00009
10struct A {
Douglas Gregor2f599792010-04-02 18:24:57 +000011 A (const A&) { printf("A::A(const A&)\n"); }
12 A() {};
13 ~A() { printf("A::~A()\n"); }
Fariborz Jahanian93034ca2009-10-16 19:20:59 +000014};
15
16struct B : public A {
17 B() {};
Douglas Gregor2f599792010-04-02 18:24:57 +000018 B(const B& Other) : A(Other) { printf("B::B(const B&)\n"); }
19 ~B() { printf("B::~B()\n"); }
20};
Fariborz Jahanian93034ca2009-10-16 19:20:59 +000021
22struct C : public B {
23 C() {};
Douglas Gregor2f599792010-04-02 18:24:57 +000024 C(const C& Other) : B(Other) { printf("C::C(const C&)\n"); }
25 ~C() { printf("C::~C()\n"); }
Fariborz Jahanian93034ca2009-10-16 19:20:59 +000026};
27
28struct 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"); }
Douglas Gregor2f599792010-04-02 18:24:57 +000033 ~X () { printf("X::~X()\n"); }
Fariborz Jahanian93034ca2009-10-16 19:20:59 +000034 B b;
35 C c;
36};
37
38void f(A) {
39 printf("f(A)\n");
40}
41
42
43void func(X x)
44{
45 f (x);
46}
47
48int main()
49{
50 X x;
51 func(x);
52}
53
Fariborz Jahanian3759a032009-10-19 19:18:20 +000054struct Base;
55
56struct Root {
57 operator Base&() { exit(1); }
58};
59
60struct Derived;
61
62struct Base : Root {
63 Base(const Base&) { printf("Base::(const Base&)\n"); }
64 Base() { printf("Base::Base()\n"); }
65 operator Derived&() { exit(1); }
66};
67
68struct Derived : Base {
69};
70
71void foo(Base) {}
72
73void test(Derived bb)
74{
Sean Callanan3b299012009-12-18 00:04:09 +000075 // CHECK-LP64-NOT: callq __ZN4BasecvR7DerivedEv
76 // CHECK-LP32-NOT: callq L__ZN4BasecvR7DerivedEv
Fariborz Jahanian3759a032009-10-19 19:18:20 +000077 foo(bb);
78}
Sean Callanan3b299012009-12-18 00:04:09 +000079// CHECK-LP64: callq __ZN1XcvR1BEv
80// CHECK-LP64: callq __ZN1AC1ERKS_
Fariborz Jahanian93034ca2009-10-16 19:20:59 +000081
Chris Lattner398e6b92010-09-22 06:09:31 +000082// CHECK-LP32: calll L__ZN1XcvR1BEv
83// CHECK-LP32: calll L__ZN1AC1ERKS_
Fariborz Jahanian3759a032009-10-19 19:18:20 +000084
85