platform_ilp32_int.c revision 1.4 1 /* $NetBSD: platform_ilp32_int.c,v 1.4 2024/03/09 17:34:01 rillig Exp $ */
2 # 3 "platform_ilp32_int.c"
3
4 /*
5 * Test features that only apply to platforms that have 32-bit int, long and
6 * pointer types and where size_t is unsigned int, not unsigned long.
7 */
8
9 /* lint1-only-if: ilp32 int */
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
17 void
18 convert_between_int_and_long(void)
19 {
20 /*
21 * No warning about possible loss of accuracy, as the types have the
22 * same size, both in target platform mode as well as in portable
23 * mode.
24 */
25 s32 = sl32;
26 sl32 = s32;
27 u32 = ul32;
28 ul32 = u32;
29 }
30
31 unsigned char u8;
32 unsigned long long u64;
33 unsigned char u8_buf[20];
34 unsigned long long u64_buf[20];
35
36 void
37 array_index(void)
38 {
39
40 /* expect+1: warning: array subscript cannot be > 19: 16777215 [168] */
41 u8 += u8_buf[0x00ffffff];
42 /* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */
43 u8 += u8_buf[0x7fffffff];
44 /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
45 /* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
46 u8 += u8_buf[2147483648];
47 /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
48 /* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
49 u8 += u8_buf[0x80000000];
50 /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
51 /* expect+1: warning: array subscript cannot be negative: -1 [167] */
52 u8 += u8_buf[0xffffffff];
53 /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
54 /* expect+1: warning: array subscript cannot be negative: -2147483648 [167] */
55 u8 += u8_buf[0x80000000];
56 /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
57 /* expect+1: warning: array subscript cannot be negative: -1 [167] */
58 u8 += u8_buf[0xffffffff];
59 /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
60 /* expect+1: warning: array subscript cannot be negative: -1 [167] */
61 u8 += u8_buf[0x00ffffffffffffff];
62 /* expect+1: warning: array subscript cannot be negative: -1 [167] */
63 u8 += u8_buf[0xffffffffffffffff];
64
65 /* expect+1: warning: array subscript cannot be > 19: 16777215 [168] */
66 u64 += u64_buf[0x00ffffff];
67 /* expect+2: warning: operator '*' produces integer overflow [141] */
68 /* expect+1: warning: array subscript cannot be negative: -1 [167] */
69 u64 += u64_buf[0x7fffffff];
70 /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
71 /* expect+1: warning: operator '*' produces integer overflow [141] */
72 u64 += u64_buf[2147483648];
73 /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
74 /* expect+1: warning: operator '*' produces integer overflow [141] */
75 u64 += u64_buf[0x80000000];
76 /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
77 /* expect+1: warning: array subscript cannot be negative: -1 [167] */
78 u64 += u64_buf[0xffffffff];
79 /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
80 /* expect+1: warning: operator '*' produces integer overflow [141] */
81 u64 += u64_buf[0x80000000];
82 /* expect+2: warning: conversion of 'unsigned int' to 'int' is out of range [119] */
83 /* expect+1: warning: array subscript cannot be negative: -1 [167] */
84 u64 += u64_buf[0xffffffff];
85 /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
86 /* expect+1: warning: array subscript cannot be negative: -1 [167] */
87 u64 += u64_buf[0x00ffffffffffffff];
88 /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
89 /* expect+1: warning: array subscript cannot be negative: -1 [167] */
90 u64 += u64_buf[0x0fffffffffffffff];
91 /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
92 /* expect+1: warning: array subscript cannot be negative: -1 [167] */
93 u64 += u64_buf[0x1fffffffffffffff];
94 /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
95 /* expect+1: warning: array subscript cannot be negative: -1 [167] */
96 u64 += u64_buf[0x3fffffffffffffff];
97 /* expect+2: warning: conversion of 'long long' to 'int' is out of range [119] */
98 /* expect+1: warning: array subscript cannot be negative: -1 [167] */
99 u64 += u64_buf[0x7fffffffffffffff];
100 /* expect+1: warning: array subscript cannot be negative: -1 [167] */
101 u64 += u64_buf[0xffffffffffffffff];
102 }
103