xref: /netbsd-src/tests/usr.bin/xlint/lint1/msg_222.c (revision 55af3de5d6aae79d43264ad456343f62ae29bbec)
1*55af3de5Srillig /*	$NetBSD: msg_222.c,v 1.8 2024/12/15 07:43:53 rillig Exp $	*/
2a0a15c14Srillig # 3 "msg_222.c"
3a0a15c14Srillig 
498412b50Srillig // Test for message: conversion of negative constant %lld to unsigned type '%s' [222]
5*55af3de5Srillig //
6*55af3de5Srillig // See also:
7*55af3de5Srillig //	msg_162.c: comparison of unsigned type with negative constant
8*55af3de5Srillig //	msg_164.c: assignment of negative constant to unsigned type
9*55af3de5Srillig //	msg_221.c: initialization of unsigned type with negative constant
10*55af3de5Srillig //	msg_296.c: conversion of negative constant to unsigned type in call
11a0a15c14Srillig 
12b2baa501Srillig /* lint1-extra-flags: -X 351 */
13b2baa501Srillig 
14*55af3de5Srillig unsigned int u32;
15*55af3de5Srillig signed char sc;
16*55af3de5Srillig unsigned char uc;
17*55af3de5Srillig _Bool b;
18e593d312Srillig 
19e593d312Srillig 
20e593d312Srillig void
21*55af3de5Srillig convert_negative_constant(void)
22e593d312Srillig {
23*55af3de5Srillig 	u32 = !-8;
24*55af3de5Srillig 	u32 = ~-8;
25*55af3de5Srillig 	/* expect+1: warning: assignment of negative constant -8 to unsigned type 'unsigned int' [164] */
26*55af3de5Srillig 	u32 = +-8;
27*55af3de5Srillig 	u32 = - -8;
28e593d312Srillig 
29*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
30*55af3de5Srillig 	u32 = u32 * -8;
31*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
32*55af3de5Srillig 	u32 = -8 * u32;
33*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
34*55af3de5Srillig 	u32 = u32 / -8;
35*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
36*55af3de5Srillig 	u32 = -8 / u32;
37*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
38*55af3de5Srillig 	u32 = u32 % -8;
39*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
40*55af3de5Srillig 	u32 = -8 / u32;
41*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
42*55af3de5Srillig 	u32 = u32 + -8;
43*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
44*55af3de5Srillig 	u32 = -8 + u32;
45*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
46*55af3de5Srillig 	u32 = u32 - -8;
47*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
48*55af3de5Srillig 	u32 = -8 - u32;
49*55af3de5Srillig 	/* expect+1: warning: negative shift [121] */
50*55af3de5Srillig 	u32 = u32 << -8;
51*55af3de5Srillig 	u32 = -8 << u32;
52*55af3de5Srillig 	/* expect+1: warning: negative shift [121] */
53*55af3de5Srillig 	u32 = u32 >> -8;
54*55af3de5Srillig 	u32 = -8 >> u32;
55e593d312Srillig 
5640a9b8fdSrillig 	/* expect+1: warning: operator '<' compares 'unsigned int' with 'negative constant' [162] */
57*55af3de5Srillig 	b = u32 < -8;
58*55af3de5Srillig 	/* expect+1: warning: operator '<=' compares 'unsigned int' with 'negative constant' [162] */
59*55af3de5Srillig 	b = u32 <= -8;
60*55af3de5Srillig 	/* expect+1: warning: operator '>' compares 'unsigned int' with 'negative constant' [162] */
61*55af3de5Srillig 	b = u32 > -8;
62*55af3de5Srillig 	/* expect+1: warning: operator '>=' compares 'unsigned int' with 'negative constant' [162] */
63*55af3de5Srillig 	b = u32 >= -8;
64*55af3de5Srillig 	/* expect+1: warning: operator '==' compares 'unsigned int' with 'negative constant' [162] */
65*55af3de5Srillig 	b = u32 == -8;
66*55af3de5Srillig 	/* expect+1: warning: operator '!=' compares 'unsigned int' with 'negative constant' [162] */
67*55af3de5Srillig 	b = u32 != -8;
68e593d312Srillig 
69*55af3de5Srillig 	u32 = u32 & -8;
70*55af3de5Srillig 	u32 = u32 ^ -8;
71*55af3de5Srillig 	u32 = u32 | -8;
72*55af3de5Srillig 	b = u32 && -8;
73*55af3de5Srillig 	b = u32 || -8;
74e593d312Srillig 
75*55af3de5Srillig 	/* expect+1: warning: assignment of negative constant -8 to unsigned type 'unsigned int' [164] */
76*55af3de5Srillig 	u32 = -8;
77*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
78*55af3de5Srillig 	u32 *= -8;
79*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
80*55af3de5Srillig 	u32 /= -8;
81*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
82*55af3de5Srillig 	u32 %= -8;
83*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
84*55af3de5Srillig 	u32 += -8;
85*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
86*55af3de5Srillig 	u32 -= -8;
87*55af3de5Srillig 	// XXX: missing 'negative shift' warning
88*55af3de5Srillig 	u32 <<= -8;
89*55af3de5Srillig 	// XXX: missing 'negative shift' warning
90*55af3de5Srillig 	u32 >>= -8;
91*55af3de5Srillig 	u32 &= -8;
92*55af3de5Srillig 	/* expect+1: warning: conversion of negative constant -8 to unsigned type 'unsigned int' [222] */
93*55af3de5Srillig 	u32 ^= -8;
94*55af3de5Srillig 	u32 |= -8;
95c589f548Srillig 
96*55af3de5Srillig 	sc += 'A' - 'a';
97*55af3de5Srillig 	sc -= 'A' - 'a';
98c589f548Srillig 
99c589f548Srillig 	// XXX: It's perfectly fine to effectively subtract a constant from
100c589f548Srillig 	// XXX: an unsigned type.
101c589f548Srillig 	/* expect+1: warning: conversion of negative constant -32 to unsigned type 'unsigned char' [222] */
102*55af3de5Srillig 	uc += 'A' - 'a';
103c589f548Srillig 	/* expect+1: warning: conversion of negative constant -32 to unsigned type 'unsigned char' [222] */
104*55af3de5Srillig 	uc -= 'A' - 'a';
105e593d312Srillig }
106