Skip to content

feat!: find the bounds of pointers with no declaration - #86

Merged
owenthcarey merged 3 commits into
mainfrom
rfc0056-bounds-without-declarations
Dec 5, 2026
Merged

owenthcarey merged 3 commits into
mainfrom
rfc0056-bounds-without-declarations

Conversation

@owenthcarey

Copy link
Copy Markdown
Contributor

Implements RFC 0056 — Bounds without declarations, which was accepted as drafted. Its Implementation amendments (1–38) and Measured gates record what was built and measured. G5, G7 and G8 are not met as written, and G4 was not run, so the RFC stays Accepted.

What changes

  • A pointer with no declared bound is found, not rejected (§1–§3).
    • Where such a pointer arrives in a safe function (a parameter, a load, a call's result, a global) and is indexed or stepped, the checker marks it (__weavec.arrival, Arrivals in SafeTypes.cpp).
    • The pass asks the runtime once for its bound (__weavec_rt_bound): the run of objects of its type that the records give (a heap block, a registered global's extent, a recorded local). Memory with no record is one object.
    • Every access is compared with the answer. A failure is pointer-out-of-bounds, and the report gains a line saying where the bound came from.
    • index-single for a pointer with no bound and the one-object cases of call-args stop being errors.
  • A member the code names bounds its pointer (amendment 29). A pointer into a struct's member is one object of the member (__weavec.extent → __weavec.object), not the run of its enclosing block. Arrays of arrays are their innermost elements (amendment 33).
  • A safe caller passes the bounds it holds (§6). The callee's body gets a hidden last parameter, held. A bound is asked of the runtime only where no code holds it. B3 is checked at every call that may reach safe code, indirect and virtual ones included (amendment 31).
  • The compiler lists what it finds (§8).
    • The ledger and the audit list each found bound with the declaration the planner proposes (found).
    • weavec-cc --weavec-fix-bounds writes those declarations from a survey's ledgers.
    • A found bound is a remark (-Rpass=weavec-safe), not a diagnostic.
    • WEAVEC_RT_STATS=1 counts the questions by site.
  • -fweavec-safe-bounds=found|declared (§9). declared keeps the language as it was before this RFC (index-single, call-args).
  • Versions: runtime ABI 52, ledger 16, audit 11.
  • Pages updated: guarantees.md (B1–B3), the Safe C, Safe C++ and C++ conversion guides, the CLI reference, rules.md, annotations, architecture, AGENTS.md, the roadmap.

Measured (darwin-arm64, Release compilers of main at 1f47ae9c and of this branch)

  • G2, the survey of fifteen projects: index-single for a pointer with no bound goes from 4,313 to 0, and call-args from 351 to 28. Functions with no error go from 61.5% to 71.8%.
  • G3: cJSON, sds, http-parser, inih and tinyxml2 are marked safe as written. Their tests pass in the fast and the checked build with no stop.
  • G5: a fresh agent wrote the Safe C json port with no bound annotation asked of it. It was all safe in 6 minutes and 3 rounds, and check.py passes 645 of 646.
  • G6: each injected spatial bug in a safe function stops at the access.
  • G8: within 1.01 of main except the C++ json port (fast, ~1.03) and the interpreter (checked, ~1.03), measured on a busy machine. Compiles 1.007.

Three costs that G8 found were removed on the way (amendment 37). tinyxml2's checked build had been 5.1 times Clang's, from questions about strings that RFC 0047 leaves to the guards. Library classes' locals had been recorded, and library member results had been treated as arrivals.

Gates not met as written, so the RFC stays Accepted:

  • S0 (d): the Safe C json port is 1.375 times the annotated port (limit 1.25). This was recorded as missed.
  • G5: the port's benchmark is 1.07 of RFC 0055's port (limit 1.05).
  • G7: all 11 C holes are closed. Of 21 C++ holes, 7 are open in every build and 7 more in the checked build only (amendments 32, 35). False stop f06 is open.
  • G8: two programs are about 3% slower (see above).
  • G9: the library gains 2,375 lines of code and the runtime 845. The draft expected about 900 and 400.
  • Not run: G4 (the libzmq and nng conversions) and the guarded corpus tier.

Tests

  • darwin-arm64: every lit test, case suite, unit test and rt_test passes. Guards/report-json.c flakes under load and passes alone.
  • New tests: test/Safe/found-bounds.c, cxx-found-bounds.cpp, bounds-declared.c; test/Guards/found-bounds.c, found-bounds-members.c, found-bounds-held.c, found-bounds-lambda.cpp, ir-found-bounds.c; test/Driver/found-bounds.c; cases test/cases/bounds/; rt_test bound-*.
  • Linux container (aarch64, glibc, libstdc++, ci-release): every lit test and the 57 CTest suites pass. A fortified glibc memset in safe code needed the row's guards at its call (amendment 38).
  • clang-tidy (in the container) reports five analyzer findings, all in lines this change does not touch: GuardLibrary.cpp:1034, GuardSafe.cpp:1313 and :1419, SafeCxx.cpp:2260 and :2274.
  • Other checks: hygiene, spelling, format, documentation examples and the site build pass.

A pointer with no declared bound in a safe function is no longer an
index-single or call-args error. Where it arrives and is indexed or
stepped, the function asks the runtime once for the run of objects of its
type the records give (__weavec_rt_bound), a safe caller passes the
bounds it holds in the hidden parameter held, a member the code names
bounds its pointer, and every access is compared with the bound found.
The ledger and the audit list each found bound with the declaration the
planner proposes, and weavec-cc --weavec-fix-bounds writes them.
-fweavec-safe-bounds=declared keeps the language before.

BREAKING CHANGE: runtime ABI 52, ledger 16, audit 11; index-single and
the one-object cases of call-args are no longer errors by default.
- A body's `held` parameter now follows from its declaration in both
  modes of `-fweavec-safe-bounds`, so a unit compiled with `declared`
  calls a `found` unit's body with the arguments it takes (§6, §9);
  amendment 7 says so.
- The short path no longer remembers a type whose last member is one
  element or none after a plain header: a larger block of it is one
  object and its trailing elements, as the general path answers.
- An element of no bytes is the general path's (no division by zero).
- Of the guarded frame's locals that share bytes, the one in scope
  gives the bound.
- A recorded local that holds the address wins over one that ends there.

Tests: test/Guards/found-bounds-modes.c; rt_test bound-shared-frames,
bound-empty-element, and new cases in bound-short-path and bound-locals.
@owenthcarey owenthcarey changed the title feat!: find the bounds of pointers with no declaration (RFC 0056) feat!: find the bounds of pointers with no declaration Dec 5, 2026
The guarantees page stated (B1) and (B3) for both builds; RFC 0056
amendments 32 and 35 record the C++ cases that are still open: an end a
lambda's initializer captures, a std::function called with an end,
std::next and vector ranges over a found pointer, and, in the checked
build, library calls that keep their object guard.
@owenthcarey
owenthcarey merged commit 528733c into main Dec 5, 2026
13 checks passed
@owenthcarey
owenthcarey deleted the rfc0056-bounds-without-declarations branch December 5, 2026 07:50
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.

1 participant