Skip to content

Fix compiler warnings for pip wheel builds (macOS + Windows) (#4989)#4989

Closed
alibeklfc wants to merge 1 commit intofacebookresearch:mainfrom
alibeklfc:export-D98197799
Closed

Fix compiler warnings for pip wheel builds (macOS + Windows) (#4989)#4989
alibeklfc wants to merge 1 commit intofacebookresearch:mainfrom
alibeklfc:export-D98197799

Conversation

@alibeklfc
Copy link
Copy Markdown
Contributor

@alibeklfc alibeklfc commented Mar 25, 2026

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):

  1. 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).

  2. 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.

  3. 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).

  4. 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

@meta-cla meta-cla bot added the CLA Signed label Mar 25, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync bot commented Mar 25, 2026

@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
…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
@meta-codesync meta-codesync bot changed the title Fix compiler warnings for pip wheel builds (macOS + Windows) Fix compiler warnings for pip wheel builds (macOS + Windows) (#4989) Mar 25, 2026
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
@meta-codesync meta-codesync bot closed this in 0759009 Mar 26, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync bot commented Mar 26, 2026

This pull request has been merged in 0759009.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant