All of lore.kernel.org
 help / color / mirror / Atom feed
* [kees:dev/v7.0-rc2/obt 6/6] drivers/misc/lkdtm/bugs.c:835:17: sparse: sparse: cast truncates bits from constant value (7fffffff becomes ff)
@ 2026-03-31 18:06 kernel test robot
  2026-03-31 19:48 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: kernel test robot @ 2026-03-31 18:06 UTC (permalink / raw)
  To: Kees Cook; +Cc: oe-kbuild-all

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git dev/v7.0-rc2/obt
head:   e5a10c0ef1457ad3c713a1bbe087da2b407d4722
commit: e5a10c0ef1457ad3c713a1bbe087da2b407d4722 [6/6] lkdtm/bugs: Add basic Overflow Behavior Types test
config: arc-randconfig-r121-20260331 (https://download.01.org/0day-ci/archive/20260401/202604010149.X24fVPZ0-lkp@intel.com/config)
compiler: arc-linux-gcc (GCC) 8.5.0
sparse: v0.6.5-rc1
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260401/202604010149.X24fVPZ0-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202604010149.X24fVPZ0-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/misc/lkdtm/bugs.c:835:17: sparse: sparse: cast truncates bits from constant value (7fffffff becomes ff)

vim +835 drivers/misc/lkdtm/bugs.c

   819	
   820	static void lkdtm_OBT_TRUNC_TRAP(void)
   821	{
   822		volatile int big = INT_MAX;
   823		volatile int wide_low_value = 5;
   824		u8t narrow_low_value = 0;
   825		s32t same = 0;
   826		u8t small = 0;
   827	
   828		pr_info("Performing same-width assignment\n");
   829		same = big;
   830	
   831		pr_info("Performing small-value assignment\n");
   832		narrow_low_value = wide_low_value;
   833	
   834		pr_info("Performing truncated assignment\n");
 > 835		small = big;
   836	
   837		pr_info("FAIL: survived overflowing truncated assignment: %d -> %u (ok: %d -> %u)\n",
   838			same, small, wide_low_value, narrow_low_value);
   839		pr_expected_config(OVERFLOW_BEHAVIOR_TYPES_TRAP);
   840	}
   841	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [kees:dev/v7.0-rc2/obt 6/6] drivers/misc/lkdtm/bugs.c:835:17: sparse: sparse: cast truncates bits from constant value (7fffffff becomes ff)
  2026-03-31 18:06 [kees:dev/v7.0-rc2/obt 6/6] drivers/misc/lkdtm/bugs.c:835:17: sparse: sparse: cast truncates bits from constant value (7fffffff becomes ff) kernel test robot
@ 2026-03-31 19:48 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2026-03-31 19:48 UTC (permalink / raw)
  To: kernel test robot; +Cc: oe-kbuild-all

On Wed, Apr 01, 2026 at 02:06:25AM +0800, kernel test robot wrote:
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git dev/v7.0-rc2/obt
> head:   e5a10c0ef1457ad3c713a1bbe087da2b407d4722
> commit: e5a10c0ef1457ad3c713a1bbe087da2b407d4722 [6/6] lkdtm/bugs: Add basic Overflow Behavior Types test
> config: arc-randconfig-r121-20260331 (https://download.01.org/0day-ci/archive/20260401/202604010149.X24fVPZ0-lkp@intel.com/config)
> compiler: arc-linux-gcc (GCC) 8.5.0
> sparse: v0.6.5-rc1
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260401/202604010149.X24fVPZ0-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202604010149.X24fVPZ0-lkp@intel.com/
> 
> sparse warnings: (new ones prefixed by >>)
> >> drivers/misc/lkdtm/bugs.c:835:17: sparse: sparse: cast truncates bits from constant value (7fffffff becomes ff)

This is by design. What's the right way to make sparse ignore a value
like this? (It appears to be seeing through the "volatile" qualifier.)

-Kees

> 
> vim +835 drivers/misc/lkdtm/bugs.c
> 
>    819	
>    820	static void lkdtm_OBT_TRUNC_TRAP(void)
>    821	{
>    822		volatile int big = INT_MAX;
>    823		volatile int wide_low_value = 5;
>    824		u8t narrow_low_value = 0;
>    825		s32t same = 0;
>    826		u8t small = 0;
>    827	
>    828		pr_info("Performing same-width assignment\n");
>    829		same = big;
>    830	
>    831		pr_info("Performing small-value assignment\n");
>    832		narrow_low_value = wide_low_value;
>    833	
>    834		pr_info("Performing truncated assignment\n");
>  > 835		small = big;
>    836	
>    837		pr_info("FAIL: survived overflowing truncated assignment: %d -> %u (ok: %d -> %u)\n",
>    838			same, small, wide_low_value, narrow_low_value);
>    839		pr_expected_config(OVERFLOW_BEHAVIOR_TYPES_TRAP);
>    840	}
>    841	
> 
> -- 
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests/wiki

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-31 19:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-31 18:06 [kees:dev/v7.0-rc2/obt 6/6] drivers/misc/lkdtm/bugs.c:835:17: sparse: sparse: cast truncates bits from constant value (7fffffff becomes ff) kernel test robot
2026-03-31 19:48 ` Kees Cook

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.