platform_lp64.c revision 1.8
1/*	$NetBSD: platform_lp64.c,v 1.8 2024/03/09 16:47:09 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
12int s32;
13unsigned int u32;
14long sl32;
15unsigned long ul32;
16__int128_t s128;
17__uint128_t u128;
18
19void
20convert_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
30void to_size_t(typeof(sizeof(int)));
31
32void
33convert_unsigned_char_to_size_t(unsigned char uc)
34{
35	/* no warning, unlike platform_int */
36	to_size_t(uc);
37}
38
39void
40convert_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
48char ch;
49
50void
51array_index(void)
52{
53	static char buf[20];
54
55	/* expect+1: warning: array subscript cannot be > 19: 2147483647 [168] */
56	ch += buf[2147483647];
57	/* expect+1: warning: array subscript cannot be > 19: 2147483648 [168] */
58	ch += buf[2147483648];
59	/* expect+1: warning: array subscript cannot be > 19: 2147483648 [168] */
60	ch += buf[0x80000000];
61	/* expect+1: warning: array subscript cannot be > 19: 4294967295 [168] */
62	ch += buf[0xffffffff];
63	/* expect+1: warning: array subscript cannot be negative: -1 [167] */
64	ch += buf[0xffffffffffffffff];
65}
66