All of lore.kernel.org
 help / color / mirror / Atom feed
* lib/test_ubsan.c:71:6: warning: variable 'val1' set but not used
@ 2021-11-10 19:04 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2021-11-10 19:04 UTC (permalink / raw)
  To: Kees Cook
  Cc: llvm, kbuild-all, linux-kernel, Andrew Morton,
	Linux Memory Management List

[-- Attachment #1: Type: text/plain, Size: 6785 bytes --]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   89d714ab6043bca7356b5c823f5335f5dce1f930
commit: 4a26f49b7b3dbe998d9b2561f9f256a1c3fdb74a ubsan: expand tests and reporting
date:   11 months ago
config: arm-randconfig-r016-20211109 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project f3798ad5fa845771846599f3c088016e3aef800c)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4a26f49b7b3dbe998d9b2561f9f256a1c3fdb74a
        git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
        git fetch --no-tags linus master
        git checkout 4a26f49b7b3dbe998d9b2561f9f256a1c3fdb74a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   lib/test_ubsan.c:16:15: warning: variable 'val' set but not used [-Wunused-but-set-variable]
           volatile int val = INT_MAX;
                        ^
   lib/test_ubsan.c:17:24: warning: variable 'uval' set but not used [-Wunused-but-set-variable]
           volatile unsigned int uval = UINT_MAX;
                                 ^
   lib/test_ubsan.c:29:24: warning: variable 'uval' set but not used [-Wunused-but-set-variable]
           volatile unsigned int uval = 0;
                                 ^
   lib/test_ubsan.c:28:15: warning: variable 'val' set but not used [-Wunused-but-set-variable]
           volatile int val = INT_MIN;
                        ^
   lib/test_ubsan.c:42:24: warning: variable 'uval' set but not used [-Wunused-but-set-variable]
           volatile unsigned int uval = UINT_MAX / 2;
                                 ^
   lib/test_ubsan.c:41:15: warning: variable 'val' set but not used [-Wunused-but-set-variable]
           volatile int val = INT_MAX / 2;
                        ^
   lib/test_ubsan.c:61:15: warning: variable 'val' set but not used [-Wunused-but-set-variable]
           volatile int val = 16;
                        ^
>> lib/test_ubsan.c:71:6: warning: variable 'val1' set but not used [-Wunused-but-set-variable]
           int val1 = 10;
               ^
   lib/test_ubsan.c:72:6: warning: variable 'val2' set but not used [-Wunused-but-set-variable]
           int val2 = INT_MAX;
               ^
   lib/test_ubsan.c:107:37: warning: variable 'eptr' set but not used [-Wunused-but-set-variable]
           enum ubsan_test_enum eval, eval2, *eptr;
                                              ^
   lib/test_ubsan.c:106:19: warning: variable 'ptr' set but not used [-Wunused-but-set-variable]
           bool val, val2, *ptr;
                            ^
   lib/test_ubsan.c:130:6: warning: variable 'val' set but not used [-Wunused-but-set-variable]
           int val;
               ^
   lib/test_ubsan.c:150:27: warning: variable 'val2' set but not used [-Wunused-but-set-variable]
           volatile long long *ptr, val2;
                                    ^
