ClangBuiltLinux/linux

-Wunused-but-set-variable building perf

nickdesaulniers opened this issue · 8 comments

$ make LLVM=1 -C tools/perf
...
event-parse.c:112:13: warning: variable 'x' set but not used [-Wunused-but-set-variable]
        static int x;
                   ^
...
tests/mmap-basic.c:117:8: error: variable 'foo' set but not used [-Werror,-Wunused-but-set-variable]
                        int foo = syscalls[i]();
                            ^
...
tests/perf-record.c:68:16: error: variable 'errs' set but not used [-Werror,-Wunused-but-set-variable]
        int err = -1, errs = 0, i, wakeups = 0;
                      ^
...
util/parse-events-bison.c:1401:9: error: variable 'parse_events_nerrs' set but not used [-Werror,-Wunused-but-set-variable]
    int yynerrs = 0;
        ^

These are exposed by llvm/llvm-project@2af845a; GCC has -Wunused-but-set-variable as well but it does not warn for the increment/decrement operations.

For what it's worth, the perf build is broken for me on Arch Linux for other reasons (newer Perl it seems).

Patch perf unwind: Fix uninitialized variable in Linus Git.

[1] https://git.kernel.org/linus/1d98cdf7fa2bc6e8063c0a692a1c091d8ebe3a75

I think that change is for a different issue?

diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index 30bbe144648a..cac1e5ab9b0e 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -113,10 +113,8 @@ static int test__basic_mmap(struct test_suite *test __maybe_unused, int subtest
        }
 
        for (i = 0; i < nsyscalls; ++i)
-               for (j = 0; j < expected_nr_events[i]; ++j) {
-                       int foo = syscalls[i]();
-                       ++foo;
-               }
+               for (j = 0; j < expected_nr_events[i]; ++j)
+                       syscalls[i]();
 
        md = &evlist->mmap[0];
        if (perf_mmap__read_init(&md->core) < 0)
diff --git a/tools/perf/tests/perf-record.c b/tools/perf/tests/perf-record.c
index 6a001fcfed68..d9165236e473 100644
--- a/tools/perf/tests/perf-record.c
+++ b/tools/perf/tests/perf-record.c
@@ -332,7 +332,7 @@ static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtest
 out:
        if (err == -EACCES)
                return TEST_SKIP;
-       if (err < 0)
+       if (err < 0 || errs)
                return TEST_FAIL;
        return TEST_OK;
 }

Let me see if I can figure out the right way to fix the rest.

perf tests record: Fail the test if the 'errs' counter is not zero

[1] https://git.kernel.org/linus/25c5e67cdf744cbb93fd06647611d3036218debe

Closing based on #1726 (comment).