xref: /llvm-project/clang/test/CodeGenCXX/RelativeVTablesABI/vbase-offset.cpp (revision 0d501f38f348cf046d40c9baee12f0c5145b6d8c)
1 // Check that the pointer adjustment from the virtual base offset is loaded as a
2 // 32-bit int.
3 
4 // RUN: %clang_cc1 %s -triple=aarch64-unknown-fuchsia -o - -emit-llvm | FileCheck %s
5 
6 // CHECK-LABEL: @_ZTv0_n12_N7Derived1fEi(
7 // CHECK-NEXT:  entry:
8 // CHECK:        [[vtable:%.+]] = load ptr, ptr %this1, align 8
9 // CHECK-NEXT:   [[vbase_offset_ptr:%.+]] = getelementptr inbounds i8, ptr [[vtable]], i64 -12
10 // CHECK-NEXT:   [[vbase_offset:%.+]] = load i32, ptr [[vbase_offset_ptr]], align 4
11 // CHECK-NEXT:   [[adj_this:%.+]] = getelementptr inbounds i8, ptr %this1, i32 [[vbase_offset]]
12 // CHECK:        [[call:%.+]] = tail call noundef i32 @_ZN7Derived1fEi(ptr noundef{{[^,]*}} [[adj_this]], i32 noundef {{.*}})
13 // CHECK:        ret i32 [[call]]
14 
15 class Base {
16 public:
17   virtual int f(int x);
18 
19 private:
20   long x;
21 };
22 
23 class Derived : public virtual Base {
24 public:
25   virtual int f(int x);
26 
27 private:
28   long y;
29 };
30 
f(int x)31 int Base::f(int x) { return x + 1; }
f(int x)32 int Derived::f(int x) { return x + 2; }
33