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