msg_132_ilp32.c revision 1.3 1 /* $NetBSD: msg_132_ilp32.c,v 1.3 2023/03/28 14:44:34 rillig Exp $ */
2 # 3 "msg_132_ilp32.c"
3
4 // Test for message: conversion from '%s' to '%s' may lose accuracy [132]
5
6 /*
7 * On 32-bit platforms, it is possible to add a 64-bit integer to a 32-bit
8 * pointer. The 64-bit integer is then converted to the ptrdiff_t of the
9 * target platform, which results in the non-obvious conversion from
10 * 'long long' to either 'long' or 'int', depending on the platform's
11 * ptrdiff_t.
12 */
13
14 /* lint1-only-if: ilp32 int */
15 /* lint1-extra-flags: -a -X 351 */
16
17 /*
18 * Seen in usr.bin/make/var.c, function RegexReplace, in the function call
19 * SepBuf_AddBytesBetween(buf, wp + m[0].rm_so, wp + m[0].rm_eo). The
20 * offsets of regular expression matches have type off_t, which is a 64-bit
21 * integer.
22 *
23 * C11 6.5.6p8 does not explicitly define the meaning of a pointer + an
24 * overly long integer, it just says "undefined behavior" if the resulting
25 * pointer would be outside the object.
26 */
27 const char *
28 array_subscript(const char *p, long long idx)
29 {
30 /* expect+1: warning: conversion from 'long long' to 'int' may lose accuracy [132] */
31 return p + idx;
32 }
33
34 /*
35 * On ILP32 platforms, pointer, long and int have the same size, so there is
36 * no loss of accuracy.
37 */
38 unsigned int
39 convert_pointer_to_smaller_integer(void *ptr)
40 {
41 return (unsigned long)(ptr) >> 12;
42 }
43