52 lines · cpp
1/// Check that the offset to top calculation is adjusted to account for the2/// omitted RTTI entry.3 4// RUN: %clang_cc1 %s -triple=aarch64-unknown-linux-gnu -fexperimental-omit-vtable-rtti -fno-rtti -o - -emit-llvm | FileCheck -check-prefixes=POINTER %s5// RUN: %clang_cc1 %s -triple=aarch64-unknown-linux-gnu -fexperimental-relative-c++-abi-vtables -fexperimental-omit-vtable-rtti -fno-rtti -o - -emit-llvm | FileCheck -check-prefixes=RELATIVE %s6 7/// Some important things to check:8/// - The n16 here represents the virtual thunk size. Normally this would be 249/// to represent 3 components (offset to top, RTTI component, vcall offset),10/// but since one 8-byte component is removed, this is now 16.11// POINTER-LABEL: @_ZTv0_n16_N7Derived1fEi(12// POINTER-NEXT: entry:13// POINTER: [[vtable:%.+]] = load ptr, ptr %this1, align 814 15/// Same here - When getting the vbase offset, we subtract 2 pointer sizes16/// instead of 3.17// POINTER-NEXT: [[vbase_offset_ptr:%.+]] = getelementptr inbounds i8, ptr [[vtable]], i64 -1618// POINTER-NEXT: [[vbase_offset:%.+]] = load i64, ptr [[vbase_offset_ptr]], align 819// POINTER-NEXT: [[adj_this:%.+]] = getelementptr inbounds i8, ptr %this1, i64 [[vbase_offset]]20// POINTER: [[call:%.+]] = tail call noundef i32 @_ZN7Derived1fEi(ptr noundef{{[^,]*}} [[adj_this]], i32 noundef {{.*}})21// POINTER: ret i32 [[call]]22 23/// For relative vtables, it's almost the same except the offset sizes are24/// halved.25// RELATIVE-LABEL: @_ZTv0_n8_N7Derived1fEi(26// RELATIVE-NEXT: entry:27// RELATIVE: [[vtable:%.+]] = load ptr, ptr %this1, align 828// RELATIVE-NEXT: [[vbase_offset_ptr:%.+]] = getelementptr inbounds i8, ptr [[vtable]], i64 -829// RELATIVE-NEXT: [[vbase_offset:%.+]] = load i32, ptr [[vbase_offset_ptr]], align 430// RELATIVE-NEXT: [[adj_this:%.+]] = getelementptr inbounds i8, ptr %this1, i32 [[vbase_offset]]31// RELATIVE: [[call:%.+]] = tail call noundef i32 @_ZN7Derived1fEi(ptr noundef{{[^,]*}} [[adj_this]], i32 noundef {{.*}})32// RELATIVE: ret i32 [[call]]33 34class Base {35public:36 virtual int f(int x);37 38private:39 long x;40};41 42class Derived : public virtual Base {43public:44 virtual int f(int x);45 46private:47 long y;48};49 50int Base::f(int x) { return x + 1; }51int Derived::f(int x) { return x + 2; }52