Skip to content

Fix compiler warnings - #83

Merged
kyakuno merged 14 commits into
masterfrom
claude/fix-compiler-warnings
May 6, 2026
Merged

Fix compiler warnings#83
kyakuno merged 14 commits into
masterfrom
claude/fix-compiler-warnings

Conversation

@kyakuno

@kyakuno kyakuno commented May 5, 2026

Copy link
Copy Markdown
Contributor

Resolve all default-level GCC/Clang format-string warnings:

  • audio_processing/gpt-sovits: cast std::chrono ms count to long long to match the %lld specifier (twice).
  • natural_language_processing/g2p_en: same chrono cast for the benchmark print, and switch %d to %zu for std::vector::size().
  • natural_language_processing/sentence_transformers, natural_language_processing/multilingual-e5: switch the second format spec from %d to %zu for std::vector::size().

After these changes, both cmake -DWITH_OPENCV=ON . and cmake -DWITH_OPENCV=OFF . builds produce zero warnings on GCC.

claude added 3 commits May 5, 2026 10:39
Resolve all default-level GCC/Clang format-string warnings:
- audio_processing/gpt-sovits: cast std::chrono ms count to long long
  to match the %lld specifier (twice).
- natural_language_processing/g2p_en: same chrono cast for the
  benchmark print, and switch %d to %zu for std::vector::size().
- natural_language_processing/sentence_transformers,
  natural_language_processing/multilingual-e5: switch the second
  format spec from %d to %zu for std::vector::size().

After these changes, both `cmake -DWITH_OPENCV=ON .` and
`cmake -DWITH_OPENCV=OFF .` builds produce zero warnings on GCC.

https://claude.ai/code/session_0156W8Q67nhiyoVNafDD5hDa
Each sample's CMakeLists.txt declared cmake_minimum_required(VERSION
3.1), which CMake now warns is deprecated:

  Compatibility with CMake < 3.10 will be removed from a future
  version of CMake.

The root CMakeLists already requires 3.10, so bump every sample to
match. No build behavior change.

https://claude.ai/code/session_0156W8Q67nhiyoVNafDD5hDa
Add explicit (int) casts where float and size_t values are passed to
APIs taking int. This silences C4244 (float -> int) on
webcamera_utils.cpp's std::round results and C4267 (size_t -> int)
on mat_utils.cpp's cv::Mat constructors. No runtime change.

https://claude.ai/code/session_0156W8Q67nhiyoVNafDD5hDa
@kyakuno kyakuno changed the title Fix compiler warnings in audio/NLP samples Fix compiler warnings May 5, 2026
claude added 11 commits May 5, 2026 11:08
Address GCC -Wall and MSVC default warnings reported by the Windows
MSBuild CI:

- Switch most for-loop iterators to size_t when comparing against
  std::vector::size() (sign-compare / C4267 fix).
- Cast comparisons of int with .size()/.dim/.size[i] to int or
  size_t depending on context (mediapipe_iris, gpt-sovits,
  g2p_en_*, clip).
- Cast size_t -> (unsigned int) when passing to ailiaSetInputBlobData,
  ailiaGetBlobData, ailiaCreateDetector, ailiaTokenizerDecode, etc.
- Cast (int) on cv::Mat ctor / hsv_to_rgb / std::round to silence
  C4244 / C4267.
- Replace sprintf with snprintf in arcface and m2det (C4996).
- Add UTF-8 prefix u8"..." to bert_maskedlm Japanese literal (C4566).
- Replace exp() with expf() in bert_maskedlm softmax (C4244 double->
  float).
- Remove unused locals (whisper task/env_id, multilingual-e5/sentence_
  transformers status, t5_whisper_medical num_beams, retinaface
  flags/fontScale, mediapipe_iris mat_confidence) and the unused
  print_net helper in clap.
- Fix typo `cv:cvtColor` -> `cv::cvtColor` in mediapipe_iris (was
  parsed as a label).

After these changes, both `cmake .` and `cmake -DWITH_OPENCV=OFF .`
builds with `-Wall` produce zero warnings on GCC.

https://claude.ai/code/session_0156W8Q67nhiyoVNafDD5hDa
- Cast COCO_CATEGORY.size() / FACE_CATEGORY.size() to (unsigned int)
  in ailiaCreateDetector calls (yolov3-face, yolov3-tiny, yolox).
- yolox_tflite: switch fopen to fopen_s on MSVC to silence C4996.

https://claude.ai/code/session_0156W8Q67nhiyoVNafDD5hDa
Define _CRT_SECURE_NO_WARNINGS globally on MSVC at the root
CMakeLists so that fopen/sprintf/strcpy etc. don't trip C4996. This
also lets us drop the per-call fopen_s shim in yolox_tflite.

