-
Kevin Modzelewski authored
The IR we generated looked something like this: 1: i64 %a = doIC() 2: checkPendingCalls() 3: Box* %b = (Box*)%b The problem is that the refcounter only knew about %b, starting on line 3. So for line 2, the refcounter didn't think it needed to decref %a if an exception was thrown. So the first thing this commit does is it adds check that when we refcount-track a value, if it is a cast, then the cast must be right next to the thing it is casting. This is stricter than we need but it should be easy enough to do and be sufficient. Another approach would have been to have the refcount checker be able to track the non-box-like values, ie track %a in the above example. This would need some checking to make sure that people didn't forget to track that. In the end I thought this would be simpler. The second thing is it adds a helper function createAfter that inserts the cast in the right location. This could have worked by having createIC do the casting itself. But this was a little bit tricky since some callers want to know the Instruction of the call itself, and if createIC only returned the cast then those would get confused. It could have returned both, but that seemed complicated.
43351fb2