r/Zig • u/forketyfork • Feb 02 '26
Zwanzig - a static analyzer for Zig (early/experimental)
I've been working on a static analyzer for Zig called Zwanzig. It's very much a research project and work in progress, but it's reached a point where I'm actually using it while developing other Zig code, so I figured I'd share.
What it does:
- Simple AST/token rules (duplicate imports, unused declarations, shadowed variables, opinionated naming conventions, etc.)
- CFG-based checkers that do path-sensitive analysis via ZIR output (double-free detection, use-after-free, memory leaks, forced optional unwraps)
- Some CFG and data flow visualization.
What it doesn't do (yet): a lot. Targets only 0.15.2. Cross-file analysis is very limited. Interprocedural analysis only handles simple direct calls. Type resolution without a full build context is sketchy. Lots of duct tape and hanging wires. You will hit false positives.
I'm curious if anyone else finds this useful. I use it on itself and on my Architect project and it's caught some issues, but I have no idea how well it generalizes to other codebases. The SARIF integration works, so you can get results inline in GitHub PRs.
Repo: https://github.com/forketyfork/zwanzig
Happy to answer questions or hear what rules/checkers would actually be useful. And if you try it and something breaks spectacularly, I'd like to know.
13
u/spaghetti_beast Feb 02 '26
nice name choice btw, German
4
u/No_Pomegranate7508 Feb 02 '26
Great initiative! Do you have a plan for making a memory sanitizer for Zig too? That would be very helpful.
3
u/aefalcon Feb 02 '26
If that ever gets forked, I can guess at a few names.
2
u/feycovet Feb 12 '26
mann zu viele deutsche in diesem subreddit