Skip to content

lint-c passes on main again: tests initialize their textures where they live and check the archives they reopen, four analyzer false positives are marked, and the baseline drops 15 findings main no longer has - #1602

Closed
PucaVaz wants to merge 1 commit into
seedds:mainfrom
PucaVaz:lint-c-green

Conversation

@PucaVaz

@PucaVaz PucaVaz commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

main's lint-c (clang-tidy ratchet, LLVM 23.1.4) has failed since b1d7c70, and every pull request's merge with main inherits it. The last completed run on main, 42264410010 on 6bbdbbe (main's tip b2d46b8 changes no linted file), had 8 file/check pairs above the baseline and 12 below it. This change takes both to 0: 225 findings against a baseline of 225.

Above the baseline: fixed

File Check Introduced by Change
dm/gfx/tests/t_dlss_mfx.m, t_upscaler_mfx.m clang-analyzer-core.StackAddressEscape b1d7c70 Since b1d7c70, g_tex_live holds the address of the object mtl_tex_init is given, and mtl_tex_release reads it to tell a finalized copy from the object. The tests' texture() initialized a local and returned a copy, so each entry pointed into its dead frame. texture() now initializes the caller's object.
dm/gfx/tests/t_depth16_clear.m clang-analyzer-core.StackAddressEscape b1d7c70 production_clears returned on a failed calloc after registering its two stack targets, without releasing them. The allocation comes first now.
dm/gfx/tests/t_pso_stall.m clang-analyzer-nullability.NullablePassedToNonnull (2, baseline 1) reported since 88c7e03 (the code is 6e06ac4's) reopen() added each archive to an NSMutableArray unchecked; one that does not open would throw. Each is checked with EXPECT and left out when nil. The older finding (line 107) stays in the baseline.

Above the baseline: false positives, marked with // NOLINT(<check>) and the reason

File Check Introduced by Why it is not a bug
dm/gfx/nvn/nvn_mtl.m pkg_share_put clang-analyzer-osx.cocoa.RetainCount ("leak of 'r'") b1d7c70 g_pkg_share owns the NvPkgRef through hm_put_id's CFBridgingRetain until hm_del_id or a replacing put releases it, as for the hm_put_id tables already marked (g_pbase_pending).
dm/gfx/nvn/nvn_mtl.m mtl_pool_addressed clang-analyzer-security.ArrayBound ("memory preceding the heap area") b1d7c70 The path assumes i == g_naddr, i <= 0 and g_naddr == g_addr_cap != 0, so a negative index. i comes from addr_first, which returns 0 to g_naddr, and g_naddr changes only on that line, from 0 up by one insert or down by a merge that keeps at least one range.
dm/gfx/nvn/nvn_mtl.m pool_seen_scan clang-analyzer-core.BitwiseShift ("right operand is negative") b1d7c70 The path takes the second word (i = 1) and assumes id_ = 32 + b <= 0, so b <= -32. b is __builtin_ctz of a non-zero word, 0 to 31.
dm/gfx/tests/t_feedback.m bugprone-signed-char-misuse 0cefa86 fx holds attachment indices and -1 for a constant not read from the tile (fb_tile_plan); bf_fn passes them as int function constants, so the -1 has to sign-extend. The cast the check suggests would make it 255. nvn_mtl.m's own copy in warm_task is already a baseline entry.

The other nvn_mtl.m findings in the failing run's annotations ('ps' RetainCount, S.stream and g_mrb ArrayBound) are the baseline's existing entries, present in the last green run (95f9a6a).

Below the baseline: lint_c.py tidy --update

The baseline goes from 240 to 225 findings:

  • 14 clang-analyzer-osx.cocoa.RetainCount entries of t_alpha, t_defer_chain, t_geometry (2), t_geometry_feedback, t_present_snap, t_primitive_restart, t_pso_pending (2), t_rt_range, t_unwritten_store, t_view_swizzle (2) and t_zskip, gone since d4239a6 (present at bd9f422, absent at d4239a6). t_feedback.m's two RetainCount findings, above a baseline of 0 in earlier failing runs, went with them.
  • One of t_image_alias.m's two NullablePassedToNonnull entries, gone since b1d7c70 (two at b1d7c70~1, one at b1d7c70).

No open pull request fixes these: #1389 and #1275 list the same pairs as coming from main and leave them.

Testing

With LLVM 23.1.4 (the release and sha256 lint-c.yml pins) and Xcode 27.2 (DEVELOPER_DIR, as CI), on an M4 Mac:

  • python3 dm/tools/lint_c.py compdb && python3 dm/tools/lint_c.py tidy -j 8 --against origin/main: 225 findings, baseline 225, 0 pairs above it, 0 below it, the baseline not grown over origin/main; exit 0. Against CI's report for 6bbdbbe the only difference is the 8 findings above. On unmodified main, the same clang-tidy with Xcode 27.0's SDK reproduced CI's report finding for finding, plus 8 parse errors in front_mac.m from that older SDK.
  • python3 -m unittest dm/tools/tests/test_lint_c.py: 19 tests pass.
  • make -C dm/gfx/tests GAME=0400486024DEC000 with check_t_depth16_clear (1042 depths, both production clears match the fragment), check_t_dlss_mfx (7 checks, 0 failed, encoding thread off and on), check_t_upscaler_mfx (91, 91 and 12 checks, 0 failed), check_t_feedback (193 checks, 0 failed) and check_t_pso_stall (44 checks, 0 failed): all pass.
  • make -C dm/host GAME=0400486024DEC000: the Mac host builds.

…ey live and check the archives they reopen, four analyzer false positives are marked, and the baseline drops 15 findings main no longer has

clang-tidy's ratchet (LLVM 23.1.4) has failed on main since b1d7c70: 8 file/check pairs above the baseline, and since d4239a6 12 below it.

Fixed in the code:
- t_dlss_mfx.m, t_upscaler_mfx.m (clang-analyzer-core.StackAddressEscape, from b1d7c70): g_tex_live now holds the address of the object mtl_tex_init is given, which mtl_tex_release reads to tell a finalized copy from the object itself. The tests' texture() initialized a local and returned a copy, so every entry pointed into its dead frame. It initializes the caller's object now.
- t_depth16_clear.m (the same check, from b1d7c70): production_clears returned on a failed calloc after registering its two stack targets, without releasing them. The allocation comes first now.
- t_pso_stall.m (clang-analyzer-nullability.NullablePassedToNonnull, reported since 88c7e03): reopen() added each archive to an NSMutableArray unchecked, and one that does not open would throw. It is checked (EXPECT) and left out.

False positives, marked on their lines with // NOLINT(<check>) and the reason:
- nvn_mtl.m pkg_share_put (clang-analyzer-osx.cocoa.RetainCount, b1d7c70): g_pkg_share owns the NvPkgRef through hm_put_id's CFBridgingRetain, as for the other hm_put_id tables already marked.
- nvn_mtl.m mtl_pool_addressed (clang-analyzer-security.ArrayBound, memory preceding the heap area, b1d7c70): the analyzer takes addr_first's index and g_naddr for any int; the index is 0 to g_naddr, which is never negative.
- nvn_mtl.m pool_seen_scan (clang-analyzer-core.BitwiseShift, b1d7c70): b is __builtin_ctz of a non-zero word, 0 to 31; the path assumes it below -32.
- t_feedback.m (bugprone-signed-char-misuse, 0cefa86): fx's -1 (a constant not read from the tile) must reach bf_fn as -1; the cast the check suggests would make it 255. nvn_mtl.m's own copy in warm_task is already a baseline entry.

Baseline: lint_c.py tidy --update drops what main no longer has, 240 to 225 findings: 14 clang-analyzer-osx.cocoa.RetainCount entries of 11 tests, gone since d4239a6, and one of t_image_alias.m's two nullability entries, gone since b1d7c70.
@github-actions github-actions Bot added nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) tools Tools and scripts (dm/tools, scripts) labels Nov 7, 2026
@PucaVaz

PucaVaz commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Closing: be23843 on main brings the analyzer ratchet back to passing (and fe08273 follows it up), which was this change's whole purpose, and this branch now conflicts with main. Nothing here is still needed.

@PucaVaz PucaVaz closed this Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) tools Tools and scripts (dm/tools, scripts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant