Home | History | Annotate | Line # | Download | only in lint1
msg_259_c90.c revision 1.1
      1  1.1  rillig /*	$NetBSD: msg_259_c90.c,v 1.1 2021/08/31 18:59:26 rillig Exp $	*/
      2  1.1  rillig # 3 "msg_259_c90.c"
      3  1.1  rillig 
      4  1.1  rillig /* Test for message: argument #%d is converted from '%s' to '%s' due to prototype [259] */
      5  1.1  rillig 
      6  1.1  rillig /* lint1-only-if: lp64 */
      7  1.1  rillig /* XXX: The flag '-s' suppresses all warnings.  Why? */
      8  1.1  rillig /* lint1-flags: -h -w */
      9  1.1  rillig 
     10  1.1  rillig void plain_char(char);
     11  1.1  rillig void signed_int(int);
     12  1.1  rillig void unsigned_int(unsigned int);
     13  1.1  rillig void signed_long(long);
     14  1.1  rillig void unsigned_long(unsigned long);
     15  1.1  rillig /* No 'long long' since it requires C99. */
     16  1.1  rillig 
     17  1.1  rillig void
     18  1.1  rillig change_in_type_width(char c, int i, long l)
     19  1.1  rillig {
     20  1.1  rillig 	plain_char(c);
     21  1.1  rillig 	signed_int(c);
     22  1.1  rillig 	/* No warning 259 on LP64, only on ILP32 */
     23  1.1  rillig 	signed_long(c);
     24  1.1  rillig 
     25  1.1  rillig 	plain_char(i);		/* XXX: why no warning? */
     26  1.1  rillig 	signed_int(i);
     27  1.1  rillig 	/* No warning 259 on LP64, only on ILP32 */
     28  1.1  rillig 	signed_long(i);
     29  1.1  rillig 
     30  1.1  rillig 	plain_char(l);		/* XXX: why no warning? */
     31  1.1  rillig 	/* expect+1: from 'long' to 'int' due to prototype [259] */
     32  1.1  rillig 	signed_int(l);
     33  1.1  rillig 	signed_long(l);
     34  1.1  rillig }
     35  1.1  rillig 
     36  1.1  rillig /*
     37  1.1  rillig  * Converting a signed integer type to its corresponding unsigned integer
     38  1.1  rillig  * type (C99 6.2.5p6) is usually not a problem since the actual values of the
     39  1.1  rillig  * expressions are usually not anywhere near the maximum signed value.  From
     40  1.1  rillig  * a technical standpoint, it is correct to warn here since even small
     41  1.1  rillig  * negative numbers may result in very large positive numbers.
     42  1.1  rillig  *
     43  1.1  rillig  * A common case where it occurs is when the difference of two pointers is
     44  1.1  rillig  * converted to size_t.  The type ptrdiff_t is defined to be signed, but in
     45  1.1  rillig  * many practical cases, the expression is '(end - start)', which makes the
     46  1.1  rillig  * resulting value necessarily positive.
     47  1.1  rillig  */
     48  1.1  rillig void
     49  1.1  rillig signed_to_unsigned(int si, long sl)
     50  1.1  rillig {
     51  1.1  rillig 	/* expect+1: warning: argument #1 is converted from 'int' to 'unsigned int' due to prototype [259] */
     52  1.1  rillig 	unsigned_int(si);
     53  1.1  rillig 
     54  1.1  rillig 	/* expect+1: warning: argument #1 is converted from 'long' to 'unsigned int' due to prototype [259] */
     55  1.1  rillig 	unsigned_int(sl);
     56  1.1  rillig 
     57  1.1  rillig 	/*
     58  1.1  rillig 	 * XXX: Why no warning?  Even though 'unsigned long' is 64 bits
     59  1.1  rillig 	 * wide, it cannot represent negative 32-bit values.
     60  1.1  rillig 	 */
     61  1.1  rillig 	unsigned_long(si);
     62  1.1  rillig 
     63  1.1  rillig 	/* expect+1: warning: argument #1 is converted from 'long' to 'unsigned long' due to prototype [259] */
     64  1.1  rillig 	unsigned_long(sl);
     65  1.1  rillig }
     66  1.1  rillig 
     67  1.1  rillig void
     68  1.1  rillig unsigned_to_signed(unsigned int ui, unsigned long ul)
     69  1.1  rillig {
     70  1.1  rillig 	/* expect+1: warning: argument #1 is converted from 'unsigned int' to 'int' due to prototype [259] */
     71  1.1  rillig 	signed_int(ui);
     72  1.1  rillig 	/* expect+1: warning: argument #1 is converted from 'unsigned long' to 'int' due to prototype [259] */
     73  1.1  rillig 	signed_int(ul);
     74  1.1  rillig 	signed_long(ui);
     75  1.1  rillig 	/* expect+1: warning: argument #1 is converted from 'unsigned long' to 'long' due to prototype [259] */
     76  1.1  rillig 	signed_long(ul);
     77  1.1  rillig }
     78  1.1  rillig 
     79  1.1  rillig void
     80  1.1  rillig signed_to_signed(signed int si, signed long sl)
     81  1.1  rillig {
     82  1.1  rillig 	signed_int(si);
     83  1.1  rillig 	/* expect+1: warning: argument #1 is converted from 'long' to 'int' due to prototype [259] */
     84  1.1  rillig 	signed_int(sl);
     85  1.1  rillig 	signed_long(si);
     86  1.1  rillig 	signed_long(sl);
     87  1.1  rillig }
     88  1.1  rillig 
     89  1.1  rillig void
     90  1.1  rillig unsigned_to_unsigned(unsigned int ui, unsigned long ul)
     91  1.1  rillig {
     92  1.1  rillig 	unsigned_int(ui);
     93  1.1  rillig 	/* expect+1: warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] */
     94  1.1  rillig 	unsigned_int(ul);
     95  1.1  rillig 	unsigned_long(ui);
     96  1.1  rillig 	unsigned_long(ul);
     97  1.1  rillig }
     98  1.1  rillig 
     99  1.1  rillig void
    100  1.1  rillig pass_sizeof_as_smaller_type(void)
    101  1.1  rillig {
    102  1.1  rillig 	/*
    103  1.1  rillig 	 * XXX: Even though the expression has type size_t, it has a constant
    104  1.1  rillig 	 * value that fits effortless into an 'unsigned int', it's so small
    105  1.1  rillig 	 * that it would even fit into a 3-bit bit-field, so lint should not
    106  1.1  rillig 	 * warn here.
    107  1.1  rillig 	 */
    108  1.1  rillig 	/* expect+1: warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] */
    109  1.1  rillig 	unsigned_int(sizeof(int));
    110  1.1  rillig }
    111