Repository navigation
feat!: find the bounds of pointers with no declaration - #86
Merged
Merged
Conversation
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
__weavec.arrival,ArrivalsinSafeTypes.cpp).__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.pointer-out-of-bounds, and the report gains a line saying where the bound came from.index-singlefor a pointer with no bound and the one-object cases ofcall-argsstop being errors.__weavec.extent→__weavec.object), not the run of its enclosing block. Arrays of arrays are their innermost elements (amendment 33).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).found).weavec-cc --weavec-fix-boundswrites those declarations from a survey's ledgers.-Rpass=weavec-safe), not a diagnostic.WEAVEC_RT_STATS=1counts the questions by site.-fweavec-safe-bounds=found|declared(§9).declaredkeeps the language as it was before this RFC (index-single,call-args).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
1f47ae9cand of this branch)index-singlefor a pointer with no bound goes from 4,313 to 0, andcall-argsfrom 351 to 28. Functions with no error go from 61.5% to 71.8%.check.pypasses 645 of 646.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:
Tests
rt_testpasses.Guards/report-json.cflakes under load and passes alone.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; casestest/cases/bounds/;rt_testbound-*.ci-release): every lit test and the 57 CTest suites pass. A fortified glibcmemsetin safe code needed the row's guards at its call (amendment 38).GuardLibrary.cpp:1034,GuardSafe.cpp:1313and:1419,SafeCxx.cpp:2260and:2274.