Debian Codegraph @

clang/test/CodeGenCXX/derived-to-base.cpp

raw
1 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
2 struct A {
3 void f();
4
5 int a;
6 };
7
8 struct B : A {
9 double b;
10 };
11
12 void f() {
13 B b;
14
15 b.f();
16 }
17
18 // CHECK: define{{.*}} ptr @_Z1fP1A(ptr noundef %a) [[NUW:#[0-9]+]]
19 B *f(A *a) {
20 // CHECK-NOT: br label
21 // CHECK: ret ptr
22 return static_cast<B*>(a);
23 }
24
25 // PR5965
26 namespace PR5965 {
27
28 // CHECK: define{{.*}} ptr @_ZN6PR59651fEP1B(ptr noundef %b) [[NUW]]
29 A *f(B* b) {
30 // CHECK-NOT: br label
31 // CHECK: ret ptr
32 return b;
33 }
34
35 }
36
37 // Don't crash on a derived-to-base conversion of an r-value
38 // aggregate.
39 namespace test3 {
40 struct A {};
41 struct B : A {};
42
43 void foo(A a);
44 void test() {
45 foo(B());
46 }
47 }
48
49 // Ensure volatile is preserved during derived-to-base conversion.
50 namespace PR127683 {
51
52 struct Base {
53 int Val;
54 };
55
56 struct Derived : Base { };
57
58 volatile Derived Obj;
59
60 // CHECK-LABEL: define void @_ZN8PR12768319test_volatile_storeEv()
61 // CHECK: store volatile i32 0, ptr @_ZN8PR1276833ObjE, align 4
62 void test_volatile_store() {
63 Obj.Val = 0;
64 }
65
66 // CHECK-LABEL: define void @_ZN8PR12768318test_volatile_loadEv()
67 // CHECK: %0 = load volatile i32, ptr @_ZN8PR1276833ObjE, align 4
68 void test_volatile_load() {
69 [[maybe_unused]] int Val = Obj.Val;
70 }
71
72 }
73
74 // CHECK: attributes [[NUW]] = { mustprogress noinline nounwind{{.*}} }