Skip to content

[CIR] Add special type for vtables #1745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -2596,13 +2596,13 @@ def CIR_VTableAddrPointOp : CIR_Op<"vtable.address_point",[
(as specified by Itanium ABI), and `address_point.offset` (address point index) the actual address
point within that vtable.

The return type is always a `!cir.ptr<!cir.ptr<() -> i32>>`.
The return type is always a `!cir.ptr<!cir.vtable>`.

Example:
```mlir
cir.global linkonce_odr @_ZTV1B = ...
...
%3 = cir.vtable.address_point(@_ZTV1B, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.ptr<() -> i32>>
%3 = cir.vtable.address_point(@_ZTV1B, address_point = <index = 0, offset = 2>) : !cir.vtable_ptr
```
}];

Expand Down
10 changes: 9 additions & 1 deletion clang/include/clang/CIR/Dialect/IR/CIRTypeConstraints.td
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,21 @@ def CIR_PtrToExceptionInfoType
def CIR_AnyDataMemberType : CIR_TypeBase<"::cir::DataMemberType",
"data member type">;

//===----------------------------------------------------------------------===//
// VTable type predicates
//===----------------------------------------------------------------------===//

def CIR_AnyVTableType : CIR_TypeBase<"::cir::VTableType",
"vtable type">;

Comment on lines +270 to +272
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def CIR_AnyVTableType : CIR_TypeBase<"::cir::VTableType",
"vtable type">;
def CIR_AnyVTableType : CIR_TypeBase<"::cir::VTableType", "vtable type">;


//===----------------------------------------------------------------------===//
// Scalar Type predicates
//===----------------------------------------------------------------------===//

defvar CIR_ScalarTypes = [
CIR_AnyBoolType, CIR_AnyIntType, CIR_AnyFloatType, CIR_AnyPtrType,
CIR_AnyDataMemberType
CIR_AnyDataMemberType, CIR_AnyVTableType
];

def CIR_AnyScalarType : AnyTypeOf<CIR_ScalarTypes, "cir scalar type"> {
Expand Down
19 changes: 18 additions & 1 deletion clang/include/clang/CIR/Dialect/IR/CIRTypes.td
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,22 @@ def CIR_DataMemberType : CIR_Type<"DataMember", "data_member",
}];
}

//===----------------------------------------------------------------------===//
// CIR_VTableType
//===----------------------------------------------------------------------===//

