Home | History | Annotate | Line # | Download | only in lint1
msg_309.c revision 1.2.2.1
      1 /*	$NetBSD: msg_309.c,v 1.2.2.1 2021/05/31 22:15:24 cjep Exp $	*/
      2 # 3 "msg_309.c"
      3 
      4 // Test for message: extra bits set to 0 in conversion of '%s' to '%s', op '%s' [309]
      5 
      6 int
      7 scale(unsigned long long x) {
      8 
      9 	/*
     10 	 * Both operands of '&' have the same type, therefore no conversion
     11 	 * is necessary and no bits can get lost.
     12 	 */
     13 	if ((x & 0xffffffff00000000ULL) != 0)
     14 		return 32;
     15 
     16 	/*
     17 	 * The constant has type 'unsigned 32-bit'.  The usual arithmetic
     18 	 * conversions of '&' convert this constant to unsigned 64-bit.
     19 	 * The programmer may or may not have intended to sign-extend the
     20 	 * bit mask here.  This situation may occur during migration from a
     21 	 * 32-bit to a 64-bit platform.
     22 	 */
     23 	if ((x & 0xffff0000) != 0)	/* expect: 309 */
     24 		return 16;
     25 
     26 	/*
     27 	 * In the remaining cases, the constant does not have its most
     28 	 * significant bit set, therefore there is no ambiguity.
     29 	 */
     30 	if ((x & 0xff00) != 0)
     31 		return 8;
     32 	if ((x & 0xf0) != 0)
     33 		return 4;
     34 	if ((x & 0xc) != 0)
     35 		return 2;
     36 	if ((x & 0x2) != 0)
     37 		return 1;
     38 	return (int)(x & 0x1);
     39 }
     40