This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Avoid some left-shifts of negative constants


One group of warnings seen with -Wextra is "left shift of negative
value [-Wshift-negative-value]".  These may be hard to eliminate
completely (some of them involve constants whose type ends up given by
a typedef name, rather than simply int), but it still seems worth
cleaning them up in other cases.  This patch changes two places that
trigger this warning to shift -1U instead of -1.

Tested for x86_64.

2019-02-06  Joseph Myers  <joseph@codesourcery.com>

	* sysdeps/x86/cacheinfo.c (init_cacheinfo): Left-shift -1U instead
	of -1.

diff --git a/sysdeps/x86/cacheinfo.c b/sysdeps/x86/cacheinfo.c
index 02c886c9cd..c179c533a5 100644
--- a/sysdeps/x86/cacheinfo.c
+++ b/sysdeps/x86/cacheinfo.c
@@ -619,7 +619,7 @@ init_cacheinfo (void)
 			      /* Compute count mask.  */
 			      asm ("bsr %1, %0"
 				   : "=r" (count_mask) : "g" (threads_l2));
-			      count_mask = ~(-1 << (count_mask + 1));
+			      count_mask = ~(-1U << (count_mask + 1));
 			      threads_l2 = (shipped - 1) & count_mask;
 			      count &= ~0x1;
 			    }
@@ -636,7 +636,7 @@ init_cacheinfo (void)
 			      /* Compute count mask.  */
 			      asm ("bsr %1, %0"
 				   : "=r" (count_mask) : "g" (threads_core));
-			      count_mask = ~(-1 << (count_mask + 1));
+			      count_mask = ~(-1U << (count_mask + 1));
 			      threads_core = (shipped - 1) & count_mask;
 			      if (level == 2)
 				threads_l2 = threads_core;

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]