Commit 5f5f311
committed
v3: address PR review batch 25 — escape-mark only returned pointers, optional fixed-array returns through defers
The escape prepass (mark_escaping_amp_ptrs) collected every ident in a
return expression, so a pointer that merely appears in a consuming
expression was treated as escaping. For `return p == p && v == 1`, that
heap-moved `v` even though only a bool is returned, and later codegen
read `v` as an int* in the integer comparison (wrong result). Replace
collect_subtree_idents with collect_return_escape_idents, which stops at
operators that consume their operands into a fresh value (infix, postfix,
is/in, and any non-& prefix such as deref *p), so only pointers in a real
escape position (the returned value or a member of a returned aggregate)
mark their source local. This also stops over-marking `return *p`.
An optional fixed-array function (?[N]T) with a pending defer routes
through gen_return_with_defers -> return_expr_string, which lacked the
fixed-array special case the direct path has. The optional's .value is a
fixed-array member that can't be set via a compound literal, so the
deferred path emitted {.ok = false}, dropping the array. Mirror the
direct path's temp + memcpy form (new fixed_array_copy_source_string
capture helper).
Adds regression coverage (batch twentysix).1 parent 8ff74f6 commit 5f5f311
4 files changed
Lines changed: 77 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
905 | 905 | | |
906 | 906 | | |
907 | 907 | | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
908 | 923 | | |
909 | 924 | | |
910 | 925 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
564 | 564 | | |
565 | 565 | | |
566 | 566 | | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
567 | 574 | | |
568 | 575 | | |
569 | 576 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
949 | 949 | | |
950 | 950 | | |
951 | 951 | | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1178 | 1178 | | |
1179 | 1179 | | |
1180 | 1180 | | |
1181 | | - | |
| 1181 | + | |
1182 | 1182 | | |
1183 | 1183 | | |
1184 | 1184 | | |
| |||
1187 | 1187 | | |
1188 | 1188 | | |
1189 | 1189 | | |
1190 | | - | |
1191 | | - | |
1192 | | - | |
| 1190 | + | |
| 1191 | + | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
1193 | 1199 | | |
1194 | 1200 | | |
1195 | 1201 | | |
1196 | 1202 | | |
1197 | | - | |
1198 | | - | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
1199 | 1222 | | |
| 1223 | + | |
1200 | 1224 | | |
1201 | | - | |
| 1225 | + | |
1202 | 1226 | | |
1203 | 1227 | | |
1204 | 1228 | | |
| |||
0 commit comments