Skip to content

type_match: score only a function's own variables, not its inlined callees' - #113

Merged
mahaloz merged 1 commit into
mainfrom
fix/typematch-skip-inlined-callees
Oct 31, 2026
Merged

mahaloz merged 1 commit into
mainfrom
fix/typematch-skip-inlined-callees

Conversation

@mahaloz

@mahaloz mahaloz commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Reviewer

Huamnb reviewed by Zion. Its a pretty small change. Looks good.

PR

type_match scores an inlined callee's parameters and locals as variables of the function they were inlined into. At -O2 most of them belong to glibc's _FORTIFY_SOURCE wrappers, and the compiled function has no storage for them, so it can never score perfect:

printf '#include <stdio.h>\n__attribute__((noinline)) void banner(int n) { printf("%%d\\n", n); printf("%%d %%d\\n", n, n); }\nint main(void) { banner(1); return 0; }\n' > f.c
gcc -g -O2 -D_FORTIFY_SOURCE=2 f.c -o f
python -c "from pathlib import Path; from decbench.metrics.type_match import extract_ground_truth_types as g; print([(v['name'], v['type']) for v in g(Path('f'))['banner']])"
# [('n', ['int']), ('__fmt', ['void']), ('__fmt', ['void'])]

With this branch, banner's ground truth is just [('n', ['int'])]. (The void spelling is #94.)

The fix:

  • _parse_function_die skips DW_TAG_inlined_subroutine children. An inlined callee nested inside a lexical block was already skipped, so only direct children of the subprogram were being scored.
  • Across the corpus this removes 92,411 of 297,193 ground-truth variables at O2, 39,999 of 318,383 at O2-noinline, and 8,345 at O0. A function whose only ground truth came from inlined callees has no type_match value any more: 123–231 per backend at O2, 81–120 at O2-noinline, 20–34 at O0.
  • Ground truth is part of the type_match cache key, so cache_version is unchanged.

Re-scored from the published checkpoints. Each cell is perfect functions before → after:

angr binja dewolf ghidra ida kuna r2dec
O2 1115 → 1517 1275 → 1708 551 → 794 1032 → 1485 1157 → 1615 764 → 1025 185 → 230
O2-noinline 2336 → 2649 2635 → 2985 1431 → 1637 2285 → 2623 2256 → 2632 1659 → 1847 522 → 532

O0 moves by +26 or less per backend. Neither perfect count nor mean changes the order of the seven backends at any opt level.

Some functions do lose: when a decompiler had matched an inlined callee's variable, that true positive is no longer scored. At O2 this is 0–148 functions per backend, against 2,086–5,954 that improve.

Refreshing the published overlay drops those functions' type_match values. The finalize_results.py coverage guard will therefore report them, and the rebuild needs --allow-drops.

Tests: tests/test_metrics.py compiles a noinline caller with an inlined static inline helper at -O2. It checks that the DWARF really has the inlined subroutine, and that the caller's ground truth holds its own x and none of the helper's value/doubled. It fails on main.

Fixes #97.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Cw8GgP4ynoKxZeBJ7RWZiN

…s inlined callees'

_parse_function_die descended into every DW_TAG_inlined_subroutine child of a
subprogram and scored the callee's parameters and locals as the caller's.
At -O2 most are the parameters of glibc's _FORTIFY_SOURCE wrappers (`__fmt`,
`__stream`), which have no storage in the compiled function, so no decompiler
could ever match them. Inlined callees nested inside a lexical block were
already skipped, so the two depths disagreed.

Inlined subroutines are now skipped at every depth. A function whose only
ground truth came from inlined callees no longer has type_match ground truth.
The ground truth is part of the type_match cache key, so cache_version is
unchanged.

Fixes #97.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cw8GgP4ynoKxZeBJ7RWZiN
@mahaloz mahaloz changed the title [AUTOMATED] type_match: score only a function's own variables, not its inlined callees' type_match: score only a function's own variables, not its inlined callees' Oct 31, 2026
@mahaloz
mahaloz merged commit cdd2df9 into main Oct 31, 2026
5 checks passed
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.

[AUTOMATED] type_match: an inlined callee's parameters and locals are scored as the caller's variables

1 participant