tools build: Fix a number of Wconversion warnings
authorIan Rogers <irogers@google.com>
Mon, 6 Jan 2025 21:54:42 +0000 (13:54 -0800)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 13 Feb 2025 04:23:05 +0000 (20:23 -0800)
There's some expressed interest in having the compiler flag
-Wconversion detect at build time certain kinds of potential problems:
https://lore.kernel.org/lkml/20250103182532.GB781381@e132581.arm.com/

As feature detection passes -Wconversion from CFLAGS when set, the
feature detection compile tests need to not fail because of
-Wconversion as the failure will be interpretted as a missing
feature. Switch various types to avoid the -Wconversion issue, the
exact meaning of the code is unimportant as it is typically looking
for header file definitions.

Signed-off-by: Ian Rogers <irogers@google.com>
Reviewed-by: James Clark <james.clark@linaro.org>
Link: https://lore.kernel.org/r/20250106215443.198633-1-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/build/feature/test-backtrace.c
tools/build/feature/test-bpf.c
tools/build/feature/test-glibc.c
tools/build/feature/test-libdebuginfod.c
tools/build/feature/test-libdw.c
tools/build/feature/test-libelf-gelf_getnote.c
tools/build/feature/test-libelf.c
tools/build/feature/test-lzma.c

index e9ddd27c69c35ecdd8c12197aabb7d62ab9ffa40..7962fbad640165f21e211c95093bd171721785f7 100644 (file)
@@ -5,7 +5,7 @@
 int main(void)
 {
        void *backtrace_fns[10];
-       size_t entries;
+       int entries;
 
        entries = backtrace(backtrace_fns, 10);
        backtrace_symbols_fd(backtrace_fns, entries, 1);
index 727d22e34a6e5daf90ab0afb40ab7a309146ab62..e7a405f83af6ed9ede61d8bf0c7ed7770b17c084 100644 (file)
@@ -44,5 +44,5 @@ int main(void)
         * Test existence of __NR_bpf and BPF_PROG_LOAD.
         * This call should fail if we run the testcase.
         */
-       return syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr));
+       return syscall(__NR_bpf, BPF_PROG_LOAD, &attr, sizeof(attr)) == 0;
 }
index 9ab8e90e7b88afde3397cfa00582fc17a2e102ff..20a250419f31063aaf33ec841b4ee98c905d17b6 100644 (file)
@@ -16,5 +16,5 @@ int main(void)
        const char *version = XSTR(__GLIBC__) "." XSTR(__GLIBC_MINOR__);
 #endif
 
-       return (long)version;
+       return version == NULL;
 }
index da22548b841371d12e02dabca88030a650e462ac..823f9fa9391dac05a89785f2f6b780c87f4e2c89 100644 (file)
@@ -4,5 +4,5 @@
 int main(void)
 {
        debuginfod_client* c = debuginfod_begin();
-       return (long)c;
+       return !!c;
 }
index 2fb59479ab77168765fadb50b5468039a924cc4d..aabd63ca76b4d7e6dc11c5c24b7fea4e0c54ae99 100644 (file)
@@ -9,7 +9,7 @@ int test_libdw(void)
 {
        Dwarf *dbg = dwarf_begin(0, DWARF_C_READ);
 
-       return (long)dbg;
+       return dbg == NULL;
 }
 
 int test_libdw_unwind(void)
index 075d062fe8419cf06b16d291153fc4e7b0196610..e06121161161a6d492d925453909aa88bee23115 100644 (file)
@@ -4,5 +4,5 @@
 
 int main(void)
 {
-       return gelf_getnote(NULL, 0, NULL, NULL, NULL);
+       return gelf_getnote(NULL, 0, NULL, NULL, NULL) == 0;
 }
index 905044127d56468f42b4af0dbb51b100faaea0f8..2dbb6ea870f357b346e1fed14124707cc3d65c63 100644 (file)
@@ -5,5 +5,5 @@ int main(void)
 {
        Elf *elf = elf_begin(0, ELF_C_READ, 0);
 
-       return (long)elf;
+       return !!elf;
 }
index 78682bb01d5761bc4401a2cbaef2ef719b9c2f92..b57103774e8ec106d650787373cbd52a646a990f 100644 (file)
@@ -4,7 +4,7 @@
 int main(void)
 {
        lzma_stream strm = LZMA_STREAM_INIT;
-       int ret;
+       lzma_ret ret;
 
        ret = lzma_stream_decoder(&strm, UINT64_MAX, LZMA_CONCATENATED);
        return ret ? -1 : 0;