Skip to content

Commit ce96db1

Browse files
committed
fix(smir): preserve drop glue edges for index projections
1 parent dafd5f5 commit ce96db1

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

kmir/src/kmir/smir.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ def _projected_ty(self, ty: Ty, projection: object) -> Ty | None:
345345
return Ty(fields[index])
346346
return None
347347

348+
if 'Index' in projection and isinstance(type_info, ArrayT):
349+
return Ty(type_info.element_type)
350+
348351
if 'ConstantIndex' in projection and isinstance(type_info, ArrayT):
349352
return Ty(type_info.element_type)
350353

kmir/src/tests/unit/test_smir.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,83 @@ def test_call_edges_preserve_drop_glue_for_downcast_field() -> None:
134134
)
135135

136136
assert smir_info.call_edges == {10: {12}, 12: set()}
137+
138+
139+
def test_call_edges_preserve_drop_glue_for_index_projection() -> None:
140+
# This SMIR models:
141+
# local 1: [Inner; 2]
142+
# local 2: usize
143+
# Drop(local 1 . Index(local 2))
144+
# so `call_edges` must keep the reachable `std::ptr::drop_in_place::<Inner>` callee.
145+
smir_info = SMIRInfo(
146+
{
147+
'name': 'drop-index-field',
148+
'allocs': [],
149+
'types': [
150+
[1, {'ArrayType': {'elem_type': 2, 'size': None}}],
151+
[
152+
2,
153+
{
154+
'StructType': {
155+
'name': 'Inner',
156+
'adt_def': 2,
157+
'fields': [],
158+
'layout': None,
159+
}
160+
},
161+
],
162+
[3, {'PrimitiveType': {'Uint': 'Usize'}}],
163+
[4, {'PtrType': {'pointee_type': 2}}],
164+
],
165+
'functions': [
166+
[10, {'NormalSym': 'caller'}],
167+
[12, {'NormalSym': 'drop_inner'}],
168+
],
169+
'items': [
170+
{
171+
'symbol_name': 'caller',
172+
'mono_item_kind': {
173+
'MonoItemFn': {
174+
'name': 'caller',
175+
'body': {
176+
'arg_count': 0,
177+
'locals': [{'ty': 0}, {'ty': 1}, {'ty': 3}],
178+
'blocks': [
179+
{
180+
'terminator': {
181+
'kind': {
182+
'Drop': {
183+
'place': {
184+
'local': 1,
185+
'projection': [{'Index': 2}],
186+
},
187+
'target': 0,
188+
'unwind': 'Continue',
189+
}
190+
}
191+
}
192+
}
193+
],
194+
},
195+
}
196+
},
197+
},
198+
{
199+
'symbol_name': 'drop_inner',
200+
'mono_item_kind': {
201+
'MonoItemFn': {
202+
'name': 'std::ptr::drop_in_place::<Inner>',
203+
'body': {
204+
'arg_count': 1,
205+
'locals': [{'ty': 0}, {'ty': 4}],
206+
'blocks': [],
207+
},
208+
}
209+
},
210+
},
211+
],
212+
'spans': [],
213+
}
214+
)
215+
216+
assert smir_info.call_edges == {10: {12}, 12: set()}

0 commit comments

Comments
 (0)