Skip to content

Full device debug puts #[unroll] and #[nounroll] attribute lines in the line table #1676

Closed

Description

@vyncint

Follow-up named on #1530: "under --device-debug the goto that replaces the marker should take the artificial location the other markers use".

What happens

#[kernel] and #[device] put a marker call at the start of each loop annotated with #[unroll], #[unroll(N)], #[unroll(never)] or #[nounroll]. The importer removes that call. It plants a hint op and replaces the call with a goto to the call's return block, in the __unroll_config and __nounroll_config branches of mir-importer/src/translator/terminator/mod.rs. Both the hint op and the goto take the call's location, and that location is the attribute:

hint.deref_mut(ctx).set_loc(loc.clone());
// ...
return Ok(helpers::emit_goto(ctx, target, hint, block_map, loc));

The kernel metadata markers (__launch_bounds_config and the rest of KERNEL_METADATA_MARKERS) have avoided this since #1125. Their replacement edge takes llvm_export::artificial_debug_location(), because "the replacement control-flow edge must also stay off the attribute line which caused the macro to inject them".

I measured on main (76ac1021) with cargo oxide build <example> --device-debug. All 38 loop-hint attributes in unroll_smoke get a .loc entry, and so do all 8 in nounroll. Each one sits on a branch inside the annotated loop:

$L__BB0_16:                             // %bb15
                                        //   in Loop: Header=BB0_15 Depth=1
	.loc	1 80 9                          // main.rs:80:9
	bra.uni 	$L__BB0_17;

A line-tables build (CUDA_OXIDE_DEBUG=line-tables) has none of them, because the branch doesn't survive optimization. Full debug skips the optimizer, so the branch and its location survive into the line table, and a debugger stepping through the loop can stop on the #[unroll] line.

Fix

Give that goto the artificial location in both branches. The hint op keeps the attribute's location, because that is where the not-unrolled warnings point.

For the guard, I'll extend examples/debug/verify-code-shape.sh. It already enforces this contract for the kernel prologue, and the compile-only sweep runs it on a --device-debug build. The debug example gets a kernel with one loop per spelling, and the script rejects any line-table entry on those attribute lines, in LLVM IR and in PTX.

I'm taking this. The PR follows.

Activity

  1. added a commit that references this issue on Nov 3, 2026
    28b323c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions