From 0c3f3f9e28fe340a3bda2c7d93c8199cc18db00d Mon Sep 17 00:00:00 2001
Origin: https://github.com/numba/numba/pull/8590
From: Siu Kwan Lam <1929845+sklam@users.noreply.github.com>
Date: Wed, 9 Nov 2022 16:34:10 -0600
Subject: [PATCH 02/14] Fix LOAD_GLOBAL arg use in test_parfors for py3.11

otherwise, sometests may segfault
---
 numba/tests/test_parfors.py | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

--- a/numba/tests/test_parfors.py
+++ b/numba/tests/test_parfors.py
@@ -129,6 +129,13 @@
 
 TestNamedTuple = namedtuple('TestNamedTuple', ('part0', 'part1'))
 
+
+def _fix_LOAD_GLOBAL_arg(arg):
+    if utils.PYVERSION >= (3, 11):
+        return arg >> 1
+    return arg
+
+
 def null_comparer(a, b):
     """
     Used with check_arq_equality to indicate that we do not care
@@ -3255,7 +3262,7 @@
             # look for LOAD_GLOBALs that point to 'range'
             for instr in dis.Bytecode(pyfunc_code):
                 if instr.opname == 'LOAD_GLOBAL':
-                    if instr.arg == range_idx:
+                    if _fix_LOAD_GLOBAL_arg(instr.arg) == range_idx:
                         range_locations.append(instr.offset + 1)
             # add in 'prange' ref
             prange_names.append('prange')
@@ -3283,10 +3290,15 @@
                         prange_names,
                         pyfunc_code.co_varnames,
                         pyfunc_code.co_filename,
-                        pyfunc_code.co_name,
-                        pyfunc_code.co_firstlineno,
-                        pyfunc_code.co_lnotab,
-                        pyfunc_code.co_freevars,
+                        pyfunc_code.co_name])
+
+        if utils.PYVERSION >= (3, 11):
+            co_args.append(pyfunc_code.co_qualname)
+        co_args.extend([pyfunc_code.co_firstlineno,
+                        pyfunc_code.co_lnotab])
+        if utils.PYVERSION >= (3, 11):
+            co_args.append(pyfunc_code.co_exceptiontable)
+        co_args.extend([pyfunc_code.co_freevars,
                         pyfunc_code.co_cellvars
                         ])
 
