Skip to content

Commit 561f38d

Browse files
authored
Fix empty DW_AT_location for reused loop variables (#811)
Nvbug5886953 exposes an issue that reused loop index variables have a DWARF location list with corrupted entries. The root cause is in the base class `Lower.loadvar`, which suppresses `!dbg` metadata on loads of function argument variables. This causes NVVM to emit `.loc line 0` between the loops, and `ptxas` builds a multi-entry location list where the line-0 ranges inserted between entries corrupt it, producing an empty `DW_AT_location` in the final DWARF. This PR overrides `loadvar` in `CUDALower` to skip the suppression. The suppression is unnecessary because `loadvar` is never called during the prologue — arg unpacking in `lower_assign` and `storevar` already handle suppression there. Also add `test_arg_load_has_dbg_location` regression test. Fixes nvbug5886953.
1 parent dd2e942 commit 561f38d

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

numba_cuda/numba/cuda/lowering.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,6 +1695,21 @@ def decref(self, typ, val):
16951695

16961696

16971697
class CUDALower(Lower):
1698+
def loadvar(self, name):
1699+
if name in self._blk_local_varmap and not self._disable_sroa_like_opt:
1700+
return self._blk_local_varmap[name]
1701+
ptr = self.getvar(name)
1702+
1703+
# Skip the base-class suspend_emission for arg-named loads.
1704+
# loadvar is never called in the prologue (arg unpacking in
1705+
# lower_assign and storevar already suppresses there).
1706+
# On CUDA the missing !dbg emits ".loc line 0"; when a
1707+
# variable (e.g. a reused loop counter) has multiple
1708+
# dbg.value entries, ptxas builds a multi-entry location
1709+
# list and the line-0 ranges inserted between entries
1710+
# will result in an corrupted DW_AT_location.
1711+
return self.builder.load(ptr)
1712+
16981713
def storevar(self, value, name, argidx=None):
16991714
"""
17001715
Store the value into the given variable.

numba_cuda/numba/cuda/tests/cudapy/test_debuginfo.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,31 @@ def foo(output):
12121212
match, f"No non-zero store to 'bar.N' with !dbg !{continue_dbg_id}"
12131213
)
12141214

1215+
def test_arg_load_has_dbg_location(self):
1216+
"""Loads of arg-named variables must carry !dbg in the body.
1217+
1218+
Reusing `j` across two loops creates multiple dbg.value
1219+
entries; a missing !dbg on the arg load (".loc line 0")
1220+
makes ptxas zero the location list and results in corrupted
1221+
DW_AT_location. Regression test for nvbug 5886953.
1222+
"""
1223+
sig = (types.float32[:], types.int64)
1224+
1225+
@cuda.jit("void(float32[:], int64)", debug=True, opt=False)
1226+
def foo(arr, n):
1227+
for j in range(n):
1228+
arr[0] += j
1229+
for j in range(n):
1230+
arr[0] += j
1231+
1232+
llvm_ir = foo.inspect_llvm(sig)
1233+
pat = re.compile(r'load\s.*%"arr"\s*$', re.MULTILINE)
1234+
match = pat.search(llvm_ir)
1235+
self.assertIsNone(
1236+
match,
1237+
msg="Load of arg 'arr' missing !dbg metadata",
1238+
)
1239+
12151240

12161241
if __name__ == "__main__":
12171242
unittest.main()

0 commit comments

Comments
 (0)