Commit 782884c
committed
fix(lowering): early_unsafe_panic must keep side-effecting statements
The pass replaces the dead tail of a function (from which return is
unreachable) with unsafe_panic, and is meant to preserve side-effecting
libfunc calls (debug::print / internal::trace) that must still run first.
But it scanned statements forward and truncated AT the first side effect
(`truncate(i)`), deleting the very statement it meant to keep. It also only
considered the first side effect, dropping later ones in the same block.
Scan in reverse and truncate after the last side effect (`i + 1`). Move the
test from PreOptimizations to PostBaseline (where this pass actually runs, so
print is the inlined extern it detects) and add a regression case.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 0ef1296 commit 782884c
3 files changed
Lines changed: 89 additions & 24 deletions
File tree
- crates/cairo-lang-lowering/src/optimizations
- test_data
Lines changed: 7 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
109 | | - | |
| 109 | + | |
110 | 110 | | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
| |||
Lines changed: 79 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
| 38 | + | |
40 | 39 | | |
41 | | - | |
| 40 | + | |
42 | 41 | | |
43 | 42 | | |
44 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
48 | 52 | | |
49 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
50 | 85 | | |
51 | 86 | | |
52 | 87 | | |
| |||
58 | 93 | | |
59 | 94 | | |
60 | 95 | | |
| 96 | + | |
61 | 97 | | |
62 | | - | |
| 98 | + | |
| 99 | + | |
63 | 100 | | |
64 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
65 | 111 | | |
66 | 112 | | |
67 | 113 | | |
68 | 114 | | |
69 | 115 | | |
70 | | - | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
71 | 124 | | |
| 125 | + | |
72 | 126 | | |
73 | | - | |
| 127 | + | |
| 128 | + | |
74 | 129 | | |
75 | 130 | | |
76 | 131 | | |
77 | | - | |
| 132 | + | |
78 | 133 | | |
79 | 134 | | |
80 | 135 | | |
81 | 136 | | |
82 | 137 | | |
| 138 | + | |
| 139 | + | |
83 | 140 | | |
84 | | - | |
| 141 | + | |
85 | 142 | | |
86 | 143 | | |
87 | 144 | | |
| |||
96 | 153 | | |
97 | 154 | | |
98 | 155 | | |
99 | | - | |
100 | | - | |
101 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
102 | 161 | | |
103 | | - | |
| 162 | + | |
104 | 163 | | |
105 | 164 | | |
106 | 165 | | |
107 | 166 | | |
108 | 167 | | |
109 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
110 | 173 | | |
111 | 174 | | |
112 | 175 | | |
0 commit comments