Commit 0759009
Fix compiler warnings for pip wheel builds (macOS + Windows) (facebookresearch#4989)
Summary:
Pull Request resolved: facebookresearch#4989
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
fbshipit-source-id: 3523ce1d93b7e68c41f9c974e3a3f992f0dbcf391 parent 8a80b3d commit 0759009
File tree
11 files changed
+91
-22
lines changed- faiss
- impl
- simdlib
- python
- utils
- simd_impl
11 files changed
+91
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
601 | 601 | | |
602 | 602 | | |
603 | 603 | | |
| 604 | + | |
604 | 605 | | |
605 | 606 | | |
| 607 | + | |
606 | 608 | | |
| 609 | + | |
607 | 610 | | |
| 611 | + | |
608 | 612 | | |
609 | 613 | | |
610 | 614 | | |
| |||
655 | 659 | | |
656 | 660 | | |
657 | 661 | | |
| 662 | + | |
658 | 663 | | |
659 | 664 | | |
| 665 | + | |
660 | 666 | | |
| 667 | + | |
661 | 668 | | |
| 669 | + | |
662 | 670 | | |
663 | 671 | | |
664 | 672 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
282 | | - | |
| 282 | + | |
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
286 | | - | |
| 286 | + | |
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
823 | 823 | | |
824 | 824 | | |
825 | 825 | | |
| 826 | + | |
826 | 827 | | |
827 | 828 | | |
| 829 | + | |
828 | 830 | | |
| 831 | + | |
829 | 832 | | |
| 833 | + | |
830 | 834 | | |
831 | 835 | | |
832 | 836 | | |
| |||
938 | 942 | | |
939 | 943 | | |
940 | 944 | | |
| 945 | + | |
941 | 946 | | |
942 | 947 | | |
| 948 | + | |
943 | 949 | | |
| 950 | + | |
944 | 951 | | |
| 952 | + | |
945 | 953 | | |
946 | 954 | | |
947 | 955 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| 144 | + | |
144 | 145 | | |
145 | 146 | | |
| 147 | + | |
146 | 148 | | |
147 | | - | |
| 149 | + | |
| 150 | + | |
148 | 151 | | |
| 152 | + | |
149 | 153 | | |
| 154 | + | |
150 | 155 | | |
151 | 156 | | |
152 | 157 | | |
| |||
462 | 467 | | |
463 | 468 | | |
464 | 469 | | |
| 470 | + | |
465 | 471 | | |
466 | 472 | | |
| 473 | + | |
467 | 474 | | |
468 | | - | |
| 475 | + | |
| 476 | + | |
469 | 477 | | |
| 478 | + | |
470 | 479 | | |
| 480 | + | |
471 | 481 | | |
472 | 482 | | |
473 | 483 | | |
| |||
601 | 611 | | |
602 | 612 | | |
603 | 613 | | |
| 614 | + | |
604 | 615 | | |
605 | 616 | | |
| 617 | + | |
606 | 618 | | |
607 | | - | |
| 619 | + | |
| 620 | + | |
608 | 621 | | |
| 622 | + | |
609 | 623 | | |
| 624 | + | |
610 | 625 | | |
611 | 626 | | |
612 | 627 | | |
| |||
727 | 742 | | |
728 | 743 | | |
729 | 744 | | |
730 | | - | |
| 745 | + | |
| 746 | + | |
731 | 747 | | |
732 | 748 | | |
733 | 749 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
130 | 134 | | |
131 | | - | |
| 135 | + | |
| 136 | + | |
132 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
133 | 141 | | |
134 | 142 | | |
135 | 143 | | |
| |||
263 | 271 | | |
264 | 272 | | |
265 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
266 | 278 | | |
267 | | - | |
| 279 | + | |
| 280 | + | |
268 | 281 | | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
269 | 285 | | |
270 | 286 | | |
271 | 287 | | |
| |||
374 | 390 | | |
375 | 391 | | |
376 | 392 | | |
377 | | - | |
| 393 | + | |
| 394 | + | |
378 | 395 | | |
379 | 396 | | |
380 | 397 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
132 | 133 | | |
133 | 134 | | |
| 135 | + | |
134 | 136 | | |
135 | | - | |
| 137 | + | |
| 138 | + | |
136 | 139 | | |
| 140 | + | |
137 | 141 | | |
| 142 | + | |
138 | 143 | | |
139 | 144 | | |
140 | 145 | | |
| |||
507 | 512 | | |
508 | 513 | | |
509 | 514 | | |
| 515 | + | |
510 | 516 | | |
511 | 517 | | |
| 518 | + | |
512 | 519 | | |
513 | | - | |
| 520 | + | |
514 | 521 | | |
| 522 | + | |
515 | 523 | | |
| 524 | + | |
516 | 525 | | |
517 | 526 | | |
518 | 527 | | |
| |||
707 | 716 | | |
708 | 717 | | |
709 | 718 | | |
| 719 | + | |
710 | 720 | | |
711 | 721 | | |
| 722 | + | |
712 | 723 | | |
713 | | - | |
| 724 | + | |
| 725 | + | |
714 | 726 | | |
| 727 | + | |
715 | 728 | | |
| 729 | + | |
716 | 730 | | |
717 | 731 | | |
718 | 732 | | |
| |||
863 | 877 | | |
864 | 878 | | |
865 | 879 | | |
866 | | - | |
| 880 | + | |
| 881 | + | |
867 | 882 | | |
868 | 883 | | |
869 | 884 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
432 | 433 | | |
433 | 434 | | |
434 | 435 | | |
435 | | - | |
| 436 | + | |
436 | 437 | | |
437 | 438 | | |
438 | 439 | | |
| |||
444 | 445 | | |
445 | 446 | | |
446 | 447 | | |
447 | | - | |
| 448 | + | |
448 | 449 | | |
449 | 450 | | |
450 | 451 | | |
| |||
481 | 482 | | |
482 | 483 | | |
483 | 484 | | |
484 | | - | |
| 485 | + | |
| 486 | + | |
485 | 487 | | |
486 | 488 | | |
487 | 489 | | |
| |||
491 | 493 | | |
492 | 494 | | |
493 | 495 | | |
494 | | - | |
| 496 | + | |
| 497 | + | |
495 | 498 | | |
496 | 499 | | |
497 | 500 | | |
498 | 501 | | |
499 | 502 | | |
500 | 503 | | |
501 | | - | |
| 504 | + | |
502 | 505 | | |
503 | 506 | | |
504 | 507 | | |
| |||
0 commit comments