Description: Fix JIT crash
 KeyError was only caught in one of the accesses to cache
Author: Armin Rigo <arigo@tunes.org>
Origin: upstream, https://bitbucket.org/pypy/pypy/commits/5ca1994
Bug-Upstream: https://bitbucket.org/pypy/pypy/issue/1669
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/pypy/+bug/1368418

--- a/rpython/jit/metainterp/heapcache.py
+++ b/rpython/jit/metainterp/heapcache.py
@@ -159,17 +159,17 @@
                                 descr,
                             )
                         elif cache is not None:
-                            if argboxes[2] in self.new_boxes:
-                                try:
-                                    idx_cache = cache[dststart + i]
-                                except KeyError:
-                                    pass
-                                else:
+                            try:
+                                idx_cache = cache[dststart + i]
+                            except KeyError:
+                                pass
+                            else:
+                                if argboxes[2] in self.new_boxes:
                                     for frombox in idx_cache.keys():
                                         if not self.is_unescaped(frombox):
                                             del idx_cache[frombox]
-                            else:
-                                cache[dststart + i].clear()
+                                else:
+                                    idx_cache.clear()
                     return
                 elif (
                     argboxes[2] in self.new_boxes and