Cast every remaining .size() (and .size() * sizeof(...)) being
passed to ailia API arguments declared as unsigned int / int:
- ailiaGetBlobData / ailiaSetInputBlobData (m2det, gpt-sovits,
  retinaface, g2p_en_model)
- ailiaPredict (clip)
- ailiaAudioGetFrameLen / ailiaAudioGetResampleLen / ailiaAudioResample
  (clap_utils, gpt-sovits)
- ailiaTokenizerDecode (sentence_transformers, fugumt-{ja,en}-{en,ja},
  multilingual-e5, t5_whisper_medical)

These are the C4267 size_t->unsigned int conversions that the MSVC
build still flagged.

https://claude.ai/code/session_0156W8Q67nhiyoVNafDD5hDa
The Windows MSBuild CI still surfaces dozens of C4244/C4267/C4305/
C4018/C4477 warnings spread across most samples. They come from the
samples mixing int / size_t / unsigned int in pre-existing code that
predates this branch, and individually casting every site is not
practical at the volume we are seeing.

Add MSVC-specific compile options at the root CMakeLists:

- /utf-8                fixes C4566 ("character cannot be represented
                        in the current code page (1252)") on the
                        Japanese string literals in fugumt-ja-en,
                        bert_maskedlm, sentence_transformers,
                        multilingual-e5, t5_whisper_medical.
- /wd4244 /wd4267 /wd4305 /wd4018 /wd4477
                        Suppress the bulk numeric-conversion and
                        format-mismatch warnings.

GCC -Wall builds remain clean and the explicit fixes from earlier
commits are kept.

https://claude.ai/code/session_0156W8Q67nhiyoVNafDD5hDa
Replace the global /wd... suppression added in the previous commit
with explicit per-site casts so that every C4244/C4267/C4305/C4477
warning is fixed at its source. Keep /utf-8 because that one is the
correct fix for C4566 (source-encoding), not a suppression.

Files changed:
- audio_processing/{clap/clap_utils,gpt-sovits/gpt-sovits,silero-vad/
  silero-vad}.cpp
- background_removal/u2net/{u2net,u2net_utils}.cpp
- face_detection/{blazeface/blazeface_utils,retinaface/retinaface}.cpp
- face_identification/arcface/arcface.cpp
- face_recognition/{face_alignment/face_alignment,mediapipe_iris/
  mediapipe_iris}.cpp
- image_classification/clip/clip.cpp
- natural_language_processing/{fugumt-en-ja,fugumt-ja-en,multilingual-
  e5,sentence_transformers,t5_whisper_medical,g2p_en/{g2p_en_averaged_
  perceptron,g2p_en_model}}.cpp
- object_detection/m2det/m2det.cpp
- pose_estimation/lightweight-human-pose-estimation/lightweight-human-
  pose-estimation.cpp
- util/wave_writer.cpp

Common transformations:
- size_t -> unsigned int / int explicit cast (C4267)
- float -> int explicit cast at cv::Point / cv::Size construction (C4244)
- double literal -> float literal (e.g. 1.35f, 0.48145466f) (C4305)
- exp/log/sqrt -> expf/logf/sqrtf (C4244 double->float)
- %ld / %lu -> %zu for std::vector::size() (C4477)
- pad_token_id (int) -> (float)pad_token_id when assigning into
  std::vector<float> (C4244)

GCC -Wall remains clean.

https://claude.ai/code/session_0156W8Q67nhiyoVNafDD5hDa
Cast inputs[i]->size() / 768 to unsigned int when assigning to
AILIAShape::y to silence C4267.

https://claude.ai/code/session_0156W8Q67nhiyoVNafDD5hDa
Add a top-level shell helper that walks every sample directory,
copies the freshly built binary, runs the sample's .sh launcher
(which downloads model weights), and prints PASS/FAIL with timing
plus the path to per-sample log files.

Usage:
  cmake -DWITH_OPENCV=ON -B build .
  cmake --build build -j
  ./test_all_samples.sh

LD_LIBRARY_PATH is set so the bundled ailia .so files are picked up.
A 600s per-sample and 10800s total timeout protect against hangs.

https://claude.ai/code/session_0156W8Q67nhiyoVNafDD5hDa
After running ./test_all_samples.sh the sample directories fill up
with copied binaries (e.g. yolox/yolox), downloaded auxiliary files
(spiece.model, sentencepiece.bpe.model, cmudict, ...) and per-sample
output.png files. Add explicit entries so that a freshly run repo
stays clean.

https://claude.ai/code/session_0156W8Q67nhiyoVNafDD5hDa
Bring in the .sh fixes and test_all_samples.sh from master.
@kyakuno
kyakuno merged commit 5b43ab1 into master May 6, 2026
2 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.

2 participants