[FEAT] Add if/else branch condition tracking to sanitizer#336
[FEAT] Add if/else branch condition tracking to sanitizer#336
Conversation
Eliminate false OOB alarms for memory accesses inside guarded branches within loops. The sanitizer now tracks branch conditions symbolically and merges them into Z3 constraints for deferred and immediate checks. Architecture mirrors the existing for-loop patching pattern: - AST transformer patches visit_If on the Triton interpreter - IfFrame tracks predicate, support constraints, and concrete result - Branch constraints are merged into PendingCheck.constraints - Concrete materialization substitutes loop idx and PID vars Known limitations: - Compound boolean expressions (and/or/not) lose symbolic info - Data-dependent conditions (tl.load results) fall back to defaults
Sanitizer Performance Benchmark
Iterations: 1 warmup + 20 measured |
When do we report oob previously? I think there must be something wrong with the caching mechanism |
I think there are actually two separate issues here. Your caching point is still relevant for a different case, though: before this PR, the loop signature is built from (addr_expr, constraints) without branch constraints, so the same address expression under different branches can collapse to one signature. This PR fixes that too by merging branch path constraints before computing the signature, and there is a regression test for “same addr expr under different branches should not dedup”. So I’d describe the root cause of the quoted false positive as path-insensitive branch handling, while cache/dedup is a secondary branch-related issue that this PR also addresses. |
|
I think it's a more general problem even outside of loops |
Summary
tl.load/tl.storeinside guardedifbranches within loops (e.g.if t > 0: tl.load(ptr + t - 1)no longer reports OOB whent=0)Test plan
uv run pytest tests/ -x -q --ignore=tests/nki(223 passed, 2 skipped)try/finallystructureif t > 0: tl.load(ptr + t - 1)with scalar tensor reports 0 OOBif pid == 0: tl.load(ptr + pid)withgrid=2reports 0 OOBKnown limitations
and/or/not/chained comparisons) lose symbolic info because Python evaluates__bool__beforepre_ifreceives the valueif tl.load(x_ptr) > 0:) fall back to plain Python truthiness (current behavior)