brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.1 KiB · d8ac436 Raw
128 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -fclangir -mconstructor-aliases -emit-cir %s -o %t.cir2// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s3// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -fclangir -mconstructor-aliases -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s5// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 -mconstructor-aliases -emit-llvm %s -o %t.ll6// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s7 8typedef __typeof(sizeof(int)) size_t;9 10struct SizedDelete {11  void operator delete(void*, size_t);12  int member;13};14void test_sized_delete(SizedDelete *x) {15  delete x;16}17 18// SizedDelete::operator delete(void*, unsigned long)19// CIR:  cir.func private @_ZN11SizedDeletedlEPvm(!cir.ptr<!void>, !u64i)20// LLVM: declare void @_ZN11SizedDeletedlEPvm(ptr, i64)21 22// CIR: cir.func dso_local @_Z17test_sized_deleteP11SizedDelete23// CIR:   %[[X:.*]] = cir.load{{.*}} %{{.*}}24// CIR:   %[[X_CAST:.*]] = cir.cast bitcast %[[X]] : !cir.ptr<!rec_SizedDelete> -> !cir.ptr<!void>25// CIR:   %[[OBJ_SIZE:.*]] = cir.const #cir.int<4> : !u64i26// CIR:   cir.call @_ZN11SizedDeletedlEPvm(%[[X_CAST]], %[[OBJ_SIZE]]) nothrow : (!cir.ptr<!void>, !u64i) -> ()27 28// LLVM: define dso_local void @_Z17test_sized_deleteP11SizedDelete29// LLVM:   %[[X:.*]] = load ptr, ptr %{{.*}}30// LLVM:   call void @_ZN11SizedDeletedlEPvm(ptr %[[X]], i64 4)31 32// OGCG: define dso_local void @_Z17test_sized_deleteP11SizedDelete33// OGCG:   %[[X:.*]] = load ptr, ptr %{{.*}}34// OGCG:   %[[ISNULL:.*]] = icmp eq ptr %[[X]], null35// OGCG:   br i1 %[[ISNULL]], label %{{.*}}, label %[[DELETE_NOTNULL:.*]]36// OGCG: [[DELETE_NOTNULL]]:37// OGCG:   call void @_ZN11SizedDeletedlEPvm(ptr noundef %[[X]], i64 noundef 4)38 39// This function is declared below the call in OGCG.40// OGCG: declare void @_ZN11SizedDeletedlEPvm(ptr noundef, i64 noundef)41 42struct Contents {43  ~Contents() {}44};45struct Container {46  Contents *contents;47  ~Container();48};49Container::~Container() { delete contents; }50 51// Contents::~Contents()52// CIR: cir.func comdat linkonce_odr @_ZN8ContentsD2Ev53// LLVM: define linkonce_odr void @_ZN8ContentsD2Ev54 55// operator delete(void*, unsigned long)56// CIR: cir.func private @_ZdlPvm(!cir.ptr<!void>, !u64i)57// LLVM: declare void @_ZdlPvm(ptr, i64)58 59// Container::~Container()60// CIR: cir.func dso_local @_ZN9ContainerD2Ev61// CIR:   %[[THIS:.*]] = cir.load %{{.*}}62// CIR:   %[[CONTENTS_PTR_ADDR:.*]] = cir.get_member %[[THIS]][0] {name = "contents"} : !cir.ptr<!rec_Container> -> !cir.ptr<!cir.ptr<!rec_Contents>>63// CIR:   %[[CONTENTS_PTR:.*]] = cir.load{{.*}} %[[CONTENTS_PTR_ADDR]]64// CIR:   cir.call @_ZN8ContentsD2Ev(%[[CONTENTS_PTR]]) nothrow : (!cir.ptr<!rec_Contents>) -> ()65// CIR:   %[[CONTENTS_CAST:.*]] = cir.cast bitcast %[[CONTENTS_PTR]] : !cir.ptr<!rec_Contents> -> !cir.ptr<!void>66// CIR:   %[[OBJ_SIZE:.*]] = cir.const #cir.int<1> : !u64i67// CIR:   cir.call @_ZdlPvm(%[[CONTENTS_CAST]], %[[OBJ_SIZE]]) nothrow : (!cir.ptr<!void>, !u64i) -> ()68 69// LLVM: define dso_local void @_ZN9ContainerD2Ev70// LLVM:   %[[THIS:.*]] = load ptr, ptr %{{.*}}71// LLVM:   %[[CONTENTS_PTR_ADDR:.*]] = getelementptr %struct.Container, ptr %[[THIS]], i32 0, i32 072// LLVM:   %[[CONTENTS_PTR:.*]] = load ptr, ptr %[[CONTENTS_PTR_ADDR]]73// LLVM:   call void @_ZN8ContentsD2Ev(ptr %[[CONTENTS_PTR]])74// LLVM:   call void @_ZdlPvm(ptr %[[CONTENTS_PTR]], i64 1)75 76// OGCG: define dso_local void @_ZN9ContainerD2Ev77// OGCG:   %[[THIS:.*]] = load ptr, ptr %{{.*}}78// OGCG:   %[[CONTENTS:.*]] = getelementptr inbounds nuw %struct.Container, ptr %[[THIS]], i32 0, i32 079// OGCG:   %[[CONTENTS_PTR:.*]] = load ptr, ptr %[[CONTENTS]]80// OGCG:   %[[ISNULL:.*]] = icmp eq ptr %[[CONTENTS_PTR]], null81// OGCG:   br i1 %[[ISNULL]], label %{{.*}}, label %[[DELETE_NOTNULL:.*]]82// OGCG: [[DELETE_NOTNULL]]:83// OGCG:   call void @_ZN8ContentsD2Ev(ptr noundef nonnull align 1 dereferenceable(1) %[[CONTENTS_PTR]])84// OGCG:   call void @_ZdlPvm(ptr noundef %[[CONTENTS_PTR]], i64 noundef 1)85 86// These functions are declared/defined below the calls in OGCG.87// OGCG: define linkonce_odr void @_ZN8ContentsD2Ev88// OGCG: declare void @_ZdlPvm(ptr noundef, i64 noundef)89 90struct StructWithVirtualDestructor {91  virtual ~StructWithVirtualDestructor();92};93 94void destroy(StructWithVirtualDestructor *x) {95  delete x;96}97 98// CIR: cir.func {{.*}} @_Z7destroyP27StructWithVirtualDestructor(%[[X_ARG:.*]]: !cir.ptr<!rec_StructWithVirtualDestructor> {{.*}})99// CIR:   %[[X_ADDR:.*]] = cir.alloca !cir.ptr<!rec_StructWithVirtualDestructor>100// CIR:   cir.store %[[X_ARG]], %[[X_ADDR]]101// CIR:   %[[X:.*]] = cir.load{{.*}} %[[X_ADDR]]102// CIR:   %[[VTABLE_PTR:.*]] = cir.vtable.get_vptr %[[X]] : !cir.ptr<!rec_StructWithVirtualDestructor> -> !cir.ptr<!cir.vptr>103// CIR:   %[[VTABLE:.*]] = cir.load{{.*}} %[[VTABLE_PTR]] : !cir.ptr<!cir.vptr>, !cir.vptr104// CIR:   %[[DTOR_FN_ADDR_PTR:.*]] = cir.vtable.get_virtual_fn_addr %[[VTABLE]][1]105// CIR:   %[[DTOR_FN_ADDR:.*]] = cir.load{{.*}} %[[DTOR_FN_ADDR_PTR]]106// CIR:   cir.call %[[DTOR_FN_ADDR]](%[[X]])107 108// LLVM: define {{.*}} void @_Z7destroyP27StructWithVirtualDestructor(ptr %[[X_ARG:.*]])109// LLVM:   %[[X_ADDR:.*]] = alloca ptr110// LLVM:   store ptr %[[X_ARG]], ptr %[[X_ADDR]]111// LLVM:   %[[X:.*]] = load ptr, ptr %[[X_ADDR]]112// LLVM:   %[[VTABLE:.*]] = load ptr, ptr %[[X]]113// LLVM:   %[[DTOR_FN_ADDR_PTR:.*]] = getelementptr inbounds ptr, ptr %[[VTABLE]], i32 1114// LLVM:   %[[DTOR_FN_ADDR:.*]] = load ptr, ptr %[[DTOR_FN_ADDR_PTR]]115// LLVM:   call void %[[DTOR_FN_ADDR]](ptr %[[X]])116 117// OGCG: define {{.*}} void @_Z7destroyP27StructWithVirtualDestructor(ptr {{.*}} %[[X_ARG:.*]])118// OGCG:   %[[X_ADDR:.*]] = alloca ptr119// OGCG:   store ptr %[[X_ARG]], ptr %[[X_ADDR]]120// OGCG:   %[[X:.*]] = load ptr, ptr %[[X_ADDR]]121// OGCG:   %[[ISNULL:.*]] = icmp eq ptr %[[X]], null122// OGCG:   br i1 %[[ISNULL]], label %{{.*}}, label %[[DELETE_NOTNULL:.*]]123// OGCG: [[DELETE_NOTNULL]]:124// OGCG:   %[[VTABLE:.*]] = load ptr, ptr %[[X]]125// OGCG:   %[[DTOR_FN_ADDR_PTR:.*]] = getelementptr inbounds ptr, ptr %[[VTABLE]], i64 1126// OGCG:   %[[DTOR_FN_ADDR:.*]] = load ptr, ptr %[[DTOR_FN_ADDR_PTR]]127// OGCG:   call void %[[DTOR_FN_ADDR]](ptr {{.*}} %[[X]])128