def CIR_VTableType : CIR_Type<"VTable", "vtable",
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {

Comment on lines +350 to +352
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def CIR_VTableType : CIR_Type<"VTable", "vtable",
[DeclareTypeInterfaceMethods<DataLayoutTypeInterface>]> {
def CIR_VTableType : CIR_Type<"VTable", "vtable", [
DeclareTypeInterfaceMethods<DataLayoutTypeInterface>
]> {

let summary = "CIR type that is used for pointers that point to a C++ vtable";
let description = [{
`cir.vtable` is a special type used as the pointee type for pointers to
vtables. This avoids using arbitrary pointer types to declare vtable
pointer values.
}];
}


//===----------------------------------------------------------------------===//
// BoolType
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -751,7 +767,8 @@ def CIRRecordType : Type<
def CIR_AnyType : AnyTypeOf<[
CIR_IntType, CIR_PointerType, CIR_DataMemberType, CIR_MethodType,
CIR_BoolType, CIR_ArrayType, CIR_VectorType, CIR_FuncType, CIR_VoidType,
CIR_RecordType, CIR_ExceptionType, CIR_AnyFloatType, CIR_ComplexType
CIR_RecordType, CIR_ExceptionType, CIR_AnyFloatType, CIR_ComplexType,
CIR_VTableType
]>;

#endif // MLIR_CIR_DIALECT_CIR_TYPES
8 changes: 2 additions & 6 deletions clang/lib/CIR/CodeGen/CIRGenBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
llvm_unreachable("unsupported long double format");
}

mlir::Type getVirtualFnPtrType(bool isVarArg = false) {
// FIXME: replay LLVM codegen for now, perhaps add a vtable ptr special
// type so it's a bit more clear and C++ idiomatic.
auto fnTy = cir::FuncType::get({}, getUInt32Ty(), isVarArg);
assert(!cir::MissingFeatures::isVarArg());
return getPointerTo(getPointerTo(fnTy));
mlir::Type getVirtualFnPtrType() {
return cir::PointerType::get(cir::VTableType::get(getContext()));
}

cir::FuncType getFuncType(llvm::ArrayRef<mlir::Type> params, mlir::Type retTy,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenItaniumCXXABI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ CIRGenItaniumCXXABI::getVTableAddressPoint(BaseSubobject Base,
.getAddressPoint(Base);

auto &builder = CGM.getBuilder();
auto vtablePtrTy = builder.getVirtualFnPtrType(/*isVarArg=*/false);
auto vtablePtrTy = builder.getVirtualFnPtrType();

return builder.create<cir::VTableAddrPointOp>(
CGM.getLoc(VTableClass->getSourceRange()), vtablePtrTy,
Expand Down
2 changes: 0 additions & 2 deletions clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,6 @@ void CIRRecordLowering::accumulateVPtrs() {
}

mlir::Type CIRRecordLowering::getVFPtrType() {
// FIXME: replay LLVM codegen for now, perhaps add a vtable ptr special
// type so it's a bit more clear and C++ idiomatic.
return builder.getVirtualFnPtrType();
}

Expand Down
5 changes: 1 addition & 4 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2423,10 +2423,7 @@ LogicalResult cir::VTableAddrPointOp::verify() {
return success();

auto resultType = getAddr().getType();
auto intTy = cir::IntType::get(getContext(), 32, /*isSigned=*/false);
auto fnTy = cir::FuncType::get({}, intTy);

auto resTy = cir::PointerType::get(cir::PointerType::get(fnTy));
auto resTy = cir::PointerType::get(cir::VTableType::get(getContext()));

if (resultType != resTy)
return emitOpError("result type must be '")
Expand Down
14 changes: 14 additions & 0 deletions clang/lib/CIR/Dialect/IR/CIRTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,20 @@ DataMemberType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
return 8;
}

llvm::TypeSize
VTableType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
// FIXME: consider size differences under different ABIs
return llvm::TypeSize::getFixed(64);
}

uint64_t
VTableType::getABIAlignment(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
// FIXME: consider alignment differences under different ABIs
return 8;
}

llvm::TypeSize
ArrayType::getTypeSizeInBits(const ::mlir::DataLayout &dataLayout,
::mlir::DataLayoutEntryListRef params) const {
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/dtors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class B : public A
};

// Class A
// CHECK: ![[ClassA:rec_.*]] = !cir.record<class "A" {!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>} #cir.record.decl.ast>
// CHECK: ![[ClassA:rec_.*]] = !cir.record<class "A" {!cir.ptr<!cir.vtable>} #cir.record.decl.ast>

// Class B
// CHECK: ![[ClassB:rec_.*]] = !cir.record<class "B" {![[ClassA]]}>
Expand Down
16 changes: 8 additions & 8 deletions clang/test/CIR/CodeGen/dynamic-cast-exact.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ struct Derived final : Base1 {};
Derived *ptr_cast(Base1 *ptr) {
return dynamic_cast<Derived *>(ptr);
// CHECK: %[[#SRC:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!rec_Base1>>, !cir.ptr<!rec_Base1>
// CHECK-NEXT: %[[#EXPECTED_VPTR:]] = cir.vtable.address_point(@_ZTV7Derived, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
// CHECK-NEXT: %[[#SRC_VPTR_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr<!rec_Base1>), !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
// CHECK-NEXT: %[[#SRC_VPTR:]] = cir.load{{.*}} %[[#SRC_VPTR_PTR]] : !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>, !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
// CHECK-NEXT: %[[#SUCCESS:]] = cir.cmp(eq, %[[#SRC_VPTR]], %[[#EXPECTED_VPTR]]) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.bool
// CHECK-NEXT: %[[#EXPECTED_VPTR:]] = cir.vtable.address_point(@_ZTV7Derived, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.vtable>
// CHECK-NEXT: %[[#SRC_VPTR_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr<!rec_Base1>), !cir.ptr<!cir.ptr<!cir.vtable>>
// CHECK-NEXT: %[[#SRC_VPTR:]] = cir.load{{.*}} %[[#SRC_VPTR_PTR]] : !cir.ptr<!cir.ptr<!cir.vtable>>, !cir.ptr<!cir.vtable>
// CHECK-NEXT: %[[#SUCCESS:]] = cir.cmp(eq, %[[#SRC_VPTR]], %[[#EXPECTED_VPTR]]) : !cir.ptr<!cir.vtable>, !cir.bool
// CHECK-NEXT: %{{.+}} = cir.ternary(%[[#SUCCESS]], true {
// CHECK-NEXT: %[[#RES:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr<!rec_Base1>), !cir.ptr<!rec_Derived>
// CHECK-NEXT: cir.yield %[[#RES]] : !cir.ptr<!rec_Derived>
Expand All @@ -39,10 +39,10 @@ Derived *ptr_cast(Base1 *ptr) {
Derived &ref_cast(Base1 &ref) {
return dynamic_cast<Derived &>(ref);
// CHECK: %[[#SRC:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!cir.ptr<!rec_Base1>>, !cir.ptr<!rec_Base1>
// CHECK-NEXT: %[[#EXPECTED_VPTR:]] = cir.vtable.address_point(@_ZTV7Derived, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
// CHECK-NEXT: %[[#SRC_VPTR_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr<!rec_Base1>), !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
// CHECK-NEXT: %[[#SRC_VPTR:]] = cir.load{{.*}} %[[#SRC_VPTR_PTR]] : !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>, !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
// CHECK-NEXT: %[[#SUCCESS:]] = cir.cmp(eq, %[[#SRC_VPTR]], %[[#EXPECTED_VPTR]]) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.bool
// CHECK-NEXT: %[[#EXPECTED_VPTR:]] = cir.vtable.address_point(@_ZTV7Derived, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.vtable>
// CHECK-NEXT: %[[#SRC_VPTR_PTR:]] = cir.cast(bitcast, %[[#SRC]] : !cir.ptr<!rec_Base1>), !cir.ptr<!cir.ptr<!cir.vtable>>
// CHECK-NEXT: %[[#SRC_VPTR:]] = cir.load{{.*}} %[[#SRC_VPTR_PTR]] : !cir.ptr<!cir.ptr<!cir.vtable>>, !cir.ptr<!cir.vtable>
// CHECK-NEXT: %[[#SUCCESS:]] = cir.cmp(eq, %[[#SRC_VPTR]], %[[#EXPECTED_VPTR]]) : !cir.ptr<!cir.vtable>, !cir.bool
// CHECK-NEXT: %[[#FAILED:]] = cir.unary(not, %[[#SUCCESS]]) : !cir.bool, !cir.bool
// CHECK-NEXT: cir.if %[[#FAILED]] {
// CHECK-NEXT: cir.call @__cxa_bad_cast() : () -> ()
Expand Down
12 changes: 7 additions & 5 deletions clang/test/CIR/CodeGen/dynamic-cast.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -fclangir -emit-cir -mmlir --mlir-print-ir-before=cir-lowering-prepare %s -o %t.cir 2>&1 | FileCheck %s -check-prefix=BEFORE
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -fclangir -emit-cir -mmlir --mlir-print-ir-after=cir-lowering-prepare %s -o %t.cir 2>&1 | FileCheck %s -check-prefix=AFTER
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -fclangir -emit-cir -mmlir --mlir-print-ir-before=cir-lowering-prepare %s -o %t.cir 2> %t.before.log
// RUN: FileCheck %s --input-file=%t.before.log -check-prefix=BEFORE
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -fclangir -emit-cir -mmlir --mlir-print-ir-after=cir-lowering-prepare %s -o %t.cir 2> %t.after.log
// RUN: FileCheck %s --input-file=%t.after.log -check-prefix=AFTER

struct Base {
virtual ~Base();
};

struct Derived : Base {};

// BEFORE: #dyn_cast_info__ZTI4Base__ZTI7Derived = #cir.dyn_cast_info<#cir.global_view<@_ZTI4Base> : !cir.ptr<!u8i>, #cir.global_view<@_ZTI7Derived> : !cir.ptr<!u8i>, @__dynamic_cast, @__cxa_bad_cast, #cir.int<0> : !s64i>
// BEFORE: !rec_Base = !cir.record
// BEFORE: !rec_Derived = !cir.record
// BEFORE-DAG: #dyn_cast_info__ZTI4Base__ZTI7Derived = #cir.dyn_cast_info<#cir.global_view<@_ZTI4Base> : !cir.ptr<!u8i>, #cir.global_view<@_ZTI7Derived> : !cir.ptr<!u8i>, @__dynamic_cast, @__cxa_bad_cast, #cir.int<0> : !s64i>
// BEFORE-DAG: !rec_Base = !cir.record
// BEFORE-DAG: !rec_Derived = !cir.record

Derived *ptr_cast(Base *b) {
return dynamic_cast<Derived *>(b);
Expand Down
34 changes: 17 additions & 17 deletions clang/test/CIR/CodeGen/multi-vtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ int main() {
return 0;
}

// CIR: ![[VTypeInfoA:rec_.*]] = !cir.record<struct {!cir.ptr<!u8i>, !cir.ptr<!u8i>}>
// CIR: ![[VTypeInfoB:rec_.*]] = !cir.record<struct {!cir.ptr<!u8i>, !cir.ptr<!u8i>, !u32i, !u32i, !cir.ptr<!u8i>, !s64i, !cir.ptr<!u8i>, !s64i}>
// CIR: ![[VTableTypeMother:rec_.*]] = !cir.record<struct {!cir.array<!cir.ptr<!u8i> x 4>}>
// CIR: ![[VTableTypeFather:rec_.*]] = !cir.record<struct {!cir.array<!cir.ptr<!u8i> x 3>}>
// CIR: ![[VTableTypeChild:rec_.*]] = !cir.record<struct {!cir.array<!cir.ptr<!u8i> x 4>, !cir.array<!cir.ptr<!u8i> x 3>}>
// CIR: !rec_Father = !cir.record<class "Father" {!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>} #cir.record.decl.ast>
// CIR: !rec_Mother = !cir.record<class "Mother" {!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>} #cir.record.decl.ast>
// CIR: !rec_Child = !cir.record<class "Child" {!rec_Mother, !rec_Father} #cir.record.decl.ast>
// CIR-DAG: ![[VTypeInfoA:rec_.*]] = !cir.record<struct {!cir.ptr<!u8i>, !cir.ptr<!u8i>}>
// CIR-DAG: ![[VTypeInfoB:rec_.*]] = !cir.record<struct {!cir.ptr<!u8i>, !cir.ptr<!u8i>, !u32i, !u32i, !cir.ptr<!u8i>, !s64i, !cir.ptr<!u8i>, !s64i}>
// CIR-DAG: ![[VTableTypeMother:rec_.*]] = !cir.record<struct {!cir.array<!cir.ptr<!u8i> x 4>}>
// CIR-DAG: ![[VTableTypeFather:rec_.*]] = !cir.record<struct {!cir.array<!cir.ptr<!u8i> x 3>}>
// CIR-DAG: ![[VTableTypeChild:rec_.*]] = !cir.record<struct {!cir.array<!cir.ptr<!u8i> x 4>, !cir.array<!cir.ptr<!u8i> x 3>}>
// CIR-DAG: !rec_Father = !cir.record<class "Father" {!cir.ptr<!cir.vtable>} #cir.record.decl.ast>
// CIR-DAG: !rec_Mother = !cir.record<class "Mother" {!cir.ptr<!cir.vtable>} #cir.record.decl.ast>
// CIR-DAG: !rec_Child = !cir.record<class "Child" {!rec_Mother, !rec_Father} #cir.record.decl.ast>

// CIR: cir.func linkonce_odr @_ZN6MotherC2Ev(%arg0: !cir.ptr<!rec_Mother>
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV6Mother, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
// CIR: %{{[0-9]+}} = cir.cast(bitcast, %{{[0-9]+}} : !cir.ptr<!rec_Mother>), !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
// CIR: cir.store{{.*}} %2, %{{[0-9]+}} : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV6Mother, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.vtable>
// CIR: %{{[0-9]+}} = cir.cast(bitcast, %{{[0-9]+}} : !cir.ptr<!rec_Mother>), !cir.ptr<!cir.ptr<!cir.vtable>>
// CIR: cir.store{{.*}} %2, %{{[0-9]+}} : !cir.ptr<!cir.vtable>, !cir.ptr<!cir.ptr<!cir.vtable>>
// CIR: cir.return
// CIR: }

Expand All @@ -52,13 +52,13 @@ int main() {
// LLVM-DAG: }

// CIR: cir.func linkonce_odr @_ZN5ChildC2Ev(%arg0: !cir.ptr<!rec_Child>
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV5Child, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
// CIR: %{{[0-9]+}} = cir.cast(bitcast, %{{[0-9]+}} : !cir.ptr<!rec_Child>), !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
// CIR: cir.store{{.*}} %{{[0-9]+}}, %{{[0-9]+}} : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV5Child, address_point = <index = 1, offset = 2>) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV5Child, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.vtable>
// CIR: %{{[0-9]+}} = cir.cast(bitcast, %{{[0-9]+}} : !cir.ptr<!rec_Child>), !cir.ptr<!cir.ptr<!cir.vtable>>
// CIR: cir.store{{.*}} %{{[0-9]+}}, %{{[0-9]+}} : !cir.ptr<!cir.vtable>, !cir.ptr<!cir.ptr<!cir.vtable>>
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV5Child, address_point = <index = 1, offset = 2>) : !cir.ptr<!cir.vtable>
// CIR: %7 = cir.base_class_addr %1 : !cir.ptr<!rec_Child> nonnull [8] -> !cir.ptr<!rec_Father>
// CIR: %8 = cir.cast(bitcast, %7 : !cir.ptr<!rec_Father>), !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>> loc(#loc8)
// CIR: cir.store{{.*}} %{{[0-9]+}}, %{{[0-9]+}} : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
// CIR: %8 = cir.cast(bitcast, %7 : !cir.ptr<!rec_Father>), !cir.ptr<!cir.ptr<!cir.vtable>> loc(#loc8)
// CIR: cir.store{{.*}} %{{[0-9]+}}, %{{[0-9]+}} : !cir.ptr<!cir.vtable>, !cir.ptr<!cir.ptr<!cir.vtable>>
// CIR: cir.return
// CIR: }

Expand Down
4 changes: 2 additions & 2 deletions clang/test/CIR/CodeGen/tbaa-vptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

// NO-TBAA-NOT: !tbaa

// CIR: #tbaa[[VPTR:.*]] = #cir.tbaa_vptr<type = !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
// CIR: #tbaa[[VPTR:.*]] = #cir.tbaa_vptr<type = !cir.ptr<!cir.vtable>>

struct Member {
~Member();
Expand All @@ -26,7 +26,7 @@ struct B : A {
B::~B() { }

// CIR-LABEL: _ZN1BD2Ev
// CIR: cir.store{{.*}} %{{.*}}, %{{.*}} : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>> tbaa(#tbaa[[VPTR]])
// CIR: cir.store{{.*}} %{{.*}}, %{{.*}} : !cir.ptr<!cir.vtable>, !cir.ptr<!cir.ptr<!cir.vtable>> tbaa(#tbaa[[VPTR]])

// LLVM-LABEL: _ZN1BD2Ev
// LLVM: store ptr getelementptr inbounds nuw (i8, ptr @_ZTV1B, i64 16), ptr %{{.*}}, align 8, !tbaa ![[TBAA_VPTR:.*]]
Expand Down
26 changes: 13 additions & 13 deletions clang/test/CIR/CodeGen/vtable-rtti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ class B : public A
};

// Type info B.
// CHECK: ![[TypeInfoB:rec_.*]] = !cir.record<struct {!cir.ptr<!u8i>, !cir.ptr<!u8i>, !cir.ptr<!u8i>}>
// CHECK-DAG: ![[TypeInfoB:rec_.*]] = !cir.record<struct {!cir.ptr<!u8i>, !cir.ptr<!u8i>, !cir.ptr<!u8i>}>

// vtable for A type
// CHECK: ![[VTableTypeA:rec_.*]] = !cir.record<struct {!cir.array<!cir.ptr<!u8i> x 5>}>
// RTTI_DISABLED: ![[VTableTypeA:rec_.*]] = !cir.record<struct {!cir.array<!cir.ptr<!u8i> x 5>}>
// CHECK-DAG: ![[VTableTypeA:rec_.*]] = !cir.record<struct {!cir.array<!cir.ptr<!u8i> x 5>}>
// RTTI_DISABLED-DAG: ![[VTableTypeA:rec_.*]] = !cir.record<struct {!cir.array<!cir.ptr<!u8i> x 5>}>

// Class A
// CHECK: ![[ClassA:rec_.*]] = !cir.record<class "A" {!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>} #cir.record.decl.ast>
// RTTI_DISABLED: ![[ClassA:rec_.*]] = !cir.record<class "A" {!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>} #cir.record.decl.ast>
// CHECK-DAG: ![[ClassA:rec_.*]] = !cir.record<class "A" {!cir.ptr<!cir.vtable>} #cir.record.decl.ast>
// RTTI_DISABLED-DAG: ![[ClassA:rec_.*]] = !cir.record<class "A" {!cir.ptr<!cir.vtable>} #cir.record.decl.ast>

// Class B
// CHECK: ![[ClassB:rec_.*]] = !cir.record<class "B" {![[ClassA]]}>
// RTTI_DISABLED: ![[ClassB:rec_.*]] = !cir.record<class "B" {![[ClassA]]}>
// CHECK-DAG: ![[ClassB:rec_.*]] = !cir.record<class "B" {![[ClassA]]}>
// RTTI_DISABLED-DAG: ![[ClassB:rec_.*]] = !cir.record<class "B" {![[ClassA]]}>

// B ctor => @B::B()
// Calls @A::A() and initialize __vptr with address of B's vtable.
Expand All @@ -45,9 +45,9 @@ class B : public A
// CHECK: %1 = cir.load %0 : !cir.ptr<!cir.ptr<![[ClassB]]>>, !cir.ptr<![[ClassB]]>
// CHECK: %2 = cir.base_class_addr %1 : !cir.ptr<![[ClassB]]> nonnull [0] -> !cir.ptr<![[ClassA]]>
// CHECK: cir.call @_ZN1AC2Ev(%2) : (!cir.ptr<![[ClassA]]>) -> ()
// CHECK: %3 = cir.vtable.address_point(@_ZTV1B, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
// CHECK: %4 = cir.cast(bitcast, %1 : !cir.ptr<![[ClassB]]>), !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
// CHECK: cir.store{{.*}} %3, %4 : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
// CHECK: %3 = cir.vtable.address_point(@_ZTV1B, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.vtable>
// CHECK: %4 = cir.cast(bitcast, %1 : !cir.ptr<![[ClassB]]>), !cir.ptr<!cir.ptr<!cir.vtable>>
// CHECK: cir.store{{.*}} %3, %4 : !cir.ptr<!cir.vtable>, !cir.ptr<!cir.ptr<!cir.vtable>>
// CHECK: cir.return
// CHECK: }

Expand All @@ -73,9 +73,9 @@ class B : public A
// CHECK: %0 = cir.alloca !cir.ptr<![[ClassA]]>, !cir.ptr<!cir.ptr<![[ClassA]]>>, ["this", init] {alignment = 8 : i64}
// CHECK: cir.store{{.*}} %arg0, %0 : !cir.ptr<![[ClassA]]>, !cir.ptr<!cir.ptr<![[ClassA]]>>
// CHECK: %1 = cir.load %0 : !cir.ptr<!cir.ptr<![[ClassA]]>>, !cir.ptr<![[ClassA]]>
// CHECK: %2 = cir.vtable.address_point(@_ZTV1A, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
// CHECK: %3 = cir.cast(bitcast, %1 : !cir.ptr<![[ClassA]]>), !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
// CHECK: cir.store{{.*}} %2, %3 : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
// CHECK: %2 = cir.vtable.address_point(@_ZTV1A, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.vtable>
// CHECK: %3 = cir.cast(bitcast, %1 : !cir.ptr<![[ClassA]]>), !cir.ptr<!cir.ptr<!cir.vtable>>
// CHECK: cir.store{{.*}} %2, %3 : !cir.ptr<!cir.vtable>, !cir.ptr<!cir.ptr<!cir.vtable>>
// CHECK: cir.return
// CHECK: }

Expand Down
Loading
Loading