fix: resolve compiler warnings for clean -Wall -Wextra -Wshadow build#4810
fix: resolve compiler warnings for clean -Wall -Wextra -Wshadow build#4810maxwbuckley wants to merge 1 commit intofacebookresearch:mainfrom
Conversation
|
@maxwbuckley thanks for the contribution. Would you like to update your change? |
ead7693 to
94f88c5
Compare
|
@maxwbuckley thanks for the update! There are couple of CI build failures, could you help to fix them? |
ef2fe4c to
3958b49
Compare
|
@junjieqi Thanks for flagging the CI failures! I've pushed fixes for all three:
I also rebased onto the latest main and added the deserialization hardening changes from #4811 (overflow-safe arithmetic, HNSW/NSG validation on read, bounds checking). |
@maxwbuckley looks like there are more conflicts, could you help update it? Thanks! |
1ceddb4 to
bd6a4ae
Compare
|
@junjieqi Rebased onto the latest main and resolved all merge conflicts. The branch is now up to date with a single squashed commit. Changes since last push:
|
bd6a4ae to
463533f
Compare
|
Updated to also fix warnings in AVX2-specific code paths (
Both generic and AVX2 builds compile clean with |
|
@limqiying has imported this pull request. If you are a Meta employee, you can view this in D94101552. |
Systematically fix compiler warnings across the FAISS codebase to enable clean builds with -Wall -Wextra -Wshadow. Changes include: - Rename shadowing variables (constructor params, loop vars, locals) - Fix signed/unsigned comparison mismatches - Add explicit casts where needed (e.g. size_t for OpenMP on MSVC) - Mark intentionally unused parameters with /*name*/ comments - Add cmake/StrictCompilerWarnings.cmake for opt-in strict builds Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
463533f to
b0410f5
Compare
|
Sorry for the delay on this. I think this would be great to do, but 170 files may be too much to do all at once. There is a big refactor going on with dynamic dispatch of SIMD (see PRs by @algoriddle ). So the code churn will be high until it is complete. If you create smaller (maybe 10-20 files at a time?) PRs, that might be easier to merge in quickly. Or, we can take it up after the dynamic dispatch PRs are all merged. |
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 2/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 11/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 6/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 9/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 8/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 3/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 4/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 13/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 10/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 5/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 1/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 12/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 7/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@mnorris11 Thanks for the feedback! I've split this PR into 13 smaller PRs (10-20 files each), rebased onto the latest
Each PR is independent and can be reviewed/merged separately. All changes are mechanical (variable renames, unused parameter annotations, casts, I'll close this PR in favor of the smaller ones. Let me know if you'd like any of them adjusted! |
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 1/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 2/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 12/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…4938) Summary: - Fix compiler warnings in SIMD libraries (simdlib_avx2, simdlib_emulated), NeuralNet, sorting, random, rabitq_simd, and general utils - Fixes include `-Wshadow` (constructor params shadowing members), `-Wunused-parameter`, and `[[maybe_unused]]` annotations All changes are mechanical. No functional changes. Part 7/13 of the compiler warnings cleanup (split from #4810 per maintainer request). Pull Request resolved: #4938 Test Plan: - [x] No functional changes — all fixes are mechanical renames and annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Reviewed By: mnorris11 Differential Revision: D96996248 Pulled By: alibeklfc fbshipit-source-id: 83167905562b8a3ac181c29b7628a6a183f54e93
Summary: - Fix compiler warnings in AdditiveQuantizer, ProductQuantizer, ResidualQuantizer, LocalSearchQuantizer, ScalarQuantizer, and related files - Includes scalar_quantizer subdirectory (distance_computers, quantizers, similarities, training) - Fixes include `-Wshadow`, `-Wunused-parameter`, `-Wformat`, and signed/unsigned comparisons All changes are mechanical. No functional changes. Part 4/13 of the compiler warnings cleanup (split from #4810 per maintainer request). Pull Request resolved: #4935 Test Plan: - [x] No functional changes — all fixes are mechanical renames and annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Reviewed By: mnorris11 Differential Revision: D96995866 Pulled By: alibeklfc fbshipit-source-id: 1a28eabda784e50b1c8fe32b665deb8919413df0
…4934) Summary: - Fix compiler warnings in HNSW, NSG, NNDescent graph implementations and their Index wrappers - Also covers ClusteringInitialization, Panorama, and IndexBinaryHNSW - Fixes include `-Wshadow` (variable renames), `-Wunused-parameter`, and `-Wimplicit-fallthrough` All changes are mechanical. No functional changes. Part 3/13 of the compiler warnings cleanup (split from #4810 per maintainer request). Pull Request resolved: #4934 Test Plan: - [x] No functional changes — all fixes are mechanical renames and annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Reviewed By: mnorris11 Differential Revision: D96995514 Pulled By: alibeklfc fbshipit-source-id: 8117658ba7e1e34db932e3e243cd17319b84c607
|
Closing in favor of the 13 smaller PRs (see table above). Each can be reviewed and merged independently. |
Summary: - Fix compiler warnings in distance computation, hamming distance, heap, partitioning, and quantize_lut utilities - Fixes include `-Wshadow`, `-Wunused-parameter`, `-Wformat`, and signed/unsigned comparisons All changes are mechanical. No functional changes. Part 6/13 of the compiler warnings cleanup (split from #4810 per maintainer request). Pull Request resolved: #4937 Test Plan: - [x] No functional changes — all fixes are mechanical renames and annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Reviewed By: mnorris11 Differential Revision: D96996091 Pulled By: alibeklfc fbshipit-source-id: 50073b6dd9cf7ed555df8b367a729d2dfbe3b003
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 1/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 2/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Mechanical fixes for compiler warnings found with -Wall -Wextra -Wshadow. No functional changes — only variable renames, unused parameter annotations, signed/unsigned casts, and [[fallthrough]] attributes. Part 12/13 of the compiler warnings cleanup (split from PR facebookresearch#4810). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…4956) Summary: - Fix compiler warnings in HNSW, NSG, NNDescent graph implementations and their Index wrappers - Also covers ClusteringInitialization, Panorama, and IndexBinaryHNSW - Fixes include `-Wshadow` (variable renames), `-Wunused-parameter`, and `-Wimplicit-fallthrough` All changes are mechanical. No functional changes. Part 3/13 of the compiler warnings cleanup (split from #4810 per maintainer request). Pull Request resolved: #4956 Test Plan: - [x] No functional changes — all fixes are mechanical renames and annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Reviewed By: junjieqi Differential Revision: D97359107 Pulled By: alibeklfc fbshipit-source-id: 04b484edf4cc555421cf216c989062f236082d71
Summary: - Fix compiler warnings in all IndexIVF variants: IndexIVF, IndexIVFFlat, IndexIVFPQ, IndexIVFFastScan, IndexIVFAdditiveQuantizer, IndexIVFAdditiveQuantizerFastScan, IndexIVFRaBitQ, IndexIVFRaBitQFastScan, IndexIVFPQFastScan, IndexIVFPQR, IndexIVFSpectralHash, IndexIVFFlatPanorama, IndexIVFIndependentQuantizer - Fixes include `-Wshadow`, `-Wunused-parameter`, `-Wformat`, signed/unsigned comparisons, and MSVC OpenMP loop variable types All changes are mechanical. No functional changes. Part 11/13 of the compiler warnings cleanup (split from #4810 per maintainer request). Pull Request resolved: #4942 Test Plan: - [x] No functional changes — all fixes are mechanical renames and annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Reviewed By: mnorris11 Differential Revision: D96996860 Pulled By: alibeklfc fbshipit-source-id: e591751f0268a3b7a6ee512fc8658c7292f289b4
…files (#4941) Summary: - Fix compiler warnings in IndexNeuralNetCodec, IndexPQ, IndexPQFastScan, IndexPreTransform, IndexRaBitQ, IndexRaBitQFastScan, IndexRefine - Fixes include `-Wshadow`, `-Wunused-parameter`, and `-Wnon-virtual-dtor` All changes are mechanical. No functional changes. Part 10/13 of the compiler warnings cleanup (split from #4810 per maintainer request). Pull Request resolved: #4941 Test Plan: - [x] No functional changes — all fixes are mechanical renames and annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Reviewed By: mnorris11 Differential Revision: D96996735 Pulled By: alibeklfc fbshipit-source-id: 61b2a702dbdaa6cbef205360b9c7944528319a71
…4936) Summary: - Fix compiler warnings in index_read, index_write, IO utilities, ResultHandler, simd_result_handlers, fast_scan - Also covers IDSelector, AuxIndexStructures, CodePacker, PolysemousTraining, kmeans1d, lattice_Zn - Fixes include `-Wshadow`, `-Wunused-parameter`, `-Wformat`, and `-Wimplicit-fallthrough` All changes are mechanical. No functional changes. Part 5/13 of the compiler warnings cleanup (split from #4810 per maintainer request). Pull Request resolved: #4936 Test Plan: - [x] No functional changes — all fixes are mechanical renames and annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Reviewed By: limqiying Differential Revision: D96995986 Pulled By: alibeklfc fbshipit-source-id: abfac3dceaa9a64752f3ac908c9a53c0f44bb2fa
Summary: - Fix compiler warnings in InvertedLists, BlockInvertedLists, DirectMap, OnDiskInvertedLists, InvertedListsIOHook - Also covers cppcontrib sa_decode files (Level2-avx2-inl, Level2-inl, PQ-avx2-inl, PQ-inl) - Fixes include `-Wshadow`, `-Wunused-parameter`, signed/unsigned comparisons, and MSVC OpenMP loop variable types All changes are mechanical. No functional changes. Part 8/13 of the compiler warnings cleanup (split from #4810 per maintainer request). Pull Request resolved: #4939 Test Plan: - [x] No functional changes — all fixes are mechanical renames and annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Reviewed By: mnorris11 Differential Revision: D96996384 Pulled By: alibeklfc fbshipit-source-id: c83bd3c2fe7be38dfc9667cec2333f2e47f6c96a
Summary: - Fix `-Wshadow`, `-Wunused-parameter`, `-Wnon-virtual-dtor` warnings in core FAISS base classes and headers - Files: Index, IndexBinary, IndexFlat, IndexFlatCodes, DistanceComputer, FaissAssert, FaissException, Quantizer, ThreadedIndex, MatrixStats All changes are mechanical (variable renames, unused parameter annotations, casts). No functional changes. Part 2/13 of the compiler warnings cleanup (split from #4810 per maintainer request). Pull Request resolved: #4933 Test Plan: - [x] No functional changes — all fixes are mechanical renames and annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Reviewed By: mnorris11 Differential Revision: D96995274 Pulled By: alibeklfc fbshipit-source-id: 2650884a1f336cb34527d4c50d42a847c9fbc0ce
Summary: - Fix compiler warnings in all 20 FAISS C++ test files - Fixes include `-Wshadow`, `-Wunused-parameter`, and signed/unsigned comparisons All changes are mechanical. No functional changes. Part 13/13 of the compiler warnings cleanup (split from #4810 per maintainer request). Pull Request resolved: #4944 Test Plan: - [x] No functional changes — all fixes are mechanical renames and annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Reviewed By: mnorris11 Differential Revision: D96996609 Pulled By: alibeklfc fbshipit-source-id: 72555246a4ccf540eb5422e64018c8d5e2660dce
Summary: - Fix compiler warnings in AutoTune, Clustering, IVFlib, VectorTransform, clone_index, index_factory, MetaIndexes, IndexReplicas, IndexRowwiseMinMax, IndexScalarQuantizer, IndexShards, IndexShardsIVF - Fixes include `-Wshadow`, `-Wunused-parameter`, `-Wformat`, and `-Woverloaded-virtual` All changes are mechanical. No functional changes. Part 12/13 of the compiler warnings cleanup (split from #4810 per maintainer request). Pull Request resolved: #4943 Test Plan: - [x] No functional changes — all fixes are mechanical renames and annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Reviewed By: mnorris11 Differential Revision: D96996987 Pulled By: alibeklfc fbshipit-source-id: 82e71810c4846284b602e045ea8069a1c3bb567f
#4940) Summary: - Fix compiler warnings in Index2Layer, IndexAdditiveQuantizer, IndexAdditiveQuantizerFastScan, IndexBinaryFlat, IndexBinaryFromFloat, IndexBinaryHash, IndexBinaryIVF, IndexFastScan, IndexIDMap, IndexLSH, IndexLattice - Fixes include `-Wshadow`, `-Wunused-parameter`, and signed/unsigned comparisons All changes are mechanical. No functional changes. Part 9/13 of the compiler warnings cleanup (split from #4810 per maintainer request). Pull Request resolved: #4940 Test Plan: - [x] No functional changes — all fixes are mechanical renames and annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Reviewed By: mnorris11 Differential Revision: D96996483 Pulled By: alibeklfc fbshipit-source-id: 2f472fcd448efc13edcc2802762da3cc3d8bdbbd
Summary
cmake/StrictCompilerWarnings.cmake) with 3 warning levels (basic, standard, strict) and optional-Werrorsupport-Wshadow,-Wunused-parameter,-Wnon-virtual-dtor,-Wformat,-Wimplicit-fallthrough, and-Woverloaded-virtual-Wall -Wextra -Wpedantic -Wshadow -Wnon-virtual-dtor -Wunused -Woverloaded-virtual -Wformat=2 -Wimplicit-fallthrough) with-WerrorMotivation
Compiler warnings often indicate real bugs (shadowed variables, implicit fallthrough, format string issues) and make it harder to spot new problems when they're noisy. This PR brings the FAISS codebase to a warning-clean state and provides infrastructure to keep it that way.
Warning infrastructure
The new
cmake/StrictCompilerWarnings.cmakemodule provides:FAISS_WARNING_LEVELcache variable (0=off, 1=basic, 2=standard, 3=strict)FAISS_WARNINGS_AS_ERRORSoption for CI enforcementfaiss_add_warnings()function applied to all build targetsChanges by category
Shadow variable fixes (
-Wshadow): Renamed local variables, loop variables, and constructor parameters that shadowed outer-scope or member variables throughout the codebase.Unused parameter fixes (
-Wunused-parameter): Added(void)paramcasts or removed parameter names for intentionally unused parameters.Format string fixes (
-Wformat): Changed%ld/%dto portable format macros (PRId64,zu) where appropriate.Implicit fallthrough fixes (
-Wimplicit-fallthrough): Added[[fallthrough]]attributes or break/return statements.Non-virtual destructor fixes (
-Wnon-virtual-dtor): Added virtual destructors where classes have virtual methods.Other: Fixed signed/unsigned comparisons, overloaded-virtual warnings, and various minor issues.
Test plan
faisslibrary builds with-Werrorat warning level 2 (GCC)🤖 Generated with Claude Code