1 // { dg-do run { target { int32 } } }
2 // { dg-options "-fsanitize=float-cast-overflow" }
3 
4 #define INT_MAX __INT_MAX__
5 #define INT_MIN (-__INT_MAX__ - 1)
6 #define UINT_MAX 2 * (unsigned) __INT_MAX__ + 1
7 
8 struct S
9 {
10   int i:1;
11 } s;
12 
13 struct T
14 {
15   unsigned int i:1;
16 } t;
17 
18 int
main(void)19 main (void)
20 {
21   volatile double d;
22 
23 #define CHECK_BOUNDARY(VAR, VAL)        \
24   (VAR) = (VAL) - 1.5;                  \
25   (VAR) = (VAL) - 1.0;                  \
26   (VAR) = (VAL) - 0.75;                  \
27   (VAR) = (VAL) - 0.5;                  \
28   (VAR) = (VAL) - 0.0000001;            \
29   (VAR) = (VAL) - 0.0;                  \
30   (VAR) = (VAL);                        \
31   (VAR) = (VAL) + 0.0;                  \
32   (VAR) = (VAL) + 0.0000001;            \
33   (VAR) = (VAL) + 0.5;                  \
34   (VAR) = (VAL) + 0.75;                  \
35   (VAR) = (VAL) + 1.0;                  \
36   (VAR) = (VAL) + 1.5;
37 
38   /* Signed bit-field.  (INT_MIN, INT_MAX) is valid.  */
39   d = INT_MIN;
40   CHECK_BOUNDARY (s.i, d);
41   d = 0.0;
42   CHECK_BOUNDARY (s.i, d);
43   d = INT_MAX;
44   CHECK_BOUNDARY (s.i, d);
45 
46   /* Unsigned bit-field.  (0, UINT_MAX) is valid.  */
47   d = UINT_MAX;
48   CHECK_BOUNDARY (t.i, d);
49   d = 0.0;
50   CHECK_BOUNDARY (t.i, d);
51 
52   return 0;
53 }
54 
55 /* { dg-output " -2.14748e\\\+09 is outside the range of representable values of type\[^\n\r]*(\n|\r\n|\r)" } */
56 /* { dg-output "\[^\n\r]* -2.14748e\\\+09 is outside the range of representable values of type\[^\n\r]*(\n|\r\n|\r)" } */
57 /* { dg-output "\[^\n\r]* 2.14748e\\\+09 is outside the range of representable values of type\[^\n\r]*(\n|\r\n|\r)" } */
58 /* { dg-output "\[^\n\r]* 2.14748e\\\+09 is outside the range of representable values of type\[^\n\r]*(\n|\r\n|\r)" } */
59 /* { dg-output "\[^\n\r]* 4.29497e\\\+09 is outside the range of representable values of type\[^\n\r]*(\n|\r\n|\r)" } */
60 /* { dg-output "\[^\n\r]* 4.29497e\\\+09 is outside the range of representable values of type\[^\n\r]*(\n|\r\n|\r)" } */
61 /* { dg-output "\[^\n\r]* -1.5 is outside the range of representable values of type\[^\n\r]*(\n|\r\n|\r)" } */
62 /* { dg-output "\[^\n\r]* -1 is outside the range of representable values of type" } */
63