After a recent improvement in clang to warn on unsequenced accesses to volatile variables [1], an instance appears in lkdtm_FAM_BOUNDS(), which can break the build with CONFIG_WERROR=y / W=e: drivers/misc/lkdtm/bugs.c:493:31: error: unsequenced accesses to volatile qualified 'element_count' [-Werror,-Wunsequenced] 493 | inst->array[element_count] = element_count; | ~~~~~~~~~~~~~ ^ Per C11 5.1.2.3.2, accessing a volatile object is a side effect. Per C11 6.5.2, unsequenced side effects on the same scalar object are undefined behavior. Per C11 6.5.16.3, the value computations of the left and right operands of the assignment operator are unsequenced. This variable is marked volatile to hide its value from the compiler at compile time. The same thing can be accomplished with OPTIMIZER_HIDE_VAR. Drop volatile from element_count to clear up the warning. The tests still pass and there are no warnings at compile time. Cc: stable@vger.kernel.org Fixes: 5d207e83ca41 ("lkdtm: Add FAM_BOUNDS test for __counted_by") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202611140405.wMowxoPE-lkp@intel.com/ Closes: https://github.com/ClangBuiltLinux/linux/issues/2194 Link: https://github.com/llvm/llvm-project/commit/955715460eaf9188c241c74750637fc82dfcc423 [1] Signed-off-by: Nathan Chancellor --- drivers/misc/lkdtm/bugs.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/misc/lkdtm/bugs.c b/drivers/misc/lkdtm/bugs.c index 2761685cf4f8..7c799fef89a8 100644 --- a/drivers/misc/lkdtm/bugs.c +++ b/drivers/misc/lkdtm/bugs.c @@ -472,12 +472,14 @@ struct lkdtm_cb_fam { int array[] __counted_by(count); }; -static volatile int element_count = 4; +static int element_count = 4; static void lkdtm_FAM_BOUNDS(void) { struct lkdtm_cb_fam *inst; + OPTIMIZER_HIDE_VAR(element_count); + inst = kzalloc_flex(*inst, array, element_count + 1); if (!inst) { pr_err("FAIL: could not allocate test struct!\n"); @@ -534,6 +536,8 @@ static void lkdtm_PTR_BOUNDS(void) { struct lkdtm_cb_ptr *inst; + OPTIMIZER_HIDE_VAR(element_count); + inst = kzalloc_obj(*inst); if (!inst) { pr_err("FAIL: could not allocate struct lkdtm_cb_ptr!\n"); --- base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master change-id: 20261114-lkdtm-bugs-wunsequenced-7c18499c2771 Best regards, -- Cheers, Nathan