xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/derived-to-base.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
2*f4a2713aSLionel Sambuc struct A {
3*f4a2713aSLionel Sambuc   void f();
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc   int a;
6*f4a2713aSLionel Sambuc };
7*f4a2713aSLionel Sambuc 
8*f4a2713aSLionel Sambuc struct B : A {
9*f4a2713aSLionel Sambuc   double b;
10*f4a2713aSLionel Sambuc };
11*f4a2713aSLionel Sambuc 
f()12*f4a2713aSLionel Sambuc void f() {
13*f4a2713aSLionel Sambuc   B b;
14*f4a2713aSLionel Sambuc 
15*f4a2713aSLionel Sambuc   b.f();
16*f4a2713aSLionel Sambuc }
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc // CHECK: define %struct.B* @_Z1fP1A(%struct.A* %a) [[NUW:#[0-9]+]]
f(A * a)19*f4a2713aSLionel Sambuc B *f(A *a) {
20*f4a2713aSLionel Sambuc   // CHECK-NOT: br label
21*f4a2713aSLionel Sambuc   // CHECK: ret %struct.B*
22*f4a2713aSLionel Sambuc   return static_cast<B*>(a);
23*f4a2713aSLionel Sambuc }
24*f4a2713aSLionel Sambuc 
25*f4a2713aSLionel Sambuc // PR5965
26*f4a2713aSLionel Sambuc namespace PR5965 {
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc // CHECK: define %struct.A* @_ZN6PR59651fEP1B(%struct.B* %b) [[NUW]]
f(B * b)29*f4a2713aSLionel Sambuc A *f(B* b) {
30*f4a2713aSLionel Sambuc   // CHECK-NOT: br label
31*f4a2713aSLionel Sambuc   // CHECK: ret %struct.A*
32*f4a2713aSLionel Sambuc   return b;
33*f4a2713aSLionel Sambuc }
34*f4a2713aSLionel Sambuc 
35*f4a2713aSLionel Sambuc }
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc // Don't crash on a derived-to-base conversion of an r-value
38*f4a2713aSLionel Sambuc // aggregate.
39*f4a2713aSLionel Sambuc namespace test3 {
40*f4a2713aSLionel Sambuc   struct A {};
41*f4a2713aSLionel Sambuc   struct B : A {};
42*f4a2713aSLionel Sambuc 
43*f4a2713aSLionel Sambuc   void foo(A a);
test()44*f4a2713aSLionel Sambuc   void test() {
45*f4a2713aSLionel Sambuc     foo(B());
46*f4a2713aSLionel Sambuc   }
47*f4a2713aSLionel Sambuc }
48*f4a2713aSLionel Sambuc 
49*f4a2713aSLionel Sambuc // CHECK: attributes [[NUW]] = { nounwind{{.*}} }
50