Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf annotate: Fix Clang build by adding block in switch case

Clang and GCC disagree with what constitutes a "declaration after
statement". GCC allows declarations in switch cases without an extra
block, as long as it's immediately after the label. Clang does not.
Unfortunately this is the case even in the latest versions of both
compilers. The only option that makes them behave in the same way is
-Wpedantic, which can't be enabled in Perf because of the number of
warnings it generates.

Add a block to fix the Clang build, which is the only thing we can do.

Fixes the build error:

ui/browsers/annotate.c:999:4: error: expected expression
struct annotation_line *al = NULL;

ui/browsers/annotate.c:1008:4: error: use of undeclared identifier 'al'
al = annotated_source__get_line(notes->src, offset);

ui/browsers/annotate.c:1009:24: error: use of undeclared identifier 'al'
browser->curr_hot = al ? &al->rb_node : NULL;

ui/browsers/annotate.c:1009:30: error: use of undeclared identifier 'al'
browser->curr_hot = al ? &al->rb_node : NULL;

ui/browsers/annotate.c:1000:8: error: mixing declarations and code is incompatible with standards before C99 [-Werror,-Wdeclaration-after-statement]
s64 offset = annotate_browser__curr_hot_offset(browser);

Fixes: ad83f3b7155d ("perf c2c annotate: Start from the contention line")
Signed-off-by: James Clark <james.clark@linaro.org>
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

James Clark and committed by
Namhyung Kim
f2195c5b a1d8548c

+2 -1
+2 -1
tools/perf/ui/browsers/annotate.c
··· 995 995 case 'H': 996 996 nd = browser->curr_hot; 997 997 break; 998 - case 's': 998 + case 's': { 999 999 struct annotation_line *al = NULL; 1000 1000 s64 offset = annotate_browser__curr_hot_offset(browser); 1001 1001 ··· 1012 1012 annotate__scnprintf_title(hists, title, sizeof(title)); 1013 1013 annotate_browser__show(browser, title, help); 1014 1014 continue; 1015 + } 1015 1016 case 'o': 1016 1017 annotate_opts.use_offset = !annotate_opts.use_offset; 1017 1018 annotation__update_column_widths(notes);