@@ -86,3 +86,42 @@ Container::~Container() { delete contents; }
8686// These functions are declared/defined below the calls in OGCG.
8787// OGCG: define linkonce_odr void @_ZN8ContentsD2Ev
8888// OGCG: declare void @_ZdlPvm(ptr noundef, i64 noundef)
89+
90+ struct StructWithVirtualDestructor {
91+ virtual ~StructWithVirtualDestructor ();
92+ };
93+
94+ void 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.vptr
104+ // 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 ptr
110+ // 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 1
114+ // 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 ptr
119+ // OGCG: store ptr %[[X_ARG]], ptr %[[X_ADDR]]
120+ // OGCG: %[[X:.*]] = load ptr, ptr %[[X_ADDR]]
121+ // OGCG: %[[ISNULL:.*]] = icmp eq ptr %[[X]], null
122+ // 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 1
126+ // OGCG: %[[DTOR_FN_ADDR:.*]] = load ptr, ptr %[[DTOR_FN_ADDR_PTR]]
127+ // OGCG: call void %[[DTOR_FN_ADDR]](ptr {{.*}} %[[X]])
0 commit comments