>> lib/test_ubsan.c:170:28: warning: unused variable 'skip_ubsan_array' [-Wunused-const-variable]
   static const test_ubsan_fp skip_ubsan_array[] = {
                              ^
   14 warnings generated.


vim +/val1 +71 lib/test_ubsan.c

    67	
    68	static void test_ubsan_shift_out_of_bounds(void)
    69	{
    70		volatile int neg = -1, wrap = 4;
  > 71		int val1 = 10;
    72		int val2 = INT_MAX;
    73	
    74		UBSAN_TEST(CONFIG_UBSAN_SHIFT, "negative exponent");
    75		val1 <<= neg;
    76	
    77		UBSAN_TEST(CONFIG_UBSAN_SHIFT, "left overflow");
    78		val2 <<= wrap;
    79	}
    80	
    81	static void test_ubsan_out_of_bounds(void)
    82	{
    83		volatile int i = 4, j = 5, k = -1;
    84		volatile char above[4] = { }; /* Protect surrounding memory. */
    85		volatile int arr[4];
    86		volatile char below[4] = { }; /* Protect surrounding memory. */
    87	
    88		above[0] = below[0];
    89	
    90		UBSAN_TEST(CONFIG_UBSAN_BOUNDS, "above");
    91		arr[j] = i;
    92	
    93		UBSAN_TEST(CONFIG_UBSAN_BOUNDS, "below");
    94		arr[k] = i;
    95	}
    96	
    97	enum ubsan_test_enum {
    98		UBSAN_TEST_ZERO = 0,
    99		UBSAN_TEST_ONE,
   100		UBSAN_TEST_MAX,
   101	};
   102	
   103	static void test_ubsan_load_invalid_value(void)
   104	{
   105		volatile char *dst, *src;
   106		bool val, val2, *ptr;
   107		enum ubsan_test_enum eval, eval2, *eptr;
   108		unsigned char c = 0xff;
   109	
   110		UBSAN_TEST(CONFIG_UBSAN_BOOL, "bool");
   111		dst = (char *)&val;
   112		src = &c;
   113		*dst = *src;
   114	
   115		ptr = &val2;
   116		val2 = val;
   117	
   118		UBSAN_TEST(CONFIG_UBSAN_ENUM, "enum");
   119		dst = (char *)&eval;
   120		src = &c;
   121		*dst = *src;
   122	
   123		eptr = &eval2;
   124		eval2 = eval;
   125	}
   126	
   127	static void test_ubsan_null_ptr_deref(void)
   128	{
   129		volatile int *ptr = NULL;
   130		int val;
   131	
   132		UBSAN_TEST(CONFIG_UBSAN_OBJECT_SIZE);
   133		val = *ptr;
   134	}
   135	
   136	static void test_ubsan_misaligned_access(void)
   137	{
   138		volatile char arr[5] __aligned(4) = {1, 2, 3, 4, 5};
   139		volatile int *ptr, val = 6;
   140	
   141		UBSAN_TEST(CONFIG_UBSAN_ALIGNMENT);
   142		ptr = (int *)(arr + 1);
   143		*ptr = val;
   144	}
   145	
   146	static void test_ubsan_object_size_mismatch(void)
   147	{
   148		/* "((aligned(8)))" helps this not into be misaligned for ptr-access. */
   149		volatile int val __aligned(8) = 4;
   150		volatile long long *ptr, val2;
   151	
   152		UBSAN_TEST(CONFIG_UBSAN_OBJECT_SIZE);
   153		ptr = (long long *)&val;
   154		val2 = *ptr;
   155	}
   156	
   157	static const test_ubsan_fp test_ubsan_array[] = {
   158		test_ubsan_add_overflow,
   159		test_ubsan_sub_overflow,
   160		test_ubsan_mul_overflow,
   161		test_ubsan_negate_overflow,
   162		test_ubsan_shift_out_of_bounds,
   163		test_ubsan_out_of_bounds,
   164		test_ubsan_load_invalid_value,
   165		test_ubsan_misaligned_access,
   166		test_ubsan_object_size_mismatch,
   167	};
   168	
   169	/* Excluded because they Oops the module. */
 > 170	static const test_ubsan_fp skip_ubsan_array[] = {
   171		test_ubsan_divrem_overflow,
   172		test_ubsan_null_ptr_deref,
   173	};
   174	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 33038 bytes --]

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

