GCC 8 became more fussy about detecting switch
fallthroughs. First it doesn't like it if you have
a fallthrough attribute that is not before a case
statement. e.g.
FOO:
BAR:
WIZZ:
ATTRIBUTE_FALLTHROUGH;
Is unacceptable as there's no final case statement,
so while FOO & BAR are falling through, WIZZ is
not falling through. IOW, GCC wants us to write
FOO:
BAR:
ATTRIBUTE_FALLTHROUGH;
WIZZ:
Second, it will report risk of fallthrough even if you
have a case statement for every single enum value, but
only if the switch is nested inside another switch and
the outer case statement has no final break. This is
is arguably valid because despite the fact that we have
cast from "int" to the enum typedef, nothing guarantees
that the variable we're switching on only contains values
that have corresponding switch labels. e.g.
int domstate = 87539319;
switch ((virDomainState)domstate) {
...
}
will not match enum value, but also not raise any kind
of compiler warning. So it is right to complain about
risk of fallthrough if no default: is present.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
Pushed as a minimal build-fix for Fedora rawhide, since the bigger
switch cleanup series is taking a while to get ready for merge.
src/qemu/qemu_domain.c | 6 ++++--
src/qemu/qemu_domain_address.c | 10 ++++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 593b9d0fb5..b1308e5a49 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -173,8 +173,9 @@ qemuDomainAsyncJobPhaseToString(qemuDomainAsyncJob job,
case QEMU_ASYNC_JOB_SNAPSHOT:
case QEMU_ASYNC_JOB_START:
case QEMU_ASYNC_JOB_NONE:
- case QEMU_ASYNC_JOB_LAST:
ATTRIBUTE_FALLTHROUGH;
+ case QEMU_ASYNC_JOB_LAST:
+ break;
}
return "none";
@@ -197,8 +198,9 @@ qemuDomainAsyncJobPhaseFromString(qemuDomainAsyncJob job,
case QEMU_ASYNC_JOB_SNAPSHOT:
case QEMU_ASYNC_JOB_START:
case QEMU_ASYNC_JOB_NONE:
- case QEMU_ASYNC_JOB_LAST:
ATTRIBUTE_FALLTHROUGH;
+ case QEMU_ASYNC_JOB_LAST:
+ break;
}
if (STREQ(phase, "none"))
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index dd3e703ca5..001c84a906 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -543,6 +543,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
case VIR_DOMAIN_CONTROLLER_MODEL_USB_LAST:
return 0;
}
+ break;
case VIR_DOMAIN_CONTROLLER_TYPE_IDE:
return pciFlags;
@@ -567,6 +568,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
case VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LAST:
return 0;
}
+ break;
case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL:
return virtioFlags;
@@ -619,6 +621,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
case VIR_DOMAIN_SOUND_MODEL_LAST:
return 0;
}
+ break;
case VIR_DOMAIN_DEVICE_DISK:
switch ((virDomainDiskBus) dev->data.disk->bus) {
@@ -636,6 +639,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
case VIR_DOMAIN_DISK_BUS_LAST:
return 0;
}
+ break;
case VIR_DOMAIN_DEVICE_HOSTDEV: {
virDomainHostdevDefPtr hostdev = dev->data.hostdev;
@@ -748,6 +752,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
case VIR_DOMAIN_MEMBALLOON_MODEL_LAST:
return 0;
}
+ break;
case VIR_DOMAIN_DEVICE_RNG:
switch ((virDomainRNGModel) dev->data.rng->model) {
@@ -757,6 +762,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
case VIR_DOMAIN_RNG_MODEL_LAST:
return 0;
}
+ break;
case VIR_DOMAIN_DEVICE_WATCHDOG:
/* only one model connects using PCI */
@@ -769,6 +775,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
case VIR_DOMAIN_WATCHDOG_MODEL_LAST:
return 0;
}
+ break;
case VIR_DOMAIN_DEVICE_VIDEO:
switch ((virDomainVideoType) dev->data.video->type) {
@@ -789,6 +796,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
case VIR_DOMAIN_VIDEO_TYPE_LAST:
return 0;
}
+ break;
case VIR_DOMAIN_DEVICE_SHMEM:
return pciFlags;
@@ -805,6 +813,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
case VIR_DOMAIN_INPUT_BUS_LAST:
return 0;
}
+ break;
case VIR_DOMAIN_DEVICE_CHR:
switch ((virDomainChrSerialTargetType) dev->data.chr->targetType) {
@@ -820,6 +829,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
case VIR_DOMAIN_CHR_SERIAL_TARGET_TYPE_LAST:
return 0;
}
+ break;
/* These devices don't ever connect with PCI */
case VIR_DOMAIN_DEVICE_NVRAM:
--
2.14.3