Skip to content

Commit eb770d6

Browse files
committed
fix(smir): preserve drop glue edges for downcast fields
1 parent a0621b7 commit eb770d6

4 files changed

Lines changed: 91 additions & 3 deletions

File tree

kmir/src/kmir/smir.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,10 @@ def _projected_ty(self, ty: Ty, projection: object) -> Ty | None:
327327
return None
328328

329329
if 'Field' in projection:
330-
index, _ = projection['Field']
330+
index, field_ty = projection['Field']
331+
if isinstance(field_ty, int):
332+
return Ty(field_ty)
333+
331334
if isinstance(type_info, (StructT, UnionT)):
332335
fields = type_info.fields
333336
elif isinstance(type_info, TupleT):

kmir/src/tests/integration/data/crate-tests/two-crate-bin/crate2::main.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
┌─ 1 (root, init)
33
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
44
5-
│ (737 steps)
5+
│ (740 steps)
66
├─ 3 (terminal)
77
│ #EndProgram ~> .K
88

kmir/src/tests/integration/data/crate-tests/two-crate-dylib/crate2::test_crate1_with.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
┌─ 1 (root, init)
33
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC
44
5-
│ (216 steps)
5+
│ (217 steps)
66
├─ 3 (terminal)
77
│ #EndProgram ~> .K
88

kmir/src/tests/unit/test_smir.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,88 @@ def test_function_symbols_reverse(smir_file: Path, update_expected_output: bool)
4545
def test_function_tys(smir_file: Path, update_expected_output: bool) -> None:
4646
"""Test function_tys using actual SMIR JSON data."""
4747
_test_smir_property(smir_file, 'function_tys', update_expected_output)
48+
49+
50+
def test_call_edges_preserve_drop_glue_for_downcast_field() -> None:
51+
smir_info = SMIRInfo(
52+
{
53+
'name': 'drop-downcast-field',
54+
'allocs': [],
55+
'types': [
56+
[
57+
1,
58+
{
59+
'EnumType': {
60+
'name': 'Wrapper',
61+
'adt_def': 1,
62+
'discriminants': [0],
63+
'fields': [[2]],
64+
'layout': None,
65+
}
66+
},
67+
],
68+
[
69+
2,
70+
{
71+
'StructType': {
72+
'name': 'Inner',
73+
'adt_def': 2,
74+
'fields': [],
75+
'layout': None,
76+
}
77+
},
78+
],
79+
[3, {'PtrType': {'pointee_type': 2}}],
80+
],
81+
'functions': [
82+
[10, {'NormalSym': 'caller'}],
83+
[12, {'NormalSym': 'drop_inner'}],
84+
],
85+
'items': [
86+
{
87+
'symbol_name': 'caller',
88+
'mono_item_kind': {
89+
'MonoItemFn': {
90+
'name': 'caller',
91+
'body': {
92+
'arg_count': 0,
93+
'locals': [{'ty': 0}, {'ty': 1}],
94+
'blocks': [
95+
{
96+
'terminator': {
97+
'kind': {
98+
'Drop': {
99+
'place': {
100+
'local': 1,
101+
'projection': [{'Downcast': 0}, {'Field': [0, 2]}],
102+
},
103+
'target': 0,
104+
'unwind': 'Continue',
105+
}
106+
}
107+
}
108+
}
109+
],
110+
},
111+
}
112+
},
113+
},
114+
{
115+
'symbol_name': 'drop_inner',
116+
'mono_item_kind': {
117+
'MonoItemFn': {
118+
'name': 'std::ptr::drop_in_place::<Inner>',
119+
'body': {
120+
'arg_count': 1,
121+
'locals': [{'ty': 0}, {'ty': 3}],
122+
'blocks': [],
123+
},
124+
}
125+
},
126+
},
127+
],
128+
'spans': [],
129+
}
130+
)
131+
132+
assert smir_info.call_edges == {10: {12}, 12: set()}

0 commit comments

Comments
 (0)