* lib/test_ubsan.c:71:6: warning: variable 'val1' set but not used
@ 2021-11-10 19:04 ` kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2021-11-10 19:04 UTC (permalink / raw)
  To: kbuild-all

[-- Attachment #1: Type: text/plain, Size: 6969 bytes --]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   89d714ab6043bca7356b5c823f5335f5dce1f930
commit: 4a26f49b7b3dbe998d9b2561f9f256a1c3fdb74a ubsan: expand tests and reporting
date:   11 months ago
config: arm-randconfig-r016-20211109 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project f3798ad5fa845771846599f3c088016e3aef800c)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=4a26f49b7b3dbe998d9b2561f9f256a1c3fdb74a
        git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
        git fetch --no-tags linus master
        git checkout 4a26f49b7b3dbe998d9b2561f9f256a1c3fdb74a
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   lib/test_ubsan.c:16:15: warning: variable 'val' set but not used [-Wunused-but-set-variable]
           volatile int val = INT_MAX;
                        ^
   lib/test_ubsan.c:17:24: warning: variable 'uval' set but not used [-Wunused-but-set-variable]
           volatile unsigned int uval = UINT_MAX;
                                 ^
   lib/test_ubsan.c:29:24: warning: variable 'uval' set but not used [-Wunused-but-set-variable]
           volatile unsigned int uval = 0;
                                 ^
   lib/test_ubsan.c:28:15: warning: variable 'val' set but not used [-Wunused-but-set-variable]
           volatile int val = INT_MIN;
                        ^
   lib/test_ubsan.c:42:24: warning: variable 'uval' set but not used [-Wunused-but-set-variable]
           volatile unsigned int uval = UINT_MAX / 2;
                                 ^
   lib/test_ubsan.c:41:15: warning: variable 'val' set but not used [-Wunused-but-set-variable]
           volatile int val = INT_MAX / 2;
                        ^
   lib/test_ubsan.c:61:15: warning: variable 'val' set but not used [-Wunused-but-set-variable]
           volatile int val = 16;
                        ^
>> lib/test_ubsan.c:71:6: warning: variable 'val1' set but not used [-Wunused-but-set-variable]
           int val1 = 10;
               ^
   lib/test_ubsan.c:72:6: warning: variable 'val2' set but not used [-Wunused-but-set-variable]
           int val2 = INT_MAX;
               ^
   lib/test_ubsan.c:107:37: warning: variable 'eptr' set but not used [-Wunused-but-set-variable]
           enum ubsan_test_enum eval, eval2, *eptr;
                                              ^
   lib/test_ubsan.c:106:19: warning: variable 'ptr' set but not used [-Wunused-but-set-variable]
           bool val, val2, *ptr;
                            ^
   lib/test_ubsan.c:130:6: warning: variable 'val' set but not used [-Wunused-but-set-variable]
           int val;
               ^
   lib/test_ubsan.c:150:27: warning: variable 'val2' set but not used [-Wunused-but-set-variable]
           volatile long long *ptr, val2;
                                    ^
>> lib/test_ubsan.c:170:28: warning: unused variable 'skip_ubsan_array' [-Wunused-const-variable]
   static const test_ubsan_fp skip_ubsan_array[] = {
                              ^
   14 warnings generated.


vim +/val1 +71 lib/test_ubsan.c

    67	
    68	static void test_ubsan_shift_out_of_bounds(void)
    69	{
    70		volatile int neg = -1, wrap = 4;
  > 71		int val1 = 10;
    72		int val2 = INT_MAX;
    73	
    74		UBSAN_TEST(CONFIG_UBSAN_SHIFT, "negative exponent");
    75		val1 <<= neg;
    76	
    77		UBSAN_TEST(CONFIG_UBSAN_SHIFT, "left overflow");
    78		val2 <<= wrap;
    79	}
    80	
    81	static void test_ubsan_out_of_bounds(void)
    82	{
    83		volatile int i = 4, j = 5, k = -1;
    84		volatile char above[4] = { }; /* Protect surrounding memory. */
    85		volatile int arr[4];
    86		volatile char below[4] = { }; /* Protect surrounding memory. */
    87	
    88		above[0] = below[0];
    89	
    90		UBSAN_TEST(CONFIG_UBSAN_BOUNDS, "above");
    91		arr[j] = i;
    92	
    93		UBSAN_TEST(CONFIG_UBSAN_BOUNDS, "below");
    94		arr[k] = i;
    95	}
    96	
    97	enum ubsan_test_enum {
    98		UBSAN_TEST_ZERO = 0,
    99		UBSAN_TEST_ONE,
   100		UBSAN_TEST_MAX,
   101	};
   102	
   103	static void test_ubsan_load_invalid_value(void)
   104	{
   105		volatile char *dst, *src;
   106		bool val, val2, *ptr;
   107		enum ubsan_test_enum eval, eval2, *eptr;
   108		unsigned char c = 0xff;
   109	
   110		UBSAN_TEST(CONFIG_UBSAN_BOOL, "bool");
   111		dst = (char *)&val;
   112		src = &c;
   113		*dst = *src;
   114	
   115		ptr = &val2;
   116		val2 = val;
   117	
   118		UBSAN_TEST(CONFIG_UBSAN_ENUM, "enum");
   119		dst = (char *)&eval;
   120		src = &c;
   121		*dst = *src;
   122	
   123		eptr = &eval2;
   124		eval2 = eval;
   125	}
   126	
   127	static void test_ubsan_null_ptr_deref(void)
   128	{
   129		volatile int *ptr = NULL;
   130		int val;
   131	
   132		UBSAN_TEST(CONFIG_UBSAN_OBJECT_SIZE);
   133		val = *ptr;
   134	}
   135	
   136	static void test_ubsan_misaligned_access(void)
   137	{
   138		volatile char arr[5] __aligned(4) = {1, 2, 3, 4, 5};
   139		volatile int *ptr, val = 6;
   140	
   141		UBSAN_TEST(CONFIG_UBSAN_ALIGNMENT);
   142		ptr = (int *)(arr + 1);
   143		*ptr = val;
   144	}
   145	
   146	static void test_ubsan_object_size_mismatch(void)
   147	{
   148		/* "((aligned(8)))" helps this not into be misaligned for ptr-access. */
   149		volatile int val __aligned(8) = 4;
   150		volatile long long *ptr, val2;
   151	
   152		UBSAN_TEST(CONFIG_UBSAN_OBJECT_SIZE);
   153		ptr = (long long *)&val;
   154		val2 = *ptr;
   155	}
   156	
   157	static const test_ubsan_fp test_ubsan_array[] = {
   158		test_ubsan_add_overflow,
   159		test_ubsan_sub_overflow,
   160		test_ubsan_mul_overflow,
   161		test_ubsan_negate_overflow,
   162		test_ubsan_shift_out_of_bounds,
   163		test_ubsan_out_of_bounds,
   164		test_ubsan_load_invalid_value,
   165		test_ubsan_misaligned_access,
   166		test_ubsan_object_size_mismatch,
   167	};
   168	
   169	/* Excluded because they Oops the module. */
 > 170	static const test_ubsan_fp skip_ubsan_array[] = {
   171		test_ubsan_divrem_overflow,
   172		test_ubsan_null_ptr_deref,
   173	};
   174	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 33038 bytes --]

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

end of thread, other threads:[~2021-11-10 19:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-10 19:04 lib/test_ubsan.c:71:6: warning: variable 'val1' set but not used kernel test robot
2021-11-10 19:04 ` kernel test robot

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.