KhronosGroup / KhronosGroup/SPIRV-Tools

Systematically look for TakeNextId failing errors in spirv-opt

Open
#2,850 1 comment 0 reactions 0 assignees View on GitHub
component:optimization dev:testing enhancement
Dominant language
C++
Stars
1.4k
Forks
709
Avg merge
1d 22h
Merged PRs (30d)
28

Description

In spirv-opt if the IDs are exhausted it will start returning 0, which in many contexts is converted to a nullptr instruction. Callers of methods that might create new instructions need to handle creation failures gracefully. Because the actual creation might be a number of calls down the stack, it is not always obvious that a call might have this failure in it.

I was thinking about how to systematically discover these types of programming errors, after getting bitten by one myself. My idea is to have a for testing version to TakeNextId that can be used instead of the standard version, and have a test harness that iteratively works through a bunch of test cases, with TakeNextId starting to fail after 0, 1, 2, etc invocations, instead of the normal failure condition, in an attempt to discover areas of the code base that don't handle this failure correctly. Kinda like fuzzing the code, but by fiddling a failure state instead of the inputs.

Contributor guide

Open the contributing guide

Research direction

Start by tracing TakeNextId and its callers in spirv-opt to identify creation paths that can return 0. Design a testing version that fails after successive invocation counts, then build a harness that exercises those cases and verifies callers handle creation failures without invalid instructions.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, testing
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.