Skip to content

fix: resolve latest codecheck findings in ptoas and ptobc - #1474

Draft
jimmychou0 wants to merge 2 commits into
hw-native-sys:masterfrom
jimmychou0:zjm/codecheck-fix-4-rebased
Draft

fix: resolve latest codecheck findings in ptoas and ptobc#1474
jimmychou0 wants to merge 2 commits into
hw-native-sys:masterfrom
jimmychou0:zjm/codecheck-fix-4-rebased

Conversation

@jimmychou0

Copy link
Copy Markdown
Contributor

Summary

Resolve the latest codecheck scan for tools/ptoas and tools/ptobc (41 findings: 36 fixed, 5 not-applicable with reasons) and fix the CI duplication findings across the split ptoas TUs. Rebased cleanly onto the current main (75e4a22) — replaces the closed #1462; base moved from main to master (new default branch).

  • G.CNS.03 — const-ify the five pure Encoder::encode*Immediate helpers (CmpPredicate/Event/MakeTensorView/PartitionView/AllocTile); encodeConstantImmediate still mutates file via internType and stays non-const.
  • G.INC.02 — drop 11 redundant includes across ptoas.cpp / ptoas_pipeline.cpp / ptoas_cpp_rewrite.cpp / ptoas_name_hints.cpp.
  • G.EXP.27 / G.EXP.36if (info.has_variant_u8)!= 0; unsigned += bool counters → explicit if { ++n; }; int hex operand explicitly cast to unsigned before |.
  • SecK_MemoryAndResourceLeakChecker — the decoded mlir::Block is owned by std::unique_ptr until region.push_back, so a mid-decode exception can no longer leak it.
  • G.CNS.02 — name the hex-escape length/offset (3/2) and SmallString capacity (128) constants.
  • G.FMT.17 / G.CMT.04 — remove the blank line at the start of parseNameHintMarker, the orphan // in the driver job-topology diagram, and the run of blank lines after namespace { in ptoas.cpp.
  • Duplication (CI) — the ptoas.cpp split had copied the same ~70-line include list into all four TUs; the 62 includes common to all four now live in ptoas_internal.h and each .cpp keeps only its TU-specific includes (net -232 duplicated lines).

Not applicable: borrowedContext ctor / initializeMLIRContext / getMLIRContext (mutable-by-design semantics), pybind11_init__core (macro-generated), char **argv (C main ABI).

Test plan

  • 144 host, LLVM 19.1.7 assert build (GCC 13.3): full build warning-free under -Werror.
  • CTest 69/69 (45 PTO/PTODSL + 23 PTOBC + smoke).
  • Cross-TU include intersection is now empty except the ptoas_internal.h chain; git diff --check clean.

- const-ify the five pure Encoder::encode*Immediate helpers that do not
  touch mutable Encoder state (encodeConstantImmediate still interns
  into file and stays non-const)
- drop redundant includes: ptoas.cpp (cctype/csignal/cstdlib/cstring/
  sys/types.h/unistd.h), ptoas_pipeline.cpp (csignal/cstring/unistd.h),
  ptoas_cpp_rewrite.cpp and ptoas_name_hints.cpp (Arith/Tensor
  BufferizableOpInterfaceImpl)
- replace unsigned += bool counters in VFSIMTSizePatcher with explicit
  if/increment blocks
- make if (info.has_variant_u8) an explicit != 0 comparison and cast the
  int hex-decode operand to unsigned before the bitwise or
- own the decoded mlir::Block with std::unique_ptr until region
  push_back so a decode exception can no longer leak it (SecK finding)
- name the hex-escape length/offset and SmallString capacity constants
  instead of magic 3/2/128
- remove the stray blank line inside parseNameHintMarker, the orphan //
  line inside the driver job-topology diagram, and the run of blank
  lines after namespace { in ptoas.cpp

Validated on the 144 host (LLVM 19.1.7 assert build, GCC 13.3): full
build warning-free under -Werror and CTest 69/69 passes.
The ptoas.cpp split copied the same ~70-line include list into all four
translation units, which the duplication checker now flags across
ptoas.cpp / ptoas_cpp_rewrite.cpp / ptoas_name_hints.cpp /
ptoas_pipeline.cpp. Move the include set common to all four TUs into
the existing internal header ptoas_internal.h and keep only the
TU-specific includes in each .cpp (Arith/Tensor Bufferizable
registrations in ptoas.cpp and ptoas_pipeline.cpp, <cctype> in the two
text-rewrite TUs), dropping includes already removed as unused.

Net -232 duplicated lines; each TU compiles with an unchanged effective
include set. Validated on the 144 host (LLVM 19.1.7 assert build):
warning-free build under -Werror and CTest 69/69.
@jimmychou0
jimmychou0 force-pushed the zjm/codecheck-fix-4-rebased branch from f605624 to 935eabc Compare September 7, 2026 01:20
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