Skip to content

Build Tricycle memory safety checker foundation#408

Open
nbeerbower wants to merge 4 commits into
mainfrom
claude/tricycle-memory-safety-nALql
Open

Build Tricycle memory safety checker foundation#408
nbeerbower wants to merge 4 commits into
mainfrom
claude/tricycle-memory-safety-nALql

Conversation

@nbeerbower

Copy link
Copy Markdown
Collaborator

Tricycle is an opt-in static analyzer that proves memory safety properties for Hemlock programs. It provides:

  • Double-free detection (TRIC001)
  • Use-after-free detection (TRIC002)
  • Use-after-move detection (TRIC003)
  • Memory leak detection (TRIC004)
  • Async lifetime safety (TRIC006)
  • Ownership tracking

Features:

  • CLI tool: tricycle check program.hml
  • Supports --strict, --all, --json output modes
  • Integrates with existing type checker for type-aware analysis
  • Proper diagnostic formatting with related locations and hints

New files:

  • include/tricycle/tricycle.h - Public API and data structures
  • src/backends/tricycle/tricycle.c - Context and diagnostics
  • src/backends/tricycle/ownership.c - Ownership analysis engine
  • src/backends/tricycle/main.c - CLI entry point
  • tests/tricycle/ - Test suite with 7 ownership tests

Build: make tricycle
Test: make test-tricycle

Tricycle is an opt-in static analyzer that proves memory safety properties
for Hemlock programs. It provides:

- Double-free detection (TRIC001)
- Use-after-free detection (TRIC002)
- Use-after-move detection (TRIC003)
- Memory leak detection (TRIC004)
- Async lifetime safety (TRIC006)
- Ownership tracking

Features:
- CLI tool: `tricycle check program.hml`
- Supports --strict, --all, --json output modes
- Integrates with existing type checker for type-aware analysis
- Proper diagnostic formatting with related locations and hints

New files:
- include/tricycle/tricycle.h - Public API and data structures
- src/backends/tricycle/tricycle.c - Context and diagnostics
- src/backends/tricycle/ownership.c - Ownership analysis engine
- src/backends/tricycle/main.c - CLI entry point
- tests/tricycle/ - Test suite with 7 ownership tests

Build: `make tricycle`
Test: `make test-tricycle`
The CheckedType returned by type_check_infer_expr was not being freed,
causing a 96-byte leak per call. Now properly call checked_type_free()
after checking the type kind.
This allows tricycle to be built with ASAN and other linker flags
passed via EXTRA_LDFLAGS, consistent with other build targets.
Tricycle test files contain intentional memory bugs (double-free,
use-after-free, etc.) that are meant to be analyzed by the tricycle
static analyzer, not executed by the hemlock interpreter.

Changes:
- Exclude tests/tricycle/ from the main test runner (run_tests.sh)
- Fix tricycle test runner by removing 'set -e' which caused premature
  exit due to (( PASSED++ )) returning 1 when PASSED=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants