softmmu/physmem: Silence GCC 10 maybe-uninitialized error
PATCH v2 1/1 softmmu/physmem: Silence GCC 10 maybe-uninitialized error
When building with GCC 10.2 configured with --extra-cflags=-Os, we get:
softmmu/physmem.c: In function ‘address_space_translate_for_iotlb’:
softmmu/physmem.c:643:26: error: ‘notifier’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
643 | notifier->active = true;
| ^
softmmu/physmem.c:608:23: note: ‘notifier’ was declared here
608 | TCGIOMMUNotifier *notifier;
| ^~~~~~~~Initialize 'notifier' to silence the warning.
---
v2: Remove pointless assert (Peter Maydell)
Yet another hole in our CI.
Supersedes: <[email protected]>
--- softmmu/physmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
softmmu/physmem.c +1 -1
@@ -605,7 +605,7 @@ static void tcg_register_iommu_notifier(CPUState *cpu,* when the IOMMU tells us the mappings we've cached have changed. */ MemoryRegion *mr =MEMORY_REGION (iommu_mr); -TCGIOMMUNotifier *notifier; +TCGIOMMUNotifier *notifier =NULL ;int i;for (i =0 ; i < cpu->iommu_notifiers->len; i++) {
Signature · 1 line
2.26.2
Paolo Bonzini
AppliedQuoted 29 lines · Philippe Mathieu-Daudé
When building with GCC 10.2 configured with --extra-cflags=-Os, we get:
softmmu/physmem.c: In function ‘address_space_translate_for_iotlb’:softmmu/physmem.c:643:26: error: ‘notifier’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 643 | notifier->active = true; | ^ softmmu/physmem.c:608:23: note: ‘notifier’ was declared here 608 | TCGIOMMUNotifier *notifier; | ^~~~~~~~Initialize 'notifier' to silence the warning.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
v2: Remove pointless assert (Peter Maydell)Yet another hole in our CI.
Supersedes: <[email protected]>
--- softmmu/physmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)softmmu/physmem.c +0
-0
softmmu/physmem.c static void tcg_register_iommu_notifier(CPUState *cpu, · line 611
Quoted 8 lines
softmmu/physmem.c +1
-1@@ -605,7 +605,7 @@ static void tcg_register_iommu_notifier(CPUState *cpu,* when the IOMMU tells us the mappings we've cached have changed. */ MemoryRegion *mr =MEMORY_REGION (iommu_mr); -TCGIOMMUNotifier *notifier; +TCGIOMMUNotifier *notifier =NULL ;int i;for (i =0 ; i < cpu->iommu_notifiers->len; i++) {
Queued, thanks.
Paolo
Quoted 10 lines · Philippe Mathieu-Daudé
When building with GCC 10.2 configured with --extra-cflags=-Os, we get:
softmmu/physmem.c: In function ‘address_space_translate_for_iotlb’:softmmu/physmem.c:643:26: error: ‘notifier’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 643 | notifier->active = true; | ^ softmmu/physmem.c:608:23: note: ‘notifier’ was declared here 608 | TCGIOMMUNotifier *notifier; | ^~~~~~~~
Quoted 7 lines
Initialize 'notifier' to silence the warning.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
v2: Remove pointless assert (Peter Maydell)Yet another hole in our CI.
I wouldn't call this a hole in the CI. AFAIU we don't support compiling with anything else than the default -O2 (and maybe -O0 for debugging?). -O3 is known to produce a lot of compiler warnings, and apparently -Os has such "problems", too. As far as I can see, it's a false positive warning here, "notifier" should always get initialized, the compiler just fails to see it correctly. Anyway, initializing the variable also can not hurt, so: