Skip to content

Commit 5478afc

Browse files
ramosian-gliderakpm00
authored andcommitted
kmsan: fix memcpy tests
Recent Clang changes may cause it to delete calls of memcpy(), if the source is an uninitialized volatile local. This happens because passing a pointer to a volatile local into memcpy() discards the volatile qualifier, giving the compiler a free hand to optimize the memcpy() call away. Use OPTIMIZER_HIDE_VAR() to hide the uninitialized var from the too-smart compiler. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Alexander Potapenko <[email protected]> Suggested-by: Marco Elver <[email protected]> Reviewed-by: Marco Elver <[email protected]> Cc: Dmitry Vyukov <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent de2e517 commit 5478afc

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

mm/kmsan/kmsan_test.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ static void test_memcpy_aligned_to_aligned(struct kunit *test)
419419
kunit_info(
420420
test,
421421
"memcpy()ing aligned uninit src to aligned dst (UMR report)\n");
422+
OPTIMIZER_HIDE_VAR(uninit_src);
422423
memcpy((void *)&dst, (void *)&uninit_src, sizeof(uninit_src));
423424
kmsan_check_memory((void *)&dst, sizeof(dst));
424425
KUNIT_EXPECT_TRUE(test, report_matches(&expect));
@@ -441,6 +442,7 @@ static void test_memcpy_aligned_to_unaligned(struct kunit *test)
441442
kunit_info(
442443
test,
443444
"memcpy()ing aligned uninit src to unaligned dst (UMR report)\n");
445+
OPTIMIZER_HIDE_VAR(uninit_src);
444446
memcpy((void *)&dst[1], (void *)&uninit_src, sizeof(uninit_src));
445447
kmsan_check_memory((void *)dst, 4);
446448
KUNIT_EXPECT_TRUE(test, report_matches(&expect));
@@ -464,6 +466,7 @@ static void test_memcpy_aligned_to_unaligned2(struct kunit *test)
464466
kunit_info(
465467
test,
466468
"memcpy()ing aligned uninit src to unaligned dst - part 2 (UMR report)\n");
469+
OPTIMIZER_HIDE_VAR(uninit_src);
467470
memcpy((void *)&dst[1], (void *)&uninit_src, sizeof(uninit_src));
468471
kmsan_check_memory((void *)&dst[4], sizeof(uninit_src));
469472
KUNIT_EXPECT_TRUE(test, report_matches(&expect));

0 commit comments

Comments
 (0)