1 extern void abort (void);
3 /* { dg-options "-O2" } */
5 /* { dg-require-effective-target int32plus } */
7 #define TYPE_MAX(type, sign) \
8 ((!sign) ? ((1 << (sizeof (type) * 8 - 1)) - 1) : \
9 ((1 << (sizeof (type) * 8)) - 1))
10 #define TYPE_MIN(type, sign) \
11 ((!sign) ? -(1 << (sizeof (type) * 8 - 1)) : 0)
13 #define TEST_FN(NAME, ARG_TYPE, RET_TYPE, CAST_TYPE, VAL, VR_MIN, VR_MAX)\
14 __attribute__((noinline, noclone)) RET_TYPE \
15 NAME (ARG_TYPE arg){ \
17 if (arg + 1 < VR_MIN || arg + 1 > VR_MAX) return ret; \
18 /* Value Range of arg at this point will be [VR_min, VR_max]. */\
20 ret = (CAST_TYPE)arg; \
24 /* Signed to signed conversion with value in-range. */
25 TEST_FN (foo1
, short, short, char, 1, TYPE_MIN (char, 0), TYPE_MAX (char, 0));
26 TEST_FN (foo2
, short, short, char, 1, TYPE_MIN (char, 0) + 1,\
27 TYPE_MAX (char, 0) - 1);
29 /* Signed to signed conversion with value not in-range. */
30 TEST_FN (foo3
, short, short, char, -1, TYPE_MIN (short, 0) + 1, 100);
31 TEST_FN (foo4
, short, short, char, 1, 12, TYPE_MAX (short, 0) + 1);
33 /* Unsigned to unsigned conversion with value in-range. */
34 TEST_FN (foo5
, unsigned short, unsigned short, unsigned char, 1,\
35 TYPE_MIN (char, 1) + 1, TYPE_MAX (char, 1) - 1);
36 TEST_FN (foo6
, unsigned short, unsigned short, unsigned char, 1,\
37 TYPE_MIN (char, 1), TYPE_MAX (char, 1));
39 /* Unsigned to unsigned conversion with value not in-range. */
40 TEST_FN (foo7
, unsigned short, unsigned short, unsigned char, 1,\
41 TYPE_MIN (short, 1) + 1, TYPE_MAX (short, 1) - 1);
42 TEST_FN (foo8
, unsigned short, unsigned short, unsigned char, 1,\
43 TYPE_MIN (short, 1), TYPE_MAX (short, 1));
45 /* Signed to unsigned conversion with value range positive. */
46 TEST_FN (foo9
, short, short, unsigned char, -1, 1,\
47 TYPE_MAX (char, 1) - 1);
48 TEST_FN (foo10
, short, short, unsigned char, 1, 0,\
51 /* Signed to unsigned conversion with value range negative. */
52 TEST_FN (foo11
, short, short, unsigned char, 1,\
53 TYPE_MIN (char, 0) + 1, TYPE_MAX (char, 0) - 1);
54 TEST_FN (foo12
, short, short, unsigned char, 1,\
55 TYPE_MIN (char, 0), TYPE_MAX (char, 0));
57 /* Unsigned to Signed conversion with value range in signed equiv range. */
58 TEST_FN (foo13
, unsigned short, unsigned short, char, 1,\
59 TYPE_MIN (char, 1) + 1, TYPE_MAX (char, 0) - 1);
60 TEST_FN (foo14
, unsigned short, unsigned short, char, 1,\
61 TYPE_MIN (char, 1), TYPE_MAX (char, 0));
63 /* Unsigned to Signed conversion with value range not-in signed range. */
64 TEST_FN (foo15
, unsigned short, unsigned short, char, 1,\
65 TYPE_MIN (char, 1) + 1, TYPE_MAX (char, 1) - 1);
66 TEST_FN (foo16
, unsigned short, unsigned short, char, 1,\
67 TYPE_MIN (char, 1), TYPE_MAX (char, 1));
71 /* Signed to signed conversion with value in-range. */
73 if (foo1 (-32) != -31)
79 /* Signed to signed conversion with value not in-range. */
81 if (foo3 (-512) != -513)
84 if (foo4 (512) != 513)
87 /* Unsigned to unsigned conversion with value in-range. */
95 /* Unsigned to unsigned conversion with value not in-range. */
97 if (foo7 (512) != 513)
100 if (foo8 (512) != 513)
103 /* Signed to unsigned conversion with value range positive. */
111 /* Signed to unsigned conversion with value range negative. */
113 if (foo11 (-125) != -124)
116 if (foo12 (-125) != -124)
119 /* Unsigned to Signed conversion with value range in signed equiv range. */
121 if (foo13 (125) != 126)
124 if (foo14 (125) != 126)
127 /* Unsigned to Signed conversion with value range not-in signed range. */
129 if (foo15 (250) != 251)
132 if (foo16 (250) != 251)