Skip to content

Facade evidence: attributes are also read from Clang's AST; a package function annotated malloc is an allocator call - #3205

Merged
ehartford merged 2 commits into
mainfrom
png-malloc-attr
Nov 9, 2026
Merged

ehartford merged 2 commits into
mainfrom
png-malloc-attr

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Part of #3115 (found with #3168's libpng). Two commits. (1) CiFacadeDraft: a pointer-returning function of the package annotated malloc/__malloc__ is an allocator call, and a callee with no reason yet is said from its return type, never (). (2) ClangBridge: a function's attributes are also read from its AST attribute children, tokenized at their spelling; libpng passes PNG_ALLOCATED as the last argument of a function-like macro from another header, and the declaration's own tokens read nothing (no attribute on any of libpng's 256 functions). Result on libpng: png_create_read_struct and png_create_info_struct are proven owned; what remains is the png_structpp destroyer shape (#3177/#3119). Fixtures conan_facade_malloc_attr_void_test, conan_facade_macro_arg_attr_test. Battery GREEN on 2fd9f10 (with run tools/battery.w in ~/.local/with-staging/ipngalloc, wall 371 s after a green gate and internals lane; GREEN BATTERY_DONE).

Eric Hartford added 2 commits November 9, 2026 13:40
…l (either spelling), and a callee with no reason yet is never said as '()'

libpng's png_create_info_struct returns `(png_inforp)png_malloc_base(…)`;
png_malloc_base returns `void *` and carries PNG_ALLOCATED, which is
`__attribute__((__malloc__))` (it may also call a user hook, so only the
annotation proves the allocation). The drafter honoured malloc only on a
function returning a record pointer and only in the plain spelling, so
the producer stayed raw with 'png_malloc_base is unproven ()': the empty
cause because the callee's own verdict had not been reached in that
pass. A pointer-returning function of the package annotated malloc (or
GCC's reserved __malloc__) is now an allocator call, as libc's malloc
and a global initialized to it are (D121), and an unreached callee is
described from its return type.

Found with the #3168 fix (libpng reads 256 functions, was 0).
Fixture: conan_facade_malloc_attr_void_test (the macro-spelled
__malloc__ before the return type, and the plain malloc after the
declarator, both allocators with a user hook); it fails on main with
'thing_alloc is unproven ()'.
…ST, at their spelling

with_cimport_fn_attributes read a declaration's attributes from the
tokens of its extent. libpng declares every function through a
function-like macro whose last argument is the attribute macro
(`PNG_INTERNAL_FUNCTION(png_voidp, png_malloc_base, (…), PNG_ALLOCATED)`,
PNG_ALLOCATED being `__attribute__((__malloc__))` in pngconf.h): the
extent starts in one file and ends in another, its tokens read nothing,
and libpng's report showed no attribute on any of its 256 functions. The
function cursor's attribute children are now visited too, each tokenized
at its spelling (inside the #define that wrote it), and the entries the
token scan did not already give are added. Only the facade scan reads
these attributes (D121 step 3 evidence); migrated corpora are untouched.

Fixture: conan_facade_macro_arg_attr_test (libpng's layout: the
attribute macro in one header, a function-like export macro, the
attribute as its last argument; fails on main: no attribute, producer
raw).
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