Repository navigation
yasc modules, pointer sigils and view defaults, tcc -format; codegen, checker and GOT-order fixes - #31
Open
matgla wants to merge 48 commits into
Open
yasc modules, pointer sigils and view defaults, tcc -format; codegen, checker and GOT-order fixes#31matgla wants to merge 48 commits into
matgla wants to merge 48 commits into
Conversation
-Woverride-init (gcc's name, -Wextra, on in the safe default): a designator
naming bits an earlier element of the same initializer already set. Bit
ranges per designator (bit-fields count bits), checked before the element's
sub-elements and recorded whole after; a union records the member it was
given last, so `{ .i = v, .p.hi = 3 }` is reported although .i and .p.hi
share no byte. The const-template probe of a large local array reports
once for both passes. The bookkeeping lives in a heap InitOvr reached from
init_params, its hooks folded into decl_designator's existing calls: no
frame growth on the parser's recursive path.
-Wuninitialized (yasc: -Wlifetime, an error in the safe default): a local
read in its own initializer -- `int x = x + 1;`, `struct pt p = p;`,
`u = { .value = v, .parts = { .imag = -u.parts.imag } }` (libc's conjf).
tcc_ir_put reports an operand read from the variable (its frame range, or
its vreg for a register candidate, whose offset is the frame's top) or
through an address of it computed into a vreg, while parse_init_elem parses
the expression; an sret call writing straight into it reads nothing. The
enclosing initializer's state waits on a static stack; error recovery
restores it and frees what the longjmp left.
Over the safe-mode ratchet's C, both checks report only libc's conjf.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… across #include A library header is written once, in yasc (yasc/x.h); `tcc -yasc-c-header yasc/x.h -o x.h` writes the C header: `#ifdef __YASC__` includes the yasc one (a yasc unit reads it), otherwise the translation -- yasc words left out, #pragma yasc / c_begin / c_end lines dropped, `#ifdef __YASC__` parts left out, owned(D) results as __yl_dealloc(D, n), [:0] parameters as __yl_cstr, view members as __yl_view; comments, macros and conditionals as written. nonnull is not derived from view: C's says null is undefined, and getline / posix_memalign define it (EINVAL). Written only when the bytes change. In C (source/driver/yasc_cheader.c), so it runs on the board too. docs/yasc_c_headers.md. #pragma tcc c_begin / c_end now set the file's dialect, as #pragma yasc does, and take effect at once also in the lookahead past a saved body: an #include inside a C section, or a header right after one full of static inline functions, fell back to yasc and its plain pointers became errors. Tests: test_yasc_c_header.py (translation, gcc -std=c99 -pedantic on the output, a yasc unit reading the source, errors, the c_begin cases). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…where the type says so
A parameter's own pointer (the last '*' before its name, or before the
',' / ')' of an abstract one) is a view unless it says owned or
borrows(...): the most a callee can do with it is look, and anything more
is an error in its body. Only what changes hands is written (owned,
drop ... owned), with maybe and inout / out. `view` written there anyway
is -Wredundant-view (safe default, with a fix-it). Inner levels, an
array's element (`char *a[]`), a function's result (`char *g(int)`), a
slice's element and every non-parameter pointer still say it, and an inner
level is said at once (no guess from the body); a pointer to a function
stays exempt, so `int (* view cmp)(...)` still means never null. A view
parameter that is freed, kept or returned as owned is one error naming it
("the parameter 'p' owns nothing (a view unless it says owned): ...").
-fmodule-header writes `const *` for an in parameter that did not write
view.
An int is a number, never a view by default: a handle stored in a plain int
(a parameter, a local, a global, a member, a result) is an error, and
`(int)fd` takes its number on purpose. A regular-C int parameter cannot
say it: an owned handle goes there as borrow(fd) / move(fd), a view as it
is. That a parameter is regular C's is YASC_PARAM_C on its Sym, kept
through a parked prototype (PARK_C).
Tests: test_yasc_param_view_default.py; the yasc tests, examples and docs
drop the parameters' `view`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`auto q = (char * owned)malloc(n);` (or cast<ptr(T * owned)>(malloc(n))) was "'auto' would copy an owned pointer" while `char * owned q = ...` took it: the cast drops YASC_FRESH and decl_auto_infer rejected every owned non-fresh value. Only a copy of an lvalue (variable, member, dereference) needs move(...) or borrow(...), as yasc_verify_move has it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A C cast does whatever it takes; a yasc cast lists what may change (docs/yasc_casts.md). One permission carries the type -- as, int, trunc, bits, float, enum, ptr, addr, fn, qual -- and align / align(N) and qual add to a pointer cast: cast<int(uint16_t)>(n) the value must fit: a trap if not cast<ptr(struct dirent *), align>(buf + n) alignment proven or checked unsafe_cast<qual(char *)>(s) drops const (strchr) - int, enum and align are checked where the types do not prove them (constants at compile time, a compare and a trap otherwise; -fno-sanitize=cast drops them); qual, fn and addr from an integer need unsafe_cast; a modifier that allows nothing is an error; qual refuses a const or volatile object. - The outermost '*' of the cast's type may spell no owned/view/maybe: it takes the operand's. - In yasc a C cast is -Wold-style-cast, an error in the safe default, whose message names the cast to write; (void)x stays, and a regular-C header's macro with a cast reads as C. - -Wcast-align names both types and alignments, reports two casts on one line apart, and skips an array whose place is aligned enough (_Alignas, a member at an aligned offset), as clang. Tests: test_yasc_casts.py (runtime cases on QEMU at every -O), the yasc test snippets and examples rewritten to the new casts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
"plain pointer in yasc: say owned or view" with no name did not say which
'*' of the line it meant (`char **g` gave two identical errors, a cast or
sizeof gave no hint). It now ends "for 'char *'" / "for 'char **'" -- the
pointer's own type -- and the caret goes under that spelling when the line
has it once. Errors that name a variable ("for 'loc'") stay as they were.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A local pointer variable's own '*' no longer needs a word: like a parameter's, it is a view by default -- a `view maybe` from its declaration on, so every check (regular C -> view needs unsafe, restrict, null where dereferenced) treats it as a written one, and what it holds is what flows into it. When the body owns it (gives it an owned result, frees it, hands it to an owned/drop parameter, stores or returns it as owned) the error stays, now "plain pointer in yasc: 'p' owns what it points at, say owned", with the note and the `* owned` fix-it; its flow variable is silenced as before. Arrays of pointers, inner levels, statics, results, members and globals still say it. An owned variable or member copied into a local is a borrow, not "an owned value": only an owned result (malloc(n)) makes a local owned. -Wredundant-view also covers `view maybe` on a local (fix-it: `* maybe`); `T * view p` on a local says more -- never null -- and stays quiet. Tests reworked for the rule (fix-its, error order, two on a line, aliases, every level), docs (cheatsheet, tutorial) and examples updated. tests/ir_tests: the same 44 known YasOS-config failures as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POSIX kept `char *` for strings the caller must not write (dlerror,
strerror, getenv). qual refuses a const object (check 1), rightly for
every other cast, so libc could not write dlerror's
`unsafe_cast<ptr(char *), const>("")`.
`const` (or `const(T *)`) drops const and nothing else, from a const
object too: the object stays const, only its type loses the word for the
interface. It is unsafe (unsafe_cast); a const that drops no const, or
const with qual in one cast, is an error; volatile and a nested const
added still need qual. qual's const-object error names const.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A local pointer is a `view maybe` unless its function owns it. The inference took `return unsafe(result);` from an owned-result function as the local returning what it owns, and asked for `* owned maybe` on it (libc dl.c dlopen: the handle comes back through a view out-pointer). The value an unsafe(expr) leaves on the stack, until the next statement, now teaches the plain-pointer inference nothing: no PP_RETURNED, no PP_OWNSRC from an owned result given through unsafe(...). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
move(p) given to a regular-C parameter ended p's ownership there, but the same value stored in a regular-C place -- a member of a context struct the kernel takes, by an initializer or an assignment -- left p owning: "'p' leaks: it still owns memory at return" (libc dlclose, `.handle = move(handle)` into dlclose_context). The frontend notes the moved temp for such a store as it does for a parameter, and the flow moves p at the STORE of that temp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`const char * borrows(static) maybe c_api(char *) dlerror(void);` gives one declaration two types: yasc callers and the body see the yasc one, C callers POSIX's. c_api(T) after a '*' stands for everything to its left in that declarator; what is to its right (more '*'s, the name, [ ], the parameter list) stays the yasc declaration's, so `out const char * borrows(s) c_api(char *) * maybe endptr` is `char **endptr` in C. T may differ from the yasc type in const and volatile only: a pointer for an int, int for long (same size on ARM, not on x86_64), char for int are errors, as is a C type that is const where the yasc declaration may write (an inout parameter, a member; a result may say more const in C). A regular-C declaration of the function in a yasc unit is compared with the C type, in either order, and the function converts to a pointer of exactly that type. Two yasc declarations with different c_api(...) are an error. The state lives outside type_decl's and post_type's frames (test_parse_stack_depth: no growth on the recursive parse path); a prototype with it is never parked (its facts are keyed by the type Sym). tcc -yasc-c-header writes T in the C header and, on a prototype, __yl_c_api(n, yasc type). In regular C that attribute (yasc_c_api(n, T)) feeds -Wyasc-c-api (ir/capi_check.c, on by default, also under -ccompat): a store through what such a function returned or stored through an out argument, directly, through a variable or after pointer arithmetic, or passing it to a pointer-to-non-const parameter, in the order the code is written. A string builtin redirected to its helper keeps the call's facts (tcc_ir_lt_copy_call). -fmodule-header reports c_api(...) instead of writing C for it. docs/yasc_c_api.md; tests/ir_tests/test_yasc_c_api.py (43). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tcc_ir_dealloc_check followed a pointer's deallocator through ASSIGN only; move(p) lowers to `T <-- V [LOAD]`, which cleared it, so dlclose(move(p)) with p from malloc, free(move(h)) with h from dlopen and `void * owned q = move(p)` released by the wrong function passed. A LOAD of a vreg's value is a copy: it now keeps the deallocator and the variable it was made from, so the report still names 'p'. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`typedef struct s {...} s;` skipped its members (member view lost its
__yl_view), and `[(c) ? 1 : -1]` lost the ':' (taken for a sentinel).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
decl(VT_JMP) (a for-init declaration) skipped yasc_pp_local_begin, so its plain pointer got "plain pointer in yasc: say owned or view" instead of the local's `view maybe` default (owned when the function owns it, `view maybe` redundant). The two examples drop their now redundant `view maybe`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test_fortify/test_yasc_libgen (which skipped quietly without include/sys/_fortify.h), alloc_trace's CROSS_FLAGS and the yasc C headers doc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…) and default arguments, tcc -format, fortify from sized parameters Pointer syntax: `*?` (may be null), `*owned`, `*@(const, owned)` against the '*', `[?n]` / `[?]` in a parameter's brackets, `int ?owned(close) fd`; `maybe` is gone and a word apart from its '*' is a lexer error (scripts/yasc_pointer_words.py rewrites old sources). View by default: plain locals (never null; `*?` allows it), struct members, globals / statics / externs (array elements too), inner levels of locals and `**` parameters; null stores through a[i] = v / *p = v are checked; conversion warnings name the argument. Global borrows (`T *borrows(zfile) g`, members, the exit / call rule via parameters). In parameters are const on every level (-Wredundant-const for a written one); view results are read-only unless `inout` stands before the type, borrows(params) results come from the arguments, library-owned results (borrows(static)) never inout. -Wparam-access: inout wider than the body uses, self-moves, inout on a const target. `unused T x` / `unused(a, b);`. out / inout / drop are words only where a parameter starts. `= undefined` passed to an in / inout parameter is an error, aggregates followed. @src() and C++-style default arguments: yasc_src is a two-word value {per-function header, line}; `void log(char *m, yasc_src at = @src())`; docs/yasc_default_args.md. Fortify from the declarations: `T p[n]` / `T p[?n]` (n before or after p) is `T *p` + `__yl_access(mode, p, n)` in -yasc-c-header output (in parameters read_only, out write_only, inout read_write) -- fixes the generated header that named a later bound; -ffortify checks strcpy / strcat / sprintf by name; `yasc_unsafe` functions are called by yasc code inside unsafe only (-Wyasc-unsafe-call); __chk_fail is libtcc1's (weak); only a function's own `T p[n]` bounds stop its inlining (any such prototype used to block every later function). Fixes: a cast<...> before a regular-C macro's functions left them checked as yasc (body_calls_unprototyped read `as(` as a call); out / drop on an array parameter reach its pointer. tcc -format [-i|-n]: C and yasc in clang-format's LLVM style, opt-in per directory with .tcc-format, refuses any token change (docs/tcc_format.md). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A .yc file is yasc whatever the command line says: under -ccompat or an explicit -std=c.. it is compiled as without them (the safe defaults, the dialect from its first line), and the options come back for the files after it. A build hands every file the same flags -- build_rootfs.sh gives libc's compiles -ccompat -- so the extension is what tells the yasc sources apart, and gcc / clang never pick one up. `-x yc` (or `-x yasc`) says the same of the files after it, for an editor checking its buffer on stdin; `-x c` goes back to C. AFF_YASC is outside AFF_TYPE_MASK, so TCCState.filetype is an unsigned short now (the char cut the flag off). No extension of its own for modules: one file is one module. `import` looks for a .ymi in the system include directories too, after -I: an installed library keeps its interfaces next to its headers (/usr/include/stdint.ymi). -fsyntax-only writes no interface and no -fmodule-header header: an editor checking an unsaved buffer from the workspace root left them there for later imports to find. docs/yasc_modules.md "File names", the man page and tcc-doc.texi; tests/ir_tests/test_yasc_extension.py, test_yasc_modules.py (test_import_from_system_include_dir, test_no_interface_under_syntax_only). YasOS libc's yasc sources are .yc: test_yasc_libgen.py, alloc_trace. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lines between the two pragmas in a module's own file are compiled as any others and also copied, as written (not preprocessed), into the -fmodule-header= C header, after its #includes: the macros a module cannot export, and #ifdef arms for other compilers and targets. The text is read back from the file by line number at `end` (a #line that moves it is an error); -fsyntax-only and -E read nothing. Errors for an unbalanced block, a block in an #include'd file, a word other than begin/end; a warning for a block outside a module. `#pragma yasc` alone is unchanged, and `#pragma yasc c_header` does not make a C file yasc. Tests: tests/ir_tests/test_yasc_c_header_block.py (16). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… names `import M;` declares M's exports in the importer as the one identifier M.name (an identifier no source spells), `import M as c;` reads `c.name` as it, `import M *;` brings the plain names. The C symbol keeps the plain name, so C links against modules unchanged; an importer's own global or function with an export's C name is an error. A dotted module is its full path (`lib.geom.pt_t`), the longest alias wins. The interface spells the module's own names M.name (.ymi format 2) and names reached through another module by that module's canonical name. Transitive imports are loaded but not named: the importer imports them itself; a tag hides a loaded but unimported module's name (`vec.make()`). The namespace state is reset at the next unit's start, since deferred bodies compile after the module is finished. The next()/sym_find hooks are noinline, off the recursive parse path's frames. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…le checks
`export import M;` re-exports M: importers of the module find M's exports as
its own (`import U *;` plainly, `import U;` as U.x, transitively). The
interface lists a re-exported import as "+M" (.ymi format 3).
A module's C header puts its declarations under `#else` of `#ifdef
__YASC__`; the yasc arm says `#pragma yasc import M`, so an #include of the
header in yasc code is `import M *;` -- the declarations with their yasc
qualifiers -- while C gets the plain ones and both get the c_header text.
The pragma hands the parser TOK___yasc_pragma_import "M" LINE ';' through
the #embed resume path; decl() takes it in a regular-C header of a yasc
unit; -E keeps the line; -fmodule-deps prints it as an import.
-Wimplicit-module-import (off by default): a warning at each #include of
the main file whose header imported a module the file does not import
itself, before or after the #include.
Cycles are said as such: a part of an umbrella importing the umbrella
("re-exports ..., the module being compiled"), #including the umbrella's
header ("brings its own header"), importing it before it exists ("if it
re-exports ..."), a module #including its own header ("imports itself"),
and a header above `module NAME;` that imported NAME ("put 'module NAME;'
first").
Tests: tests/ir_tests/test_yasc_module_umbrella.py (24); the module and
c_header tests follow the new header text and format 3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… drop self must own
- `unsafe_suppress(leak, a, b);`: the named owned variables' leaks are not
reported -- a stub deallocator whose allocator allocates nothing yet, where
unused() still leaves "'res' leaks" at the closing brace (outside any
unsafe { }). Every other check stays; it counts as unused(); no code;
-funsafe-report lists it; a name in scope wins. The C header generator
takes it as a yasc statement. test_yasc_unsafe_suppress.py.
- `?out T *p`: out minus the every-return rule; declaration and definition
agree; an out parameter handed on to ?out may stay unwritten
(test_yasc_maybe_out.py).
- Borrows through T** and address-taken locals followed in the dangling
check (test_yasc_borrows_pointee.py).
- `drop struct S *self` needs an S that owns something its type shows.
- A module's own declaration of a header's external name without `export`
is an error that says to write it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…eaders as modules
Modules: `export public { }` / `export private { }` (two C headers), one
export section at the top, cycles between bodies, a missing or stale
interface built by the importing compile (module sources also found in the
include directories), keyword module names (`module float;`), alias,
@Assert, @NoReturn, constexpr functions and header forms, word aliases,
c_header blocks after/unguarded, typedefs of a compiler type macro kept in
the C header, `bool` headers include <stdbool.h>, one typedef from two
`import *` modules is one name.
Fixes: the C header note no longer outlives its import (freed file name),
module roots without dir/.. chains, a restart after an interface build
keeps quiet imports' macros, -fsyntax-only demands no C text, a function in
a c_header block does not end the export section.
include/: stddef, stdarg, float, stdnoreturn, stdatomic, tgmath, arm_acle,
yasc and yasc_src are modules writing their headers (`make headers`);
<stddef.h> is C23's names. Also @bswap, -mcpu profiles, FP contraction
(FMA) and ACLE DSP intrinsics, UBSan and SSP in libtcc1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yasc_member_alias_use asked find_field for the member by its plain name, which raises "field not found" on a miss: an alias name never reached its path. The SYM_FIELD form answers null. Test: a struct's `alias st_atime = st_atim.tv_sec;` through an importer (yasc reads the path, C gets POSIX's #define), an unknown first member an error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A _Complex member of a constant-initialised local struct/union is read through the folded .data copy once symref_prop rewrites the pointer into a symref operand. The fresh operand dropped is_complex, so the call lowered the argument as one scalar and the callee lost the imaginary half (-O1/-O2/-Os, float, double and long double). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he build's spelling Long double is VT_DOUBLE | VT_LONG here, but __builtin_infl/nanl/huge_vall, modfl and copysignl gave a bare VT_LDOUBLE, usual arithmetic conversions (combine_types) dropped VT_LONG, and the conjl/creall/cimagl fold made the result plain double. __builtin_complex rejected the mix and _Generic picked double for ld + ld. VT_LDOUBLE_T and is_long_double() in tcc.h now name the one spelling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the core argument moves
emit_vfp_arg_moves copied a float or double argument whose value (or
address) sat in a core register into its s/d register only after the
r0-r3 argument moves, which may already have overwritten that register:
`check("x", id(v), K, 0, 0)` passed K as the float, and a by-value struct
in r0-r2 replaced a double staged in r0:r1. Those arguments now join
phase 0, before the core moves; only immediates and memory are still
materialised afterwards.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…bles grow
NestedFunc kept its captures and the parent typedefs, enumeration constants,
statics and tags in MAX_CAPTURED_VARS (32) entry arrays and dropped the rest
silently ('v32' undeclared); the IR state mirrored the captures in 32 entry
arrays too, so a 33rd capture that did compile read 0. The NestedFunc tables
grow (nested_capture_add, nested_parent_*_add, freed by nested_func_release),
NestedEnv sizes its bindings at entry, the prescan's parameter list and the
inliner's genuine-capture list are vectors, and TCCIRState keeps one owned
IRCapture array. MAX_CAPTURED_VARS is gone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e script's last data section A linker script without .got placed it after every script section, after .bss in .data's PT_LOAD, at .bss's file offset: a loader copied its bytes over .bss. Writable PROGBITS orphans now join the last output section with writable file contents, as GNU ld places them. test_segment_sizes_stop_at_ file_contents links -static and checks each section's file offset. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… prototype: the prototype makes the nested function A block-scope `auto` function prototype was declared as an extern, so a call or an address taken before the nested definition bound the global name with no static chain (undefined symbol, or a silent call of an unrelated global). parse_btype now records `auto`; such a prototype makes the nested function's Sym and NestedFunc slot up front (static chain, trampoline, nested_chain_level all reach it) and the definition in the same block adopts it. A prototype with no definition in its block, or a definition of another type, is an error as in gcc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…test
A nested function calling through its parent's `int (*sp)(int)` failed to
compile ("too few arguments"): the capture's CType pointed at the parent's
function-type Sym, freed when the parent's scope closed. 944967e fixed
it incidentally -- inside gen_function sym_pop parks such Syms on
outlived_locals until after compile_nested_functions. The test pins it
(function pointers, arrays of them, pointer to array, depth 2, a store from
the nested body); under SYM_DEBUG + valgrind the old sym_pop gives invalid
reads in unary_funcall / is_compatible_func, the current one none.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
unary_funcall_body let a nested callee past INLINE_NEST_MAX and inline_expansion_in_progress, so l1 -> l2 -> l1 expanded until the compile was killed at -O2/-Os (base f6d53136). On this tree the shadowed-name check refuses the re-entry by accident; the gate now bounds it itself. A nested callee still skips the return-type list. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… activation Taking a nested function's address stored the static chain in one .data slot per nested function, read by a static trampoline, so a recursive (or re-entered) parent's inner activation overwrote it and a pointer made by an outer activation called the nested function with the innermost frame. INIT_CHAIN_SLOT now writes a 16-byte trampoline into the taking frame (ldr.w sl,[pc,#4]; ldr.w pc,[pc,#4]; chain; target), DSB + ISB, and returns its address | 1. The frontend reserves the block in loc and the frame floor keeps it (nested_tramp_floor, as __builtin_apply_args' block). YasOS maps the user RAM pool executable, so the stack block runs there. Test bug_nested_fnptr_per_activation: recursive parent, pointer kept across deeper activations, sibling address, qsort comparator, address taken in a loop; failed at every level before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n mark onto complex lvalues svalue_to_iroperand skipped every alignment mark for complex operands, so a packed member's underaligned bit was lost and the by-value struct argument path trusted the type's 4-byte alignment: `ldrd r0, r1, [p+1]` / `ldmia [p+3]` faulted (UNALIGNED). Complex lvalues now get IROP_AUX_UNDERALIGN (never ALIGN4_OK), and struct_src_addr_aligned4 refuses an underaligned source before consulting the type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…removes the file tcc_write_elf_file now checks fflush/ferror and fclose after the writer returns; a full disk or file size limit used to leave a truncated object or executable and exit 0. test_output_write_errors.py covers -c and link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ed of the module's c_header text `import M: x;` in an export block copied M's whole c_header text into the C header: its hand-written `#pragma yasc c_header` blocks and every `constexpr if` typedef. The loaded interface now keeps each block's end, and a name-list re-export takes M's constants (they come with any name), the `constexpr if` typedefs and word aliases that a listed name or a kept declaration needs (transitively, arms kept), and a hand-written block only when it defines such a name. libc's dirent.h loses stddef's NULL, offsetof, unreachable, nullptr_t and friends for its one size_t. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the member held
lt_instr's owned = owned move copied the source's state, and a member path
not followed yet is LT_UNINIT ("what its struct owned"). The variable moved
into then owned nothing: a takes(v) call did not leave it to the caller on a
null result (`'old' is used after it was moved` on realloc's failure path),
and its leaks went unreported. A path's LT_UNINIT now moves as LT_OWN, as a
move out of a global does.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ne may write the target `char *q = buf + 2; q[0] = 'x';` folds the assignment into the add (`V0 <-- P0 ADD #2`), which the out-parameter check never counted as handing the pointer on, so `out char buf[n]` was reported "not written". An add/sub of an out parameter's pointer into a variable now counts like a copy of it. inout parameters keep their own -Wparam-access tracking of offsets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… keeps both arms
try_inline_const_eval folds a `{ return expr; }` call to a constant at -O1+,
and an `if`/`while`/`&&` on it turned the untaken arm off before lifetime.c
saw the raw IR: a leak on an early return there went unreported above -O0
(utest's ASSERT_EQ on such a call). The folded result is VT_NONCONST now (a
call is never a constant expression, and -O0 never folds it), and a
condition on a VT_NONCONST integer is tested at run time
(tcc_ir_codegen_cond_nonconst); the passes still drop the dead arm.
VT_NONCONST shares its bit with VT_MUSTCAST's high bit: default argument
promotion now skips the delayed char/short cast for a constant, as
type/cast.c already did (a folded enum result as a variadic argument
crashed gen_cast).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the return reads them ssa:narrow turns a truncated UMULL/SMULL into a 32-bit MUL (fresh operand slots: an ASSIGN has no src2), the PACK64 feeding RETURNVALUE hints its lo/hi sources to r0/r1, and the r0 return hint marks every copy on the chain, not only its root. time_now_timespec: `umull r0,r1; mov r1,r0; mov r0,r4` -> `mul r1,...; mov r0,r4`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…xpr line numbers, checker and codegen fixes Regression tests for each fix (load CSE alias class, dead def across branches, nested-fn cleanup static chain, typed overflow builtins, naked return, duplicate link symbols, module header includes, ...). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n test_tccgen size.c and cond.c call them now; the tccgen unit binary failed to link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e code reads through r9 Under -msb-relative-got a global's slot is one ldr.w Rt,[r9,#imm12], so it must lie in the GOT's first 4096 bytes; a PLT stub holds its slot offset in a literal. build_got_entries made the PLT slots first (ld.so's order), and the native tcc's ~440 globals behind ~90 imports no longer linked. With text/data separation the R_GLOB_DAT pass now runs first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gnulib's regex.h #undefs <limits.h>'s RE_DUP_MAX, which the module-generated header marks constexpr: ctags stopped building. The error holds in a yasc unit (its main file, so an import's constants still conflict); C gets C's rules and the usual 'redefined' warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libtcc1.a is built before there is a C library; a cross without a sysroot (CI) found the host's glibc stdint.h and failed on bits/libc-header-start.h. The types come from the compiler's own __UINTPTR_TYPE__ and fixed widths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kl is read only when lt is set, right after its assignment; Debian's gcc 12.2 on the rig's Pi cannot tell through the unity inlining and the metrics job's -Werror build failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- decl: a saved body's file name is interned before the body is read; a header that ends with the body is closed (its name freed) by the time the dialect is looked up. - yasc modules: an import that leaves by longjmp (the stop that has the driver build a missing interface, or an error) no longer loses what yasc_import and its callers held: it sits on a held list that the next unit's reset frees. - constexpr functions: the expanded token string's struct is freed. - tcc -format: the token array survives a lexer error return (LSan's exit also dropped the unflushed pass-through text). - -fmodule-header-private= is freed with the state. - tests: the cast qualifier test declares its own malloc/free (the host's <stdlib.h> says nothing of ownership); the truncated-executable test links with -B/-L of the build tree. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
90 ir_tests failed on CI: the CI cross (plain ./configure --enable-cross) has no YasOS sysroot and no tinycc include dir on its search path, so <stdint.h> and <regex.h> fell through to the host's glibc headers and <stdarg.h> was not found. Locally a YasOS-configured cross and a stale /usr/local/lib/tcc hid it. - test_at_min_max (and test_at_bswap through it), test_yasc_casts, test_yasc_ownership, test_compiler_fortify: cross_includes.INCLUDE_FLAGS (-nostdinc, the tests' newlib headers, tcc's include/) - test_yasc_ownership: regex_t / regfree declared in the fixture (newlib's <regex.h> does not parse as yasc) - test_yasc_facts: -fno-yasc-facts for the "plain" object, the facts are on by default - test_yasc_attr_alias_qconst: host gcc -std=c2x (gcc 13 rejects c23) 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.
The yasc dialect rounds since #30, the module system, and the fixes the libc port and the YasOS build turned up. Rebased onto
mob(#29 and #30 dropped as already merged; the tree is unchanged by the rebase).yasc
.ycsources; modules with one export section (export public/export private), namespaces (import M;→M.x,as c,*,import M: x, y;), interfaces built on demand, C headers generated from modules (#pragma yasc c_header, header body guards), tcc's own headers as modules*?owned,*owned,*@(...)), view by default for params, locals, members and globals; deep in-const;?out,unsafe_suppress(leak, p),@src()and default arguments,cast<>/unsafe_cast<>,c_api(T),alias,@assert, constexpr functionstcc -format(C and yasc layout),-Woverride-init,-yasc-c-headerFixes (each with a regression test)
_Complexmembers, r0/r1 struct-return moves, long double spelling, nested-function trampolines per activation and capture tables,-staticorphan.got-Wlifetimeleak above -O0, out buffers written through an offset, owned values moved out of a member, borrows throughT**ldr [r9, #imm12]reach (test_got_sbrel_plt_last.py)#undef/ redefine a constexpr constant from a module-generated header (gnulibregex.handRE_DUP_MAX); yasc units keep the erroryasc_tag_completeandtcc_ir_codegen_cond_nonconstTested locally:
make test -j16passes; IR suite 26319 passed, 213 skipped;build_rootfs.shand the YasOS kernel build with this cross.🤖 Generated with Claude Code