[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / CodeGenCXX / derived-to-base-conv.cpp
blob8ba98020707c231c270e2fca5379ff223eb09206
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++11 -emit-llvm %s -o - | FileCheck %s
3 struct A {
4 A(const A&);
5 A();
6 ~A();
7 };
9 struct B : public A {
10 B();
11 B(const B& Other);
12 ~B();
15 struct C : public B {
16 C();
17 C(const C& Other);
18 ~C();
19 };
21 struct X {
22 operator B&();
23 operator C&();
24 X(const X&);
25 X();
26 ~X();
27 B b;
28 C c;
31 void test0_helper(A);
32 void test0(X x) {
33 test0_helper(x);
34 // CHECK-LABEL: define{{.*}} void @_Z5test01X(
35 // CHECK-SAME: ptr noundef [[ARG:%.*]])
36 // CHECK: [[ARG_ADDR:%.*]] = alloca ptr
37 // CHECK-NEXT: [[TMP:%.*]] = alloca [[A:%.*]], align
38 // CHECK-NEXT: store ptr [[ARG]], ptr [[ARG_ADDR]]
39 // CHECK-NEXT: [[T0:%.*]] = call noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) ptr @_ZN1XcvR1BEv(
40 // CHECK-NEXT: call void @_ZN1AC1ERKS_(ptr {{[^,]*}} [[TMP]], ptr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) [[T0]])
41 // CHECK-NEXT: call void @_Z12test0_helper1A(ptr noundef [[TMP]])
42 // CHECK-NEXT: call void @_ZN1AD1Ev(ptr {{[^,]*}} [[TMP]])
43 // CHECK-NEXT: ret void
46 struct Base;
48 struct Root {
49 operator Base&();
52 struct Derived;
54 struct Base : Root {
55 Base(const Base &);
56 Base();
57 operator Derived &();
60 struct Derived : Base {
63 void test1_helper(Base);
64 void test1(Derived bb) {
65 // CHECK-LABEL: define{{.*}} void @_Z5test17Derived(
66 // CHECK-NOT: call {{.*}} @_ZN4BasecvR7DerivedEv(
67 // CHECK: call void @_ZN4BaseC1ERKS_(
68 // CHECK-NOT: call {{.*}} @_ZN4BasecvR7DerivedEv(
69 // CHECK: call void @_Z12test1_helper4Base(
70 test1_helper(bb);
73 // Don't crash after devirtualizing a derived-to-base conversion
74 // to an empty base allocated at offset zero.
75 // rdar://problem/11993704
76 class Test2a {};
77 class Test2b final : public virtual Test2a {};
78 void test2(Test2b &x) {
79 Test2a &y = x;
80 // CHECK-LABEL: define{{.*}} void @_Z5test2R6Test2b(
81 // CHECK: [[X:%.*]] = alloca ptr, align 8
82 // CHECK-NEXT: [[Y:%.*]] = alloca ptr, align 8
83 // CHECK-NEXT: store ptr {{%.*}}, ptr [[X]], align 8
84 // CHECK-NEXT: [[T0:%.*]] = load ptr, ptr [[X]], align 8
85 // CHECK-NEXT: store ptr [[T0]], ptr [[Y]], align 8
86 // CHECK-NEXT: ret void