From 948cf35ace3e4fa106982f43a9fa5cc79462fd26 Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Wed, 11 Feb 2026 09:14:45 -0800 Subject: [PATCH] Enable `-Wstring-conversion` in faiss/PACKAGE +1 Summary: This diff enables compilation warning flags for the directory in question. Further details are in [this workplace post](https://fb.workplace.com/permalink.php?story_fbid=pfbid02XaWNiCVk69r1ghfvDVpujB8Hr9Y61uDvNakxiZFa2jwiPHscVdEQwCBHrmWZSyMRl&id=100051201402394). This is a low-risk diff. There are **no run-time effects** and the diff has already been observed to compile locally. **If the code compiles, it work; test errors are spurious.** Differential Revision: D92431717 fbshipit-source-id: b49a9b0870aeffa03334b61b32a02ba4fb71de6b --- demos/demo_sift1M.cpp | 16 ++++++++-------- faiss/gpu/GpuCloner.cpp | 2 +- faiss/index_factory.cpp | 16 ++++++++-------- faiss/svs/IndexSVSFaissUtils.h | 8 +++++--- faiss/svs/IndexSVSVamana.h | 2 +- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/demos/demo_sift1M.cpp b/demos/demo_sift1M.cpp index f9a0fb699..5580ffcfd 100644 --- a/demos/demo_sift1M.cpp +++ b/demos/demo_sift1M.cpp @@ -39,19 +39,19 @@ float* fvecs_read(const char* fname, size_t* d_out, size_t* n_out) { } int d; fread(&d, 1, sizeof(int), f); - assert((d > 0 && d < 1000000) || !"unreasonable dimension"); + assert((d > 0 && d < 1000000) && "unreasonable dimension"); fseek(f, 0, SEEK_SET); struct stat st; fstat(fileno(f), &st); size_t sz = st.st_size; - assert(sz % ((d + 1) * 4) == 0 || !"weird file size"); + assert(sz % ((d + 1) * 4) == 0 && "weird file size"); size_t n = sz / ((d + 1) * 4); *d_out = d; *n_out = n; float* x = new float[n * (d + 1)]; size_t nr __attribute__((unused)) = fread(x, sizeof(float), n * (d + 1), f); - assert(nr == n * (d + 1) || !"could not read whole file"); + assert(nr == n * (d + 1) && "could not read whole file"); // shift array to remove row headers for (size_t i = 0; i < n; i++) @@ -115,7 +115,7 @@ int main() { size_t nb, d2; float* xb = fvecs_read("sift1M/sift_base.fvecs", &d2, &nb); - assert(d == d2 || !"dataset does not have same dimension as train set"); + assert(d == d2 && "dataset does not have same dimension as train set"); printf("[%.3f s] Indexing database, size %ld*%ld\n", elapsed() - t0, @@ -135,7 +135,7 @@ int main() { size_t d2; xq = fvecs_read("sift1M/sift_query.fvecs", &d2, &nq); - assert(d == d2 || !"query does not have same dimension as train set"); + assert(d == d2 && "query does not have same dimension as train set"); } size_t k; // nb of results per query in the GT @@ -149,7 +149,7 @@ int main() { // load ground-truth and convert int to long size_t nq2; int* gt_int = ivecs_read("sift1M/sift_groundtruth.ivecs", &k, &nq2); - assert(nq2 == nq || !"incorrect nb of ground truth entries"); + assert(nq2 == nq && "incorrect nb of ground truth entries"); gt = new faiss::idx_t[k * nq]; for (int i = 0; i < k * nq; i++) { @@ -198,8 +198,8 @@ int main() { break; } } - assert(selected_params.size() >= 0 || - !"could not find good enough op point"); + assert(selected_params.size() >= 0 && + "could not find good enough op point"); } { // Use the found configuration to perform a search diff --git a/faiss/gpu/GpuCloner.cpp b/faiss/gpu/GpuCloner.cpp index 884ba8dc2..a3db96492 100644 --- a/faiss/gpu/GpuCloner.cpp +++ b/faiss/gpu/GpuCloner.cpp @@ -64,7 +64,7 @@ void ToCPUCloner::merge_index(Index* dst, Index* src, bool successive_ids) { FAISS_ASSERT(ifl2); ifl->merge_from(*ifl2, successive_ids ? ifl->ntotal : 0); } else { - FAISS_ASSERT(!"merging not implemented for this type of class"); + FAISS_ASSERT(false && "merging not implemented for this type of class"); } } diff --git a/faiss/index_factory.cpp b/faiss/index_factory.cpp index c250bd7d5..4b52a9b4a 100644 --- a/faiss/index_factory.cpp +++ b/faiss/index_factory.cpp @@ -585,7 +585,7 @@ SVSStorageKind parse_lvq(const std::string& lvq_string) { if (lvq_string == "LVQ4x8") { return SVSStorageKind::SVS_LVQ4x8; } - FAISS_ASSERT(!"not supported SVS LVQ level"); + FAISS_ASSERT(false && "not supported SVS LVQ level"); } SVSStorageKind parse_leanvec(const std::string& leanvec_string) { @@ -598,7 +598,7 @@ SVSStorageKind parse_leanvec(const std::string& leanvec_string) { if (leanvec_string == "LeanVec8x8") { return SVSStorageKind::SVS_LeanVec8x8; } - FAISS_ASSERT(!"not supported SVS Leanvec level"); + FAISS_ASSERT(false && "not supported SVS Leanvec level"); } Index* parse_svs_datatype( @@ -616,28 +616,28 @@ Index* parse_svs_datatype( if (index_type == "Flat") { return new IndexSVSFlat(d, mt); } - FAISS_ASSERT(!"Unspported SVS index type"); + FAISS_ASSERT(false && "Unspported SVS index type"); } if (re_match(datatype_string, "FP16", sm)) { if (index_type == "Vamana") { return new IndexSVSVamana( d, std::stoul(arg_string), mt, SVSStorageKind::SVS_FP16); } - FAISS_ASSERT(!"Unspported SVS index type for Float16"); + FAISS_ASSERT(false && "Unspported SVS index type for Float16"); } if (re_match(datatype_string, "SQI8", sm)) { if (index_type == "Vamana") { return new IndexSVSVamana( d, std::stoul(arg_string), mt, SVSStorageKind::SVS_SQI8); } - FAISS_ASSERT(!"Unspported SVS index type for SQI8"); + FAISS_ASSERT(false && "Unspported SVS index type for SQI8"); } if (re_match(datatype_string, "(LVQ[0-9]+x[0-9]+)", sm)) { if (index_type == "Vamana") { return new IndexSVSVamanaLVQ( d, std::stoul(arg_string), mt, parse_lvq(sm[0].str())); } - FAISS_ASSERT(!"Unspported SVS index type for LVQ"); + FAISS_ASSERT(false && "Unspported SVS index type for LVQ"); } if (re_match(datatype_string, "(LeanVec[0-9]+x[0-9]+)(_[0-9]+)?", sm)) { std::string leanvec_d_string = @@ -652,7 +652,7 @@ Index* parse_svs_datatype( leanvec_d, parse_leanvec(sm[1].str())); } - FAISS_ASSERT(!"Unspported SVS index type for LeanVec"); + FAISS_ASSERT(false && "Unspported SVS index type for LeanVec"); } return nullptr; } @@ -672,7 +672,7 @@ Index* parse_IndexSVS(const std::string& code_string, int d, MetricType mt) { "Vamana", degree_string, datatype_string, d, mt); } if (re_match(code_string, "IVF([0-9]+)(,.+)?", sm)) { - FAISS_ASSERT(!"Unspported SVS index type"); + FAISS_ASSERT(false && "Unspported SVS index type"); } return nullptr; } diff --git a/faiss/svs/IndexSVSFaissUtils.h b/faiss/svs/IndexSVSFaissUtils.h index feef739e5..55b4992a8 100644 --- a/faiss/svs/IndexSVSFaissUtils.h +++ b/faiss/svs/IndexSVSFaissUtils.h @@ -66,7 +66,7 @@ inline svs_runtime::MetricType to_svs_metric(faiss::MetricType metric) { case METRIC_L2: return svs_runtime::MetricType::L2; default: - FAISS_ASSERT(!"not supported SVS distance"); + FAISS_ASSERT(false && "not supported SVS distance"); } } @@ -93,7 +93,8 @@ template struct InputBufferConverter { InputBufferConverter(std::span data = {}) : buffer(data.size()) { FAISS_ASSERT( - !"InputBufferConverter: there is no suitable user code for this type conversion"); + false && + "InputBufferConverter: there is no suitable user code for this type conversion"); std::transform( data.begin(), data.end(), buffer.begin(), [](const U& val) { return static_cast(val); @@ -153,7 +154,8 @@ struct OutputBufferConverter { OutputBufferConverter(std::span data = {}) : data_span(data), buffer(data.size()) { FAISS_ASSERT( - !"OutputBufferConverter: there is no suitable user code for this type conversion"); + false && + "OutputBufferConverter: there is no suitable user code for this type conversion"); } ~OutputBufferConverter() { diff --git a/faiss/svs/IndexSVSVamana.h b/faiss/svs/IndexSVSVamana.h index 67f548051..bd4bd2abe 100644 --- a/faiss/svs/IndexSVSVamana.h +++ b/faiss/svs/IndexSVSVamana.h @@ -71,7 +71,7 @@ inline svs_runtime::StorageKind to_svs_storage_kind(SVSStorageKind kind) { case SVS_LeanVec8x8: return svs_runtime::StorageKind::LeanVec8x8; default: - FAISS_ASSERT(!"not supported SVS storage kind"); + FAISS_ASSERT(false && "not supported SVS storage kind"); } }