Repository navigation
Static analysis rounds 5 and 6, yasc slices, in/inout/out, enforced initialization, unreachable - #29
Merged
Merged
Conversation
matgla
added a commit
to matgla/yasos.zig
that referenced
this pull request
Nov 23, 2026
…chet floor libs/tinycc -> matgla/tinycc#29 (80165e52b6, on mob = #28): -b VLAs/alloca/ longjmp, lifetime with several owners, taint across units, %N$ formats, _FORTIFY_SOURCE builtins, more error recovery; plus #28's CI fixes (ASan leak fixes on error paths, -fmodule-header qualifiers, -fmax-errors in the flow checks). libs/libc -> matgla/yasos_libc#5 (0905390): sys/_fortify.h, the __*_chk functions, alloc_size, stpcpy/stpncpy; the no-OS build undefines _FORTIFY_SOURCE (zig's clang defines it; the kernel did not build). safe_mode_ratchet: libs/libc 371 -> 380 warnings, 1775 -> 1894 errors -- the new fortify.c and tests/fortify_tests.c are regular C, and round 5's checks. an524 QEMU: smoke gate 15322 passed (the 6 failures are mibench sources missing in the worktree), tcc self-host fixpoint PASS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
matgla
added a commit
to matgla/yasos.zig
that referenced
this pull request
Nov 24, 2026
…d unions, register fields); ratchet floor tinycc feat/round5-checks 21312f7744 (matgla/tinycc#29): yasc strict lifetimes with unsafe { } / unsafe(expr), restrict as a checked exclusive borrow, tagged unions, register fields ro / wo / w1c, -fyasc-facts optimizations, and the fixes a review of them found (an ASan stack-use-after-return after asm errors, a nested tagged-union crash, four -fyasc-facts miscompiles, false strict errors, leaks). scripts/safe_mode_ratchet.json: the new floor. Our C is regular C, and in the yasc default a pointer from regular C is dereferenced or becomes owned only inside unsafe, so the counts grow (libs/libc 1894 -> 2388 errors, apps/yasvi 2124 -> 3182, ...). Tested on an524 QEMU: build_rootfs, kernel, tcc self-host fixpoint PASS (77 + 78 identical); the pimoroni_pico_plus2_and_vga image builds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
matgla
added a commit
that referenced
this pull request
Nov 25, 2026
…nitialization, unreachable Static analysis (rounds 5 and 6, PR #29): - strict lifetimes, unsafe regions, tagged unions checked at compile time, register fields ro/wo/w1c (-Wregister-access), -fyasc-facts optimisations; borrows from several owners, borrowing structs, frame addresses through borrowing calls; -Wtainted-format across units; recovery from macro, asm, setup and codegen errors; __has_builtin for the __builtin___*_chk. - yasc: parameter arrays are views ([owned]/[maybe]/... in the brackets), `T * readonly p`, @min and @max, cheat sheet. - -Warray-bounds=2 through pointers, -Wuse-after-free, -b registers main's argv. - The safe default has every check; fortify from the declaration: access and null_terminated_string_arg checked at calls; -Wcross-tu does not depend on the output path; -Wdiscarded-qualifiers names the qualifier and both types. - Diagnostics on a terminal: the source line with a caret, [-Wname], bold names. yasc: - Parameters are in (read-only) unless they say inout or out; out = written before read. `out T * borrows(s) * view p`: what an out parameter stores borrows from s. A redeclaration that says something else about its pointers is an error. - Initialization is enforced: scalars by flow (through out parameters and inlined callees), aggregates need an initializer or `= undefined`. - `unreachable` is a checked trap; -fsanitize=unreachable for __builtin_unreachable(); while(1), do-while(1) and __builtin_trap end a path (no missing-return false positives). - One null pointer, nullptr (-Wzero-as-null-pointer-constant); C23 bool, true, false, nullptr under -ccompat + #pragma yasc too. - Parameters that say their buffer: char s[:0], T p[n], const void buf[n]. - yasc_view / yasc_maybe attribute on a regular-C struct member. - `static !T f(void)` keeps its storage class. Bounds checks (-fsanitize=bounds): - a parameter declared `T p[n]` / `T p[N]` is checked against n (not [static N]), through inline expansion too; the check is cmp/branch/udf. - proven checks go: ssa:vrp (induction variables up to and down from the bound, w - 1, phi joins, one value through copies and equal pure defs, strnlen's zero and i + 1 <= len, strlen's zero) and ssa:bounds_iv before the loop passes, so a checked loop compiles as the unchecked one; stack_deref_fold folds a frame base with a constant scaled index; ssa:fold folds a constant barrel-shifted operand; ssa:cprop forwards a never-written parameter's copy across blocks. - __dirname_chk / __basename_chk with a known path are the plain calls. yasc slices: - `[]T` and `[:0]T` (ptr + len in r0:r1), s[i] checked at every -O, x[a:b], x[a:], x[:b], p[0:n], x[a:b:0], .ptr / .len, conversions from arrays and string literals, slices of slices; a slice parameter is a view source; [:0] slices keep their zero (s[s.len] readable, written only with a zero). Runtime: - libgcc's __clz/__ctz/__popcount/__parity si2/di2 helpers in libtcc1 (weak); complex division __divsc3/__divdc3 in the soft FP runtime (lib/fp/soft/divc3.c) -- the YasOS libc no longer defines them. Fixes: - sl_forward forwarded a slot's stored value into `T <- Addr[StackLoc] [LOAD]` (a frame object's address widened to 64 bits passed a[0] at -O1+). - PT_LOAD p_filesz ends at the last section with file contents. - The -O0 frame floor keeps a frontend object whole when the IR names only its end or middle. - A function a regular-C macro defines in yasc code was checked as yasc from -O1. - __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ predefined beside __GNUC__ for YasOS. - yasc enforced initialization: `&v` passed to an inlined callee's `out T * maybe * view p` (out on the pointer p points at) counts as setting v. - Leaks under ASan: a yasc parameter bound declared later (`T p[n]`), and the parameter names of a list an error recovered out of. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
matgla
force-pushed
the
feat/round5-checks
branch
from
November 25, 2026 17:14
21312f7 to
7d29fa0
Compare
matgla
added a commit
that referenced
this pull request
Nov 25, 2026
…nitialization, unreachable Static analysis (rounds 5 and 6, PR #29): - strict lifetimes, unsafe regions, tagged unions checked at compile time, register fields ro/wo/w1c (-Wregister-access), -fyasc-facts optimisations; borrows from several owners, borrowing structs, frame addresses through borrowing calls; -Wtainted-format across units; recovery from macro, asm, setup and codegen errors; __has_builtin for the __builtin___*_chk. - yasc: parameter arrays are views ([owned]/[maybe]/... in the brackets), `T * readonly p`, @min and @max, cheat sheet. - -Warray-bounds=2 through pointers, -Wuse-after-free, -b registers main's argv. - The safe default has every check; fortify from the declaration: access and null_terminated_string_arg checked at calls; -Wcross-tu does not depend on the output path; -Wdiscarded-qualifiers names the qualifier and both types. - Diagnostics on a terminal: the source line with a caret, [-Wname], bold names. yasc: - Parameters are in (read-only) unless they say inout or out; out = written before read. `out T * borrows(s) * view p`: what an out parameter stores borrows from s. A redeclaration that says something else about its pointers is an error. - Initialization is enforced: scalars by flow (through out parameters and inlined callees), aggregates need an initializer or `= undefined`. - `unreachable` is a checked trap; -fsanitize=unreachable for __builtin_unreachable(); while(1), do-while(1) and __builtin_trap end a path (no missing-return false positives). - One null pointer, nullptr (-Wzero-as-null-pointer-constant); C23 bool, true, false, nullptr under -ccompat + #pragma yasc too. - Parameters that say their buffer: char s[:0], T p[n], const void buf[n]. - yasc_view / yasc_maybe attribute on a regular-C struct member. - `static !T f(void)` keeps its storage class. Bounds checks (-fsanitize=bounds): - a parameter declared `T p[n]` / `T p[N]` is checked against n (not [static N]), through inline expansion too; the check is cmp/branch/udf. - proven checks go: ssa:vrp (induction variables up to and down from the bound, w - 1, phi joins, one value through copies and equal pure defs, strnlen's zero and i + 1 <= len, strlen's zero) and ssa:bounds_iv before the loop passes, so a checked loop compiles as the unchecked one; stack_deref_fold folds a frame base with a constant scaled index; ssa:fold folds a constant barrel-shifted operand; ssa:cprop forwards a never-written parameter's copy across blocks. - __dirname_chk / __basename_chk with a known path are the plain calls. yasc slices: - `[]T` and `[:0]T` (ptr + len in r0:r1), s[i] checked at every -O, x[a:b], x[a:], x[:b], p[0:n], x[a:b:0], .ptr / .len, conversions from arrays and string literals, slices of slices; a slice parameter is a view source; [:0] slices keep their zero (s[s.len] readable, written only with a zero). Runtime: - libgcc's __clz/__ctz/__popcount/__parity si2/di2 helpers in libtcc1 (weak); complex division __divsc3/__divdc3 in the soft FP runtime (lib/fp/soft/divc3.c) -- the YasOS libc no longer defines them. Fixes: - sl_forward forwarded a slot's stored value into `T <- Addr[StackLoc] [LOAD]` (a frame object's address widened to 64 bits passed a[0] at -O1+). - PT_LOAD p_filesz ends at the last section with file contents. - The -O0 frame floor keeps a frontend object whole when the IR names only its end or middle. - A function a regular-C macro defines in yasc code was checked as yasc from -O1. - __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ predefined beside __GNUC__ for YasOS. - yasc enforced initialization: `&v` passed to an inlined callee's `out T * maybe * view p` (out on the pointer p points at) counts as setting v. - ssa:cmp_eq_prop: a never-written PARAM counts like an SSA TEMP, so the equality facts survive cprop forwarding parameters into compares. - Leaks under ASan: a yasc parameter bound declared later (`T p[n]`), and the parameter names of a list an error recovered out of. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
matgla
force-pushed
the
feat/round5-checks
branch
from
November 25, 2026 18:15
7d29fa0 to
b4ae35f
Compare
…nitialization, unreachable Static analysis (rounds 5 and 6, PR #29): - strict lifetimes, unsafe regions, tagged unions checked at compile time, register fields ro/wo/w1c (-Wregister-access), -fyasc-facts optimisations; borrows from several owners, borrowing structs, frame addresses through borrowing calls; -Wtainted-format across units; recovery from macro, asm, setup and codegen errors; __has_builtin for the __builtin___*_chk. - yasc: parameter arrays are views ([owned]/[maybe]/... in the brackets), `T * readonly p`, @min and @max, cheat sheet. - -Warray-bounds=2 through pointers, -Wuse-after-free, -b registers main's argv. - The safe default has every check; fortify from the declaration: access and null_terminated_string_arg checked at calls; -Wcross-tu does not depend on the output path; -Wdiscarded-qualifiers names the qualifier and both types. - Diagnostics on a terminal: the source line with a caret, [-Wname], bold names. yasc: - Parameters are in (read-only) unless they say inout or out; out = written before read. `out T * borrows(s) * view p`: what an out parameter stores borrows from s. A redeclaration that says something else about its pointers is an error. - Initialization is enforced: scalars by flow (through out parameters and inlined callees), aggregates need an initializer or `= undefined`. - `unreachable` is a checked trap; -fsanitize=unreachable for __builtin_unreachable(); while(1), do-while(1) and __builtin_trap end a path (no missing-return false positives). - One null pointer, nullptr (-Wzero-as-null-pointer-constant); C23 bool, true, false, nullptr under -ccompat + #pragma yasc too. - Parameters that say their buffer: char s[:0], T p[n], const void buf[n]. - yasc_view / yasc_maybe attribute on a regular-C struct member. - `static !T f(void)` keeps its storage class. Bounds checks (-fsanitize=bounds): - a parameter declared `T p[n]` / `T p[N]` is checked against n (not [static N]), through inline expansion too; the check is cmp/branch/udf. - proven checks go: ssa:vrp (induction variables up to and down from the bound, w - 1, phi joins, one value through copies and equal pure defs, strnlen's zero and i + 1 <= len, strlen's zero) and ssa:bounds_iv before the loop passes, so a checked loop compiles as the unchecked one; stack_deref_fold folds a frame base with a constant scaled index; ssa:fold folds a constant barrel-shifted operand; ssa:cprop forwards a never-written parameter's copy across blocks. - __dirname_chk / __basename_chk with a known path are the plain calls. yasc slices: - `[]T` and `[:0]T` (ptr + len in r0:r1), s[i] checked at every -O, x[a:b], x[a:], x[:b], p[0:n], x[a:b:0], .ptr / .len, conversions from arrays and string literals, slices of slices; a slice parameter is a view source; [:0] slices keep their zero (s[s.len] readable, written only with a zero). Runtime: - libgcc's __clz/__ctz/__popcount/__parity si2/di2 helpers in libtcc1 (weak); complex division __divsc3/__divdc3 in the soft FP runtime (lib/fp/soft/divc3.c) -- the YasOS libc no longer defines them. Fixes: - sl_forward forwarded a slot's stored value into `T <- Addr[StackLoc] [LOAD]` (a frame object's address widened to 64 bits passed a[0] at -O1+). - PT_LOAD p_filesz ends at the last section with file contents. - The -O0 frame floor keeps a frontend object whole when the IR names only its end or middle. - A function a regular-C macro defines in yasc code was checked as yasc from -O1. - __GNUC_MINOR__ and __GNUC_PATCHLEVEL__ predefined beside __GNUC__ for YasOS. - yasc enforced initialization: `&v` passed to an inlined callee's `out T * maybe * view p` (out on the pointer p points at) counts as setting v. - ssa:cmp_eq_prop: a never-written PARAM counts like an SSA TEMP, so the equality facts survive cprop forwarding parameters into compares. - Leaks under ASan: a yasc parameter bound declared later (`T p[n]`), and the parameter names of a list an error recovered out of. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
matgla
force-pushed
the
feat/round5-checks
branch
from
November 25, 2026 18:30
b4ae35f to
62c1cc3
Compare
A CI cross (--enable-cross, no YasOS sysroot) has no <stddef.h> or <string.h> on its include path: test_compiler_fortify now takes tcc's own include/ (-nostdinc -isystem include), test_diag_color declares strcpy instead of including <string.h>. They passed only on crosses configured by build_rootfs.sh, whose sysinclude is the rootfs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Everything outstanding on top of #28, squashed into one commit on
mob: static analysis rounds 5 and 6, yasc slices,in/inout/out, enforced initialization, checkedunreachable, nullptr only. The x86_64 target is not included: it stays onfeat/x86_64-target.Checks and the safe default
unsafe, tagged unions, register fieldsro/wo/w1c,-fyasc-facts, borrows from several owners, taint across units, error recovery for macro/asm/setup/codegen errors.accessandnull_terminated_string_argare checked at calls.[-Wname]and bold names.yasc
in(read-only) unless they sayinoutorout.out T * borrows(s) * view psays what an out parameter stores borrows from. A redeclaration that says something else about its pointers is an error.= undefined.unreachableis a checked trap.-fsanitize=unreachablecovers__builtin_unreachable().while(1)and__builtin_trapend a path, so they no longer give missing-return false positives.-Wzero-as-null-pointer-constant).char s[:0],T p[n]andconst void buf[n]parameters say their buffer.yasc_view/yasc_maybework on regular-C struct members.[]T/[:0]T: ptr + len in r0:r1,s[i]checked at every -O,x[a:b:0].Bounds checks:
T p[n]parameters are checked with cmp/branch/udf, and checks that ssa:vrp / ssa:bounds_iv prove go away, so a checked loop compiles like the unchecked one.Runtime: libgcc's
__clz/__ctz/__popcount/__paritysi2/di2 helpers (weak) are in libtcc1. Complex division (__divsc3/__divdc3) is in the soft FP runtime. The YasOS libc no longer defines them.Fixes: sl_forward miscompile, PT_LOAD p_filesz, the -O0 frame floor,
static !Tstorage class,__func__NULL under newlib (__GNUC_MINOR__), a false initialization error through an inlined pointer out parameter, two ASan leaks (a yasc bound declared later, parameter names after a recovered error), ssa:cmp_eq_prop keeps its equality facts on never-written parameters (goldenssa:cmp_eq_prop/simpleupdated: the loads cprop forwards are gone, the second compare still folds).Tested locally
make test CI=1passes through aeabi, asm, warn/optflag/opt-dsl checks, all unit suites, frontend, linker, debug, runtime.test-selfhostfails locally only because my host'ssys/mman.hhas noMAP_SLOW. Float ABI matrix softfp/hard 334 passed each; golden IR 25/25.--enable-cross --enable-O2 --debug --enable-asan): 23261 passed. The 20 failures are all local environment: mibench sources missing (8), gcc pr78622 needs%hhdfrom the toolchain's prebuilt newlib (USE_NEWLIB_BUILD=0), and the valgrind tests cannot run an ASan binary.build_rootfs.shcross configure: 23353 passed. Its 34 failures only happen with that configuration: objdump cannot decode the YasOS-only relocation 0x8b thattest_compiler_fortifyreads,912_complex_div_runtimehard-faults when built with the YasOS PIC cross for bare metal (it passes with the CI configure), plus mibench and pr78622 as above.🤖 Generated with Claude Code