[PATCH] tcg/perf: Placate clang-21's -Wdefault-const-init-field-unsafe

Ilya Leoshkevich posted 1 patch 5 months, 4 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20250519214903.55284-1-iii@linux.ibm.com
Maintainers: Richard Henderson <richard.henderson@linaro.org>
There is a newer version of this series
tcg/perf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] tcg/perf: Placate clang-21's -Wdefault-const-init-field-unsafe
Posted by Ilya Leoshkevich 5 months, 4 weeks ago
clang-21 complains about the const "name" field in struct debug_entry.
While this warning may be too aggressive, there is not too much value
in having const there, so just drop it.

Note: in addition to this fix, I had to turn off the following clang-21
warnings to make the build work:

* -Wno-parentheses-equality
* -Wno-unused-value
* -Wno-tautological-unsigned-enum-zero-compare
* -Wno-tautological-compare

Reported-by: Peter Maydell <peter.maydell@linaro.org>
Closes: https://gitlab.com/qemu-project/qemu/-/issues/2970
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 tcg/perf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tcg/perf.c b/tcg/perf.c
index 4e8d2c1bee7..f30c5b489d1 100644
--- a/tcg/perf.c
+++ b/tcg/perf.c
@@ -154,7 +154,7 @@ struct debug_entry {
     uint64_t addr;
     int lineno;
     int discrim;
-    const char name[];
+    char name[];
 };
 
 struct jr_code_debug_info {
-- 
2.49.0
Re: [PATCH] tcg/perf: Placate clang-21's -Wdefault-const-init-field-unsafe
Posted by Richard Henderson 5 months, 3 weeks ago
On 5/19/25 22:48, Ilya Leoshkevich wrote:
> diff --git a/tcg/perf.c b/tcg/perf.c
> index 4e8d2c1bee7..f30c5b489d1 100644
> --- a/tcg/perf.c
> +++ b/tcg/perf.c
> @@ -154,7 +154,7 @@ struct debug_entry {
>       uint64_t addr;
>       int lineno;
>       int discrim;
> -    const char name[];
> +    char name[];
>   };
>   
>   struct jr_code_debug_info {

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
Re: [PATCH] tcg/perf: Placate clang-21's -Wdefault-const-init-field-unsafe
Posted by Peter Maydell 5 months, 4 weeks ago
On Mon, 19 May 2025 at 22:49, Ilya Leoshkevich <iii@linux.ibm.com> wrote:
>
> clang-21 complains about the const "name" field in struct debug_entry.
> While this warning may be too aggressive, there is not too much value
> in having const there, so just drop it.

It looks like this warning is only emitted by git-trunk clang,
and there's a proposal to make it stop doing it:
https://github.com/llvm/llvm-project/pull/140578
so our other option here is "do nothing" :-)

But I agree there's not really any purpose to the 'const' here.

> Note: in addition to this fix, I had to turn off the following clang-21
> warnings to make the build work:
>
> * -Wno-parentheses-equality
> * -Wno-unused-value
> * -Wno-tautological-unsigned-enum-zero-compare
> * -Wno-tautological-compare

Interesting. I wonder if any of those are worth looking at.g

> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Closes: https://gitlab.com/qemu-project/qemu/-/issues/2970
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  tcg/perf.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tcg/perf.c b/tcg/perf.c
> index 4e8d2c1bee7..f30c5b489d1 100644
> --- a/tcg/perf.c
> +++ b/tcg/perf.c
> @@ -154,7 +154,7 @@ struct debug_entry {
>      uint64_t addr;
>      int lineno;
>      int discrim;
> -    const char name[];
> +    char name[];
>  };

With an update to the commit message to note that this warning
isn't (yet) in any released clang

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM