xref: /netbsd-src/tests/usr.bin/xlint/lint1/expr_fold_strict_bool.c (revision 6f6b09ef952b87a8258c163a7c779f0a5bb252c4)
1 /*	$NetBSD: expr_fold_strict_bool.c,v 1.3 2024/06/08 09:09:20 rillig Exp $	*/
2 # 3 "expr_fold_strict_bool.c"
3 
4 /*
5  * Test constant folding in strict bool mode.
6  *
7  * In this mode, _Bool is not an unsigned integer type.  In fact, it is not
8  * an arithmetic type at all.
9  */
10 
11 /* lint1-extra-flags: -T */
12 
13 typedef long long int64_t;
14 typedef unsigned long long uint64_t;
15 
16 struct fold_64_bit {
17 
18 	_Bool lt_signed_small_ok: -3LL < 1LL ? 1 : -1;
19 	/* expect+1: error: illegal bit-field size: 255 [36] */
20 	_Bool lt_signed_small_bad: 1LL < -3LL ? 1 : -1;
21 
22 	_Bool lt_signed_big_ok: (int64_t)(1ULL << 63) < 1LL ? 1 : -1;
23 	/* expect+1: error: illegal bit-field size: 255 [36] */
24 	_Bool lt_signed_big_bad: 1LL < (int64_t)(1ULL << 63) ? 1 : -1;
25 
26 	_Bool lt_unsigned_small_ok: 1ULL < 3ULL ? 1 : -1;
27 	/* expect+1: error: illegal bit-field size: 255 [36] */
28 	_Bool lt_unsigned_small_bad: 3ULL < 1ULL ? 1 : -1;
29 
30 	/*
31 	 * Before tree.c 1.345 from 2021-08-22, lint wrongly assumed that the
32 	 * result of all binary operators were the common arithmetic type,
33 	 * but that was wrong for the comparison operators.  The expression
34 	 * '1ULL < 2ULL' does not have type 'unsigned long long' but 'int' in
35 	 * default mode, or '_Bool' in strict bool mode.
36 	 */
37 	_Bool lt_unsigned_big_ok: 1ULL < 1ULL << 63 ? 1 : -1;
38 	/* expect+1: error: illegal bit-field size: 255 [36] */
39 	_Bool lt_unsigned_big_bad: 1ULL << 63 < 1ULL ? 1 : -1;
40 };
41