Skip to content

Commit 30edbdf

Browse files
committed
ubsan: Silence W=1 warnings in self-test
Silence a handful of W=1 warnings in the UBSan selftest, which set variables without using them. For example: lib/test_ubsan.c:101:6: warning: variable 'val1' set but not used [-Wunused-but-set-variable] 101 | int val1 = 10; | ^ Reported-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/ Reviewed-by: Marco Elver <[email protected]> Signed-off-by: Kees Cook <[email protected]>
1 parent 167ebed commit 30edbdf

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ obj-$(CONFIG_HASH_KUNIT_TEST) += test_hash.o
6969
obj-$(CONFIG_TEST_IDA) += test_ida.o
7070
obj-$(CONFIG_TEST_UBSAN) += test_ubsan.o
7171
CFLAGS_test_ubsan.o += $(call cc-disable-warning, vla)
72+
CFLAGS_test_ubsan.o += $(call cc-disable-warning, unused-but-set-variable)
7273
UBSAN_SANITIZE_test_ubsan.o := y
7374
obj-$(CONFIG_TEST_KSTRTOX) += test-kstrtox.o
7475
obj-$(CONFIG_TEST_LIST_SORT) += test_list_sort.o

lib/test_ubsan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ static void test_ubsan_divrem_overflow(void)
2323
static void test_ubsan_shift_out_of_bounds(void)
2424
{
2525
volatile int neg = -1, wrap = 4;
26-
int val1 = 10;
27-
int val2 = INT_MAX;
26+
volatile int val1 = 10;
27+
volatile int val2 = INT_MAX;
2828

2929
UBSAN_TEST(CONFIG_UBSAN_SHIFT, "negative exponent");
3030
val1 <<= neg;

0 commit comments

Comments
 (0)