1 /* $NetBSD: platform_lp64.c,v 1.14 2024/03/30 17:12:26 rillig Exp $ */
2 # 3 "platform_lp64.c"
3
4 /*
5 * Test features that only apply to platforms that have 32-bit int and 64-bit
6 * long and pointer types.
7 */
8
9 /* lint1-only-if: lp64 */
10 /* lint1-extra-flags: -c -h -a -p -b -r -z -X 351 */
11
12 int s32;
13 unsigned int u32;
14 long sl32;
15 unsigned long ul32;
16 __int128_t s128;
17 __uint128_t u128;
18
19 void
convert_between_int_and_long(void)20 convert_between_int_and_long(void)
21 {
22 /* expect+1: warning: conversion from 'long' to 'int' may lose accuracy [132] */
23 s32 = sl32;
24 sl32 = s32;
25 /* expect+1: warning: conversion from 'unsigned long' to 'unsigned int' may lose accuracy [132] */
26 u32 = ul32;
27 ul32 = u32;
28 }
29
30 void to_size_t(typeof(sizeof(int)));
31
32 void
convert_unsigned_char_to_size_t(unsigned char uc)33 convert_unsigned_char_to_size_t(unsigned char uc)
34 {
35 /* no warning, unlike platform_int */
36 to_size_t(uc);
37 }
38
39 void
convert_128(void)40 convert_128(void)
41 {
42 /* expect+1: warning: conversion from '__int128_t' to 'int' may lose accuracy [132] */
43 s32 = s128;
44 /* expect+1: warning: conversion from '__uint128_t' to 'unsigned int' may lose accuracy [132] */
45 u32 = u128;
46 }
47
48 unsigned char u8;
49 unsigned long long u64;
50 unsigned char u8_buf[20];
51 unsigned long long u64_buf[20];
52
53 void
array_index(void)54 array_index(void)
55 {
56
57 /* expect+1: warning: array subscript 16777215 cannot be > 19 [168] */
58 u8 += u8_buf[0x00ffffff];
59 /* expect+1: warning: array subscript 2147483647 cannot be > 19 [168] */
60 u8 += u8_buf[0x7fffffff];
61 /* expect+1: warning: array subscript 2147483648 cannot be > 19 [168] */
62 u8 += u8_buf[2147483648];
63 /* expect+1: warning: array subscript 2147483648 cannot be > 19 [168] */
64 u8 += u8_buf[0x80000000];
65 /* expect+1: warning: array subscript 4294967295 cannot be > 19 [168] */
66 u8 += u8_buf[0xffffffff];
67 /* expect+1: warning: array subscript 2147483648 cannot be > 19 [168] */
68 u8 += u8_buf[0x80000000];
69 /* expect+1: warning: array subscript 4294967295 cannot be > 19 [168] */
70 u8 += u8_buf[0xffffffff];
71 /* expect+1: warning: array subscript 72057594037927935 cannot be > 19 [168] */
72 u8 += u8_buf[0x00ffffffffffffff];
73 /* expect+1: warning: array subscript 18446744073709551615 cannot be > 19 [168] */
74 u8 += u8_buf[0xffffffffffffffff];
75
76 /* expect+1: warning: array subscript 16777215 cannot be > 19 [168] */
77 u64 += u64_buf[0x00ffffff];
78 /* expect+1: warning: array subscript 2147483647 cannot be > 19 [168] */
79 u64 += u64_buf[0x7fffffff];
80 /* expect+1: warning: array subscript 2147483648 cannot be > 19 [168] */
81 u64 += u64_buf[2147483648];
82 /* expect+1: warning: array subscript 2147483648 cannot be > 19 [168] */
83 u64 += u64_buf[0x80000000];
84 /* expect+1: warning: array subscript 4294967295 cannot be > 19 [168] */
85 u64 += u64_buf[0xffffffff];
86 /* expect+1: warning: array subscript 2147483648 cannot be > 19 [168] */
87 u64 += u64_buf[0x80000000];
88 /* expect+1: warning: array subscript 4294967295 cannot be > 19 [168] */
89 u64 += u64_buf[0xffffffff];
90 /* expect+1: warning: array subscript 72057594037927935 cannot be > 19 [168] */
91 u64 += u64_buf[0x00ffffffffffffff];
92 /* expect+1: warning: array subscript 1152921504606846975 cannot be > 19 [168] */
93 u64 += u64_buf[0x0fffffffffffffff];
94 /* expect+2: warning: '2305843009213693951 * 8' overflows 'long' [141] */
95 /* expect+1: warning: array subscript 1152921504606846975 cannot be > 19 [168] */
96 u64 += u64_buf[0x1fffffffffffffff];
97 /* expect+2: warning: '4611686018427387903 * 8' overflows 'long' [141] */
98 /* expect+1: warning: array subscript 1152921504606846975 cannot be > 19 [168] */
99 u64 += u64_buf[0x3fffffffffffffff];
100 /* expect+2: warning: '9223372036854775807 * 8' overflows 'long' [141] */
101 /* expect+1: warning: array subscript 1152921504606846975 cannot be > 19 [168] */
102 u64 += u64_buf[0x7fffffffffffffff];
103 /* expect+2: warning: '18446744073709551615 * 8' overflows 'unsigned long' [141] */
104 /* expect+1: warning: array subscript 2305843009213693951 cannot be > 19 [168] */
105 u64 += u64_buf[0xffffffffffffffff];
106 }
107