Home | History | Annotate | Line # | Download | only in lint1
      1 /*	$NetBSD: platform_lp64.c,v 1.19 2025/05/15 21:35: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
     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
     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
     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
     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 
    108 extern const unsigned short *_ctype_tab_;
    109 
    110 int
    111 msg_341(void)
    112 {
    113 	// https://mail-index.netbsd.org/current-users/2024/12/15/msg045888.html
    114 	/* expect+1: warning: argument to 'function from <ctype.h>' must be 'unsigned char' or EOF, not 'unsigned int' [341] */
    115 	return (((int)((_ctype_tab_ + 1)[(0xffffffffu)])));
    116 
    117 }
    118 
    119 void
    120 msg_122(void)
    121 {
    122 	typedef unsigned typedef_type_identifier;
    123 	__attribute__((__mode__(TI))) typedef unsigned attr_typedef_type_identifier;
    124 	typedef __attribute__((__mode__(TI))) unsigned typedef_attr_type_identifier;
    125 	typedef unsigned __attribute__((__mode__(TI))) typedef_type_attr_identifier;
    126 	typedef unsigned typedef_type_identifier_attr __attribute__((__mode__(TI)));
    127 	__attribute__(()) __attribute__((__mode__(TI))) typedef unsigned attr_attr_typedef_type_identifier;
    128 	typedef __attribute__(()) __attribute__((__mode__(TI))) unsigned typedef_attr_attr_type_identifier;
    129 	typedef unsigned __attribute__(()) __attribute__((__mode__(TI))) typedef_type_attr_attr_identifier;
    130 	typedef unsigned typedef_type_identifier_attr_attr __attribute__(()) __attribute__((__mode__(TI)));
    131 
    132 	struct {
    133 		typedef_type_identifier typedef_type_identifier;
    134 		attr_typedef_type_identifier attr_typedef_type_identifier;
    135 		typedef_attr_type_identifier typedef_attr_type_identifier;
    136 		typedef_type_attr_identifier typedef_type_attr_identifier;
    137 		typedef_type_identifier_attr typedef_type_identifier_attr;
    138 		attr_attr_typedef_type_identifier attr_attr_typedef_type_identifier;
    139 		typedef_attr_attr_type_identifier typedef_attr_attr_type_identifier;
    140 		typedef_type_attr_attr_identifier typedef_type_attr_attr_identifier;
    141 		typedef_type_identifier_attr_attr typedef_type_identifier_attr_attr;
    142 	} s = {0};
    143 
    144 	/* expect+1: warning: shift amount 80 is greater than bit-size 32 of 'unsigned int' [122] */
    145 	u128 = s.typedef_type_identifier << 80;
    146 	u128 = s.attr_typedef_type_identifier << 80;
    147 	u128 = s.typedef_attr_type_identifier << 80;
    148 	u128 = s.typedef_type_attr_identifier << 80;
    149 	u128 = s.typedef_type_identifier_attr << 80;
    150 	u128 = s.attr_attr_typedef_type_identifier << 80;
    151 	u128 = s.typedef_attr_attr_type_identifier << 80;
    152 	u128 = s.typedef_type_attr_attr_identifier << 80;
    153 	u128 = s.typedef_type_identifier_attr_attr << 80;
    154 
    155 	unsigned type_identifier = 0;
    156 	__attribute__((__mode__(TI))) unsigned attr_type_identifier = 0;
    157 	unsigned __attribute__((__mode__(TI))) type_attr_identifier = 0;
    158 	unsigned type_identifier_attr __attribute__((__mode__(TI))) = 0;
    159 	__attribute__(()) __attribute__((__mode__(TI))) unsigned attr_attr_type_identifier = 0;
    160 	unsigned __attribute__(()) __attribute__((__mode__(TI))) type_attr_attr_identifier = 0;
    161 	unsigned type_identifier_attr_attr __attribute__(()) __attribute__((__mode__(TI))) = 0;
    162 
    163 	/* expect+1: warning: shift amount 80 is greater than bit-size 32 of 'unsigned int' [122] */
    164 	u128 = type_identifier << 80;
    165 	u128 = attr_type_identifier << 80;
    166 	u128 = type_attr_identifier << 80;
    167 	u128 = type_identifier_attr << 80;
    168 	u128 = attr_attr_type_identifier << 80;
    169 	u128 = type_attr_attr_identifier << 80;
    170 	u128 = type_identifier_attr_attr << 80;
    171 }
    172