Fix compiler warnings for pip wheel builds (macOS + Windows) (#4989)#4989
Closed
alibeklfc wants to merge 1 commit intofacebookresearch:mainfrom
Closed
Fix compiler warnings for pip wheel builds (macOS + Windows) (#4989)#4989alibeklfc wants to merge 1 commit intofacebookresearch:mainfrom
alibeklfc wants to merge 1 commit intofacebookresearch:mainfrom
Conversation
Contributor
|
@alibeklfc has exported this pull request. If you are a Meta employee, you can view the originating Diff in D98197799. |
alibeklfc
added a commit
to alibeklfc/faiss
that referenced
this pull request
Mar 25, 2026
…kresearch#4989) Summary: Fix compiler warnings that appear during pip wheel builds on macOS (AppleClang) and Windows (MSVC). **macOS fixes (AppleClang):** 1. Replace deprecated `sprintf` calls with `snprintf` in all three simdlib headers: - `simdlib_emulated.h` (4 call sites) - `simdlib_avx2.h` (4 call sites) - `simdlib_avx512.h` (3 call sites) AppleClang marks `sprintf` as deprecated. The fix replaces `ptr += sprintf(ptr, fmt, val)` with `ptr += snprintf(ptr, (size_t)(res + sizeof(res) - ptr), fmt, val)`, where the second argument computes the remaining buffer space. This is safe and behavior-preserving: these are debug-only `tostring()` methods that format small integers/floats into 1000-2000 byte buffers, using at most ~256 bytes in the worst case (64 elements × ~4 chars). When output fits (which it always does), `snprintf` returns the same value as `sprintf`, so `ptr` advances identically. 2. Add missing `override` specifiers to fix `-Winconsistent-missing-override`: - `IVFFlatScanner::scan_codes()` in `IndexIVFFlat.h` - `RaBitQHeapHandler::begin()` and `end()` in `IndexRaBitQFastScan.h` These methods override virtual base class methods but lacked the `override` keyword. Adding it is purely declarative — no behavioral change, but enables compile-time checking if the base signature changes. **Windows fixes (MSVC):** 3. Guard `#pragma GCC diagnostic` blocks with `#if defined(__GNUC__) || defined(__clang__)` to silence MSVC C4068 "unknown pragma" warnings in: - `simdlib_emulated.h`, `simdlib_avx2.h` - `IVFlib.cpp`, `PolysemousTraining.cpp` The pragmas only control warning suppression (for `-Wformat-nonliteral`) and have zero effect on code generation. GCC/Clang still see them and behave identically; MSVC skips them (it doesn't have that warning anyway). 4. Fix `%ld` printf format specifiers in `partitioning.cpp` to use `%zu` for `size_t` and `%" PRId64 "` for `int64_t` (MSVC C4477: `long` is 32-bit on Windows, so `%ld` is wrong for both types). These are debug-only `IFV printf` calls gated behind a verbose flag. Differential Revision: D98197799
b3857a5 to
5b55b2e
Compare
…kresearch#4989) Summary: Fix compiler warnings that appear during pip wheel builds on macOS (AppleClang) and Windows (MSVC). **macOS fixes (AppleClang):** 1. Replace deprecated `sprintf` calls with `snprintf` in all three simdlib headers: - `simdlib_emulated.h` (4 call sites) - `simdlib_avx2.h` (4 call sites) - `simdlib_avx512.h` (3 call sites) AppleClang marks `sprintf` as deprecated. The fix replaces `ptr += sprintf(ptr, fmt, val)` with `ptr += snprintf(ptr, (size_t)(res + sizeof(res) - ptr), fmt, val)`, where the second argument computes the remaining buffer space. This is safe and behavior-preserving: these are debug-only `tostring()` methods that format small integers/floats into 1000-2000 byte buffers, using at most ~256 bytes in the worst case (64 elements × ~4 chars). When output fits (which it always does), `snprintf` returns the same value as `sprintf`, so `ptr` advances identically. 2. Add missing `override` specifiers to fix `-Winconsistent-missing-override`: - `IVFFlatScanner::scan_codes()` in `IndexIVFFlat.h` - `RaBitQHeapHandler::begin()` and `end()` in `IndexRaBitQFastScan.h` - `IDSelectorModulo::is_member()` in `faiss_example_external_module.swig` These methods override virtual base class methods but lacked the `override` keyword. Adding it is purely declarative — no behavioral change, but enables compile-time checking if the base signature changes. **Windows fixes (MSVC):** 3. Guard `#pragma GCC diagnostic` blocks with `#if defined(__GNUC__) || defined(__clang__)` to silence MSVC C4068 "unknown pragma" warnings in: - `simdlib_emulated.h`, `simdlib_avx2.h`, `simdlib_avx512.h` - `IVFlib.cpp`, `PolysemousTraining.cpp` The pragmas only control warning suppression (for `-Wformat-nonliteral`) and have zero effect on code generation. GCC/Clang still see them and behave identically; MSVC skips them (it doesn't have that warning anyway). 4. Fix `%ld` printf format specifiers in `partitioning.cpp` to use `%zu` for `size_t` and `%" PRId64 "` for `int64_t` (MSVC C4477: `long` is 32-bit on Windows, so `%ld` is wrong for both types). These are debug-only `IFV printf` calls gated behind a verbose flag. 5. Fix `size_t` to `int` narrowing in `IndexIVFSpectralHash.cpp` (MSVC C4267): `std::make_unique<RandomRotationMatrix>(d_in, nbit_in)` where `d_in` is `size_t` but the constructor takes `int`. Added `static_cast<int>(d_in)`. Safe because `d_in` is vector dimensionality (typically 64-2048). 6. Fix pointer-to-`long` truncation in `distances_sse-inl.h` (MSVC C4311): Alignment check `(long)ptr & 15` truncates 64-bit pointers on Windows where `long` is 32-bit. Changed to `(uintptr_t)ptr` which is correct on all platforms. The alignment test logic is unchanged. Differential Revision: D98197799
5b55b2e to
d33dad3
Compare
alibeklfc
added a commit
to alibeklfc/faiss
that referenced
this pull request
Mar 25, 2026
…kresearch#4989) Summary: Fix compiler warnings that appear during pip wheel builds on macOS (AppleClang) and Windows (MSVC). **macOS fixes (AppleClang):** 1. Replace deprecated `sprintf` calls with `snprintf` in all three simdlib headers: - `simdlib_emulated.h` (4 call sites) - `simdlib_avx2.h` (4 call sites) - `simdlib_avx512.h` (3 call sites) AppleClang marks `sprintf` as deprecated. The fix replaces `ptr += sprintf(ptr, fmt, val)` with `ptr += snprintf(ptr, (size_t)(res + sizeof(res) - ptr), fmt, val)`, where the second argument computes the remaining buffer space. This is safe and behavior-preserving: these are debug-only `tostring()` methods that format small integers/floats into 1000-2000 byte buffers, using at most ~256 bytes in the worst case (64 elements × ~4 chars). When output fits (which it always does), `snprintf` returns the same value as `sprintf`, so `ptr` advances identically. 2. Add missing `override` specifiers to fix `-Winconsistent-missing-override`: - `IVFFlatScanner::scan_codes()` in `IndexIVFFlat.h` - `RaBitQHeapHandler::begin()` and `end()` in `IndexRaBitQFastScan.h` - `IDSelectorModulo::is_member()` in `faiss_example_external_module.swig` These methods override virtual base class methods but lacked the `override` keyword. Adding it is purely declarative — no behavioral change, but enables compile-time checking if the base signature changes. **Windows fixes (MSVC):** 3. Guard `#pragma GCC diagnostic` blocks with `#if defined(__GNUC__) || defined(__clang__)` to silence MSVC C4068 "unknown pragma" warnings in: - `simdlib_emulated.h`, `simdlib_avx2.h`, `simdlib_avx512.h` - `IVFlib.cpp`, `PolysemousTraining.cpp` The pragmas only control warning suppression (for `-Wformat-nonliteral`) and have zero effect on code generation. GCC/Clang still see them and behave identically; MSVC skips them (it doesn't have that warning anyway). 4. Fix `%ld` printf format specifiers in `partitioning.cpp` to use `%zu` for `size_t` and `%" PRId64 "` for `int64_t` (MSVC C4477: `long` is 32-bit on Windows, so `%ld` is wrong for both types). These are debug-only `IFV printf` calls gated behind a verbose flag. 5. Fix `size_t` to `int` narrowing in `IndexIVFSpectralHash.cpp` (MSVC C4267): `std::make_unique<RandomRotationMatrix>(d_in, nbit_in)` where `d_in` is `size_t` but the constructor takes `int`. Added `static_cast<int>(d_in)`. Safe because `d_in` is vector dimensionality (typically 64-2048). 6. Fix pointer-to-`long` truncation in `distances_sse-inl.h` (MSVC C4311): Alignment check `(long)ptr & 15` truncates 64-bit pointers on Windows where `long` is 32-bit. Changed to `(uintptr_t)ptr` which is correct on all platforms. The alignment test logic is unchanged. Reviewed By: mnorris11 Differential Revision: D98197799
alibeklfc
added a commit
to alibeklfc/faiss
that referenced
this pull request
Mar 26, 2026
…kresearch#4989) Summary: Fix compiler warnings that appear during pip wheel builds on macOS (AppleClang) and Windows (MSVC). **macOS fixes (AppleClang):** 1. Replace deprecated `sprintf` calls with `snprintf` in all three simdlib headers: - `simdlib_emulated.h` (4 call sites) - `simdlib_avx2.h` (4 call sites) - `simdlib_avx512.h` (3 call sites) AppleClang marks `sprintf` as deprecated. The fix replaces `ptr += sprintf(ptr, fmt, val)` with `ptr += snprintf(ptr, (size_t)(res + sizeof(res) - ptr), fmt, val)`, where the second argument computes the remaining buffer space. This is safe and behavior-preserving: these are debug-only `tostring()` methods that format small integers/floats into 1000-2000 byte buffers, using at most ~256 bytes in the worst case (64 elements × ~4 chars). When output fits (which it always does), `snprintf` returns the same value as `sprintf`, so `ptr` advances identically. 2. Add missing `override` specifiers to fix `-Winconsistent-missing-override`: - `IVFFlatScanner::scan_codes()` in `IndexIVFFlat.h` - `RaBitQHeapHandler::begin()` and `end()` in `IndexRaBitQFastScan.h` - `IDSelectorModulo::is_member()` in `faiss_example_external_module.swig` These methods override virtual base class methods but lacked the `override` keyword. Adding it is purely declarative — no behavioral change, but enables compile-time checking if the base signature changes. **Windows fixes (MSVC):** 3. Guard `#pragma GCC diagnostic` blocks with `#if defined(__GNUC__) || defined(__clang__)` to silence MSVC C4068 "unknown pragma" warnings in: - `simdlib_emulated.h`, `simdlib_avx2.h`, `simdlib_avx512.h` - `IVFlib.cpp`, `PolysemousTraining.cpp` The pragmas only control warning suppression (for `-Wformat-nonliteral`) and have zero effect on code generation. GCC/Clang still see them and behave identically; MSVC skips them (it doesn't have that warning anyway). 4. Fix `%ld` printf format specifiers in `partitioning.cpp` to use `%zu` for `size_t` and `%" PRId64 "` for `int64_t` (MSVC C4477: `long` is 32-bit on Windows, so `%ld` is wrong for both types). These are debug-only `IFV printf` calls gated behind a verbose flag. 5. Fix `size_t` to `int` narrowing in `IndexIVFSpectralHash.cpp` (MSVC C4267): `std::make_unique<RandomRotationMatrix>(d_in, nbit_in)` where `d_in` is `size_t` but the constructor takes `int`. Added `static_cast<int>(d_in)`. Safe because `d_in` is vector dimensionality (typically 64-2048). 6. Fix pointer-to-`long` truncation in `distances_sse-inl.h` (MSVC C4311): Alignment check `(long)ptr & 15` truncates 64-bit pointers on Windows where `long` is 32-bit. Changed to `(uintptr_t)ptr` which is correct on all platforms. The alignment test logic is unchanged. Reviewed By: mnorris11 Differential Revision: D98197799
alibeklfc
added a commit
to alibeklfc/faiss
that referenced
this pull request
Mar 26, 2026
…kresearch#4989) Summary: Fix compiler warnings that appear during pip wheel builds on macOS (AppleClang) and Windows (MSVC). **macOS fixes (AppleClang):** 1. Replace deprecated `sprintf` calls with `snprintf` in all three simdlib headers: - `simdlib_emulated.h` (4 call sites) - `simdlib_avx2.h` (4 call sites) - `simdlib_avx512.h` (3 call sites) AppleClang marks `sprintf` as deprecated. The fix replaces `ptr += sprintf(ptr, fmt, val)` with `ptr += snprintf(ptr, (size_t)(res + sizeof(res) - ptr), fmt, val)`, where the second argument computes the remaining buffer space. This is safe and behavior-preserving: these are debug-only `tostring()` methods that format small integers/floats into 1000-2000 byte buffers, using at most ~256 bytes in the worst case (64 elements × ~4 chars). When output fits (which it always does), `snprintf` returns the same value as `sprintf`, so `ptr` advances identically. 2. Add missing `override` specifiers to fix `-Winconsistent-missing-override`: - `IVFFlatScanner::scan_codes()` in `IndexIVFFlat.h` - `RaBitQHeapHandler::begin()` and `end()` in `IndexRaBitQFastScan.h` - `IDSelectorModulo::is_member()` in `faiss_example_external_module.swig` These methods override virtual base class methods but lacked the `override` keyword. Adding it is purely declarative — no behavioral change, but enables compile-time checking if the base signature changes. **Windows fixes (MSVC):** 3. Guard `#pragma GCC diagnostic` blocks with `#if defined(__GNUC__) || defined(__clang__)` to silence MSVC C4068 "unknown pragma" warnings in: - `simdlib_emulated.h`, `simdlib_avx2.h`, `simdlib_avx512.h` - `IVFlib.cpp`, `PolysemousTraining.cpp` The pragmas only control warning suppression (for `-Wformat-nonliteral`) and have zero effect on code generation. GCC/Clang still see them and behave identically; MSVC skips them (it doesn't have that warning anyway). 4. Fix `%ld` printf format specifiers in `partitioning.cpp` to use `%zu` for `size_t` and `%" PRId64 "` for `int64_t` (MSVC C4477: `long` is 32-bit on Windows, so `%ld` is wrong for both types). These are debug-only `IFV printf` calls gated behind a verbose flag. 5. Fix `size_t` to `int` narrowing in `IndexIVFSpectralHash.cpp` (MSVC C4267): `std::make_unique<RandomRotationMatrix>(d_in, nbit_in)` where `d_in` is `size_t` but the constructor takes `int`. Added `static_cast<int>(d_in)`. Safe because `d_in` is vector dimensionality (typically 64-2048). 6. Fix pointer-to-`long` truncation in `distances_sse-inl.h` (MSVC C4311): Alignment check `(long)ptr & 15` truncates 64-bit pointers on Windows where `long` is 32-bit. Changed to `(uintptr_t)ptr` which is correct on all platforms. The alignment test logic is unchanged. Reviewed By: mnorris11 Differential Revision: D98197799
Contributor
|
This pull request has been merged in 0759009. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Fix compiler warnings that appear during pip wheel builds on macOS (AppleClang)
and Windows (MSVC).
macOS fixes (AppleClang):
Replace deprecated
sprintfcalls withsnprintfin all three simdlib headers:simdlib_emulated.h(4 call sites)simdlib_avx2.h(4 call sites)simdlib_avx512.h(3 call sites)AppleClang marks
sprintfas deprecated. The fix replacesptr += sprintf(ptr, fmt, val)withptr += snprintf(ptr, (size_t)(res + sizeof(res) - ptr), fmt, val),where the second argument computes the remaining buffer space. This is
safe and behavior-preserving: these are debug-only
tostring()methodsthat format small integers/floats into 1000-2000 byte buffers, using at
most ~256 bytes in the worst case (64 elements × ~4 chars). When output
fits (which it always does),
snprintfreturns the same value assprintf, soptradvances identically.Add missing
overridespecifiers to fix-Winconsistent-missing-override:IVFFlatScanner::scan_codes()inIndexIVFFlat.hRaBitQHeapHandler::begin()andend()inIndexRaBitQFastScan.hIDSelectorModulo::is_member()infaiss_example_external_module.swigThese methods override virtual base class methods but lacked the
overridekeyword. Adding it is purely declarative — no behavioralchange, but enables compile-time checking if the base signature changes.
Windows fixes (MSVC):
Guard
#pragma GCC diagnosticblocks with#if defined(__GNUC__) || defined(__clang__)to silence MSVC C4068 "unknown pragma" warnings in:
simdlib_emulated.h,simdlib_avx2.h,simdlib_avx512.hIVFlib.cpp,PolysemousTraining.cppThe pragmas only control warning suppression (for
-Wformat-nonliteral)and have zero effect on code generation. GCC/Clang still see them and
behave identically; MSVC skips them (it doesn't have that warning anyway).
Fix
%ldprintf format specifiers inpartitioning.cppto use%zuforsize_tand%" PRId64 "forint64_t(MSVC C4477:longis 32-biton Windows, so
%ldis wrong for both types). These are debug-onlyIFV printfcalls gated behind a verbose flag.Fix
size_ttointnarrowing inIndexIVFSpectralHash.cpp(MSVC C4267):std::make_unique<RandomRotationMatrix>(d_in, nbit_in)whered_inissize_tbut the constructor takesint. Addedstatic_cast<int>(d_in).Safe because
d_inis vector dimensionality (typically 64-2048).Fix pointer-to-
longtruncation indistances_sse-inl.h(MSVC C4311):Alignment check
(long)ptr & 15truncates 64-bit pointers on Windowswhere
longis 32-bit. Changed to(uintptr_t)ptrwhich is correcton all platforms. The alignment test logic is unchanged.
Differential Revision: D98197799