[sw] Ensure all switches have defaults
Signed-off-by: Sam Elliott <selliott@lowrisc.org>
diff --git a/meson.build b/meson.build
index cb7871c..286e297 100644
--- a/meson.build
+++ b/meson.build
@@ -45,6 +45,8 @@
# C compiler arguments to to catch common errors, used on all builds.
extra_warning_args = [
'-Wimplicit-fallthrough', # Error on implicit fallthrough
+ '-Wswitch-default', # Ensure all switches have default statements
+ '-Wno-covered-switch-default', # We require `default:` always.
]
# C compiler arguments to optimize for size, used on cross builds only.
diff --git a/sw/device/benchmarks/coremark/top_earlgrey/ee_printf.c b/sw/device/benchmarks/coremark/top_earlgrey/ee_printf.c
index b010cbd..210c9e2 100644
--- a/sw/device/benchmarks/coremark/top_earlgrey/ee_printf.c
+++ b/sw/device/benchmarks/coremark/top_earlgrey/ee_printf.c
@@ -506,6 +506,8 @@
case '0':
flags |= ZEROPAD;
goto repeat;
+ default:
+ break;
}
// Get field width
diff --git a/sw/device/lib/usb_controlep.c b/sw/device/lib/usb_controlep.c
index fbb20c2..9d4836e 100644
--- a/sw/device/lib/usb_controlep.c
+++ b/sw/device/lib/usb_controlep.c
@@ -149,6 +149,9 @@
usbdev_buf_copyto_byid(ctx, buf, &zero, len);
usbdev_sendbuf_byid(ctx, buf, len, ctctx->ep);
return kCtWaitIn;
+
+ default:
+ return kCtError;
}
return kCtError;
}
diff --git a/sw/device/tests/runtime/print_unittest.cc b/sw/device/tests/runtime/print_unittest.cc
index 4013292..6e00af0 100644
--- a/sw/device/tests/runtime/print_unittest.cc
+++ b/sw/device/tests/runtime/print_unittest.cc
@@ -169,6 +169,9 @@
case 8:
EXPECT_EQ(buf_, "Hello, 0x0000000000001234!\n");
break;
+ default:
+ FAIL() << "Unknown pointer size";
+ break;
}
}
@@ -181,6 +184,9 @@
case 8:
EXPECT_EQ(buf_, "Hello, 0x0000000000000000!\n");
break;
+ default:
+ FAIL() << "Unknown pointer size";
+ break;
}
}