blob: 172acb9469db828cb2854e17fd27cefad21c06e0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
/* $NetBSD: lex_integer.c,v 1.11 2023/03/28 14:44:34 rillig Exp $ */
# 3 "lex_integer.c"
/*
* Tests for lexical analysis of integer constants.
*
* C99 6.4.4.1 "Integer constants"
*/
/* lint1-only-if: lp64 */
/* lint1-extra-flags: -X 351 */
long signed_long;
unsigned long long unsigned_long_long_var;
struct s {
int member;
};
/*
* When lint tries to convert the argument to 'struct s', it prints the
* actual type of the argument as a side effect.
*/
void print_type(struct s);
void
no_suffix(void)
{
/* expect+1: ... passing 'int' ... */
print_type(0);
/* The '-' is not part of the constant, it is a unary operator. */
/* expect+1: ... passing 'int' ... */
print_type(-1);
/* expect+1: ... passing 'int' ... */
print_type(2147483647);
/* expect+1: ... passing 'int' ... */
print_type(0x7fffffff);
/* expect+1: ... passing 'int' ... */
print_type(017777777777);
/* expect+1: ... passing 'unsigned int' ... */
print_type(0x80000000);
/* expect+1: ... passing 'unsigned int' ... */
print_type(020000000000);
/* expect+1: ... passing 'unsigned int' ... */
print_type(0xffffffff);
/* expect+1: ... passing 'long' ... */
print_type(2147483648);
/* expect+1: ... passing 'long' ... */
print_type(0x0000000100000000);
/* expect+1: ... passing 'long' ... */
print_type(0x7fffffffffffffff);
/* expect+1: ... passing 'unsigned long' ... */
print_type(0x8000000000000000);
/* expect+1: ... passing 'unsigned long' ... */
print_type(0xffffffffffffffff);
/* expect+2: warning: integer constant out of range [252] */
/* expect+1: ... passing 'unsigned long' ... */
print_type(0x00010000000000000000);
}
void
suffix_u(void)
{
/* expect+1: ... passing 'unsigned int' ... */
print_type(3U);
/* expect+1: ... passing 'unsigned int' ... */
print_type(3u);
/* expect+1: ... passing 'unsigned int' ... */
print_type(4294967295U);
/* expect+1: ... passing 'unsigned long' ... */
print_type(4294967296U);
}
void
suffix_l(void)
{
/* expect+1: ... passing 'long' ... */
print_type(3L);
/* expect+1: ... passing 'long' ... */
print_type(3l);
}
void
suffix_ul(void)
{
/* expect+1: ... passing 'unsigned long' ... */
print_type(3UL);
/* expect+1: ... passing 'unsigned long' ... */
print_type(3LU);
}
void
suffix_ll(void)
{
/* expect+1: ... passing 'long long' ... */
print_type(3LL);
/* The 'Ll' must not use mixed case. Checked by the compiler. */
/* expect+1: ... passing 'long long' ... */
print_type(3Ll);
/* expect+1: ... passing 'long long' ... */
print_type(3ll);
}
void
suffix_ull(void)
{
/* expect+1: ... passing 'unsigned long long' ... */
print_type(3llu);
/* expect+1: ... passing 'unsigned long long' ... */
print_type(3Ull);
/* The 'LL' must not be split. Checked by the compiler. */
/* expect+1: ... passing 'unsigned long long' ... */
print_type(3lul);
/* The 'Ll' must not use mixed case. Checked by the compiler. */
/* expect+1: ... passing 'unsigned long long' ... */
print_type(3ULl);
}
void
suffix_too_many(void)
{
/* expect+2: warning: malformed integer constant [251] */
/* expect+1: ... passing 'long long' ... */
print_type(3LLL);
/* expect+2: warning: malformed integer constant [251] */
/* expect+1: ... passing 'unsigned int' ... */
print_type(3uu);
}
/* https://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html */
void
binary_literal(void)
{
/* This is a GCC extension, but lint doesn't know that. */
/* expect+1: ... passing 'int' ... */
print_type(0b1111000001011010);
/* expect+1: ... passing 'unsigned int' ... */
print_type(0b11110000111100001111000011110000);
}
|