Skip to contentSkip to conversation

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

PATCH Superseded Ilya Leoshkevich 3 participants 3 messages May 19, 2025 – May 24, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

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

---
 tcg/perf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/perf.c +1 -1
index 4e8d2c1bee7..f30c5b489d1 100644
@@ -154,7 +154,7 @@ struct debug_entry {
     uint64_t addr;
     int lineno;
     int discrim;
-    const char name[];
+    char name[];
 };
 
 struct jr_code_debug_info {
Signature · 1 line
2.49.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Ilya Leoshkevich

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.

Quoted 7 lines

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

Quoted 12 lines
---
 tcg/perf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/perf.c +0 -0
index 4e8d2c1bee7..f30c5b489d1 100644

tcg/perf.c struct debug_entry { · line 158

Quoted 6 lines
tcg/perf.c +1 -1
@@ -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

thanks
-- PMM