* [PATCH] perf annotate: Fix Clang build by adding block in switch case
@ 2025-10-22 11:02 James Clark
2025-10-22 16:39 ` Ian Rogers
2025-10-24 18:57 ` Namhyung Kim
0 siblings, 2 replies; 3+ messages in thread
From: James Clark @ 2025-10-22 11:02 UTC (permalink / raw)
To: linux-perf-users, namhyung, acme
Cc: irogers, James Clark, Peter Zijlstra, Ingo Molnar, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, Justin Stitt, Tianyou Li,
Thomas Falcon, Zhiguo Zhou, Wangyang Guo, Pan Deng, linux-kernel,
llvm
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>
---
tools/perf/ui/browsers/annotate.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
index 3a81912279ad..36aca8d6d003 100644
--- a/tools/perf/ui/browsers/annotate.c
+++ b/tools/perf/ui/browsers/annotate.c
@@ -995,7 +995,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
case 'H':
nd = browser->curr_hot;
break;
- case 's':
+ case 's': {
struct annotation_line *al = NULL;
s64 offset = annotate_browser__curr_hot_offset(browser);
@@ -1012,6 +1012,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
annotate__scnprintf_title(hists, title, sizeof(title));
annotate_browser__show(browser, title, help);
continue;
+ }
case 'o':
annotate_opts.use_offset = !annotate_opts.use_offset;
annotation__update_column_widths(notes);
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf annotate: Fix Clang build by adding block in switch case
2025-10-22 11:02 [PATCH] perf annotate: Fix Clang build by adding block in switch case James Clark
@ 2025-10-22 16:39 ` Ian Rogers
2025-10-24 18:57 ` Namhyung Kim
1 sibling, 0 replies; 3+ messages in thread
From: Ian Rogers @ 2025-10-22 16:39 UTC (permalink / raw)
To: James Clark
Cc: linux-perf-users, namhyung, acme, Peter Zijlstra, Ingo Molnar,
Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter,
Nathan Chancellor, Nick Desaulniers, Bill Wendling, Justin Stitt,
Tianyou Li, Thomas Falcon, Zhiguo Zhou, Wangyang Guo, Pan Deng,
linux-kernel, llvm
On Wed, Oct 22, 2025 at 4:03 AM James Clark <james.clark@linaro.org> wrote:
>
> 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>
Thanks,
Ian
> ---
> tools/perf/ui/browsers/annotate.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/ui/browsers/annotate.c b/tools/perf/ui/browsers/annotate.c
> index 3a81912279ad..36aca8d6d003 100644
> --- a/tools/perf/ui/browsers/annotate.c
> +++ b/tools/perf/ui/browsers/annotate.c
> @@ -995,7 +995,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
> case 'H':
> nd = browser->curr_hot;
> break;
> - case 's':
> + case 's': {
> struct annotation_line *al = NULL;
> s64 offset = annotate_browser__curr_hot_offset(browser);
>
> @@ -1012,6 +1012,7 @@ static int annotate_browser__run(struct annotate_browser *browser,
> annotate__scnprintf_title(hists, title, sizeof(title));
> annotate_browser__show(browser, title, help);
> continue;
> + }
> case 'o':
> annotate_opts.use_offset = !annotate_opts.use_offset;
> annotation__update_column_widths(notes);
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] perf annotate: Fix Clang build by adding block in switch case
2025-10-22 11:02 [PATCH] perf annotate: Fix Clang build by adding block in switch case James Clark
2025-10-22 16:39 ` Ian Rogers
@ 2025-10-24 18:57 ` Namhyung Kim
1 sibling, 0 replies; 3+ messages in thread
From: Namhyung Kim @ 2025-10-24 18:57 UTC (permalink / raw)
To: linux-perf-users, acme, James Clark
Cc: irogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
Alexander Shishkin, Jiri Olsa, Adrian Hunter, Nathan Chancellor,
Nick Desaulniers, Bill Wendling, Justin Stitt, Tianyou Li,
Thomas Falcon, Zhiguo Zhou, Wangyang Guo, Pan Deng, linux-kernel,
llvm
On Wed, 22 Oct 2025 12:02:40 +0100, James Clark wrote:
> 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.
>
> [...]
Applied to perf-tools-next, thanks!
Best regards,
Namhyung
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-24 18:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-22 11:02 [PATCH] perf annotate: Fix Clang build by adding block in switch case James Clark
2025-10-22 16:39 ` Ian Rogers
2025-10-24 18:57 ` Namhyung Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).