2018-11-28 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / Wconversion-real-integer.c
blob92e6987d9ec3c2884c1d1105a94dcafc9cdff787
1 /* Test for diagnostics for Wconversion between floating-point and
2 integers. */
4 /* { dg-do compile } */
5 /* { dg-skip-if "doubles are floats,ints are 16bits" { "avr-*-*" } } */
6 /* { dg-options "-std=c99 -Wconversion" } */
7 /* { dg-require-effective-target int32plus } */
8 /* { dg-require-effective-target double64plus } */
9 #include <limits.h>
11 void fsi (signed int x);
12 void fui (unsigned int x);
13 void ffloat (float x);
14 void fdouble (double x);
16 float vfloat;
17 double vdouble;
19 void h (void)
21 unsigned int ui = 3;
22 int si = 3;
23 unsigned char uc = 3;
24 signed char sc = 3;
25 float f = 3;
26 double d = 3;
28 fsi (3.1f); /* { dg-warning "conversion" } */
29 si = 3.1f; /* { dg-warning "conversion" } */
30 fsi (3.1); /* { dg-warning "conversion" } */
31 si = 3.1; /* { dg-warning "conversion" } */
32 fsi (d); /* { dg-warning "conversion" } */
33 si = d; /* { dg-warning "conversion" } */
34 fui (-1.0); /* { dg-warning "overflow" } */
35 ui = -1.0; /* { dg-warning "overflow" } */
36 ffloat (INT_MAX); /* { dg-warning "conversion" } */
37 vfloat = INT_MAX; /* { dg-warning "conversion" } */
38 ffloat (16777217); /* { dg-warning "conversion" } */
39 vfloat = 16777217; /* { dg-warning "conversion" } */
40 ffloat (si); /* { dg-warning "conversion" } */
41 vfloat = si; /* { dg-warning "conversion" } */
42 ffloat (ui); /* { dg-warning "conversion" } */
43 vfloat = ui; /* { dg-warning "conversion" } */
45 fsi (3);
46 si = 3;
47 fsi (3.0f);
48 si = 3.0f;
49 fsi (3.0);
50 si = 3.0;
51 fsi (16777217.0f);
52 si = 16777217.0f;
53 fsi ((int) 3.1);
54 si = (int) 3.1;
55 ffloat (3U);
56 vfloat = 3U;
57 ffloat (3);
58 vfloat = 3;
59 ffloat (INT_MIN);
60 vfloat = INT_MIN;
61 ffloat (uc);
62 vfloat = uc;
63 ffloat (sc);
64 vfloat = sc;
66 fdouble (UINT_MAX);
67 vdouble = UINT_MAX;
68 fdouble (ui);
69 vdouble = ui;
70 fdouble (si);
71 vdouble = si;
75 void fss (signed short x);
76 void fus (unsigned short x);
77 void fsc (signed char x);
78 void fuc (unsigned char x);
80 void h2 (void)
82 unsigned short int us;
83 short int ss;
84 unsigned char uc;
85 signed char sc;
87 fss (4294967294.0); /* { dg-warning "conversion" } */
88 ss = 4294967294.0; /* { dg-warning "conversion" } */
89 fss (-4294967294.0); /* { dg-warning "conversion" } */
90 ss = -4294967294.0; /* { dg-warning "conversion" } */
91 fus (4294967294.0); /* { dg-warning "conversion" } */
92 us = 4294967294.0; /* { dg-warning "conversion" } */
93 fus (-4294967294.0); /* { dg-warning "conversion" } */
94 us = -4294967294.0; /* { dg-warning "conversion" } */
96 fsc (500.0); /* { dg-warning "conversion" } */
97 sc = 500.0; /* { dg-warning "conversion" } */
98 fsc (-500.0); /* { dg-warning "conversion" } */
99 sc = -500.0; /* { dg-warning "conversion" } */
100 fuc (500.0); /* { dg-warning "conversion" } */
101 uc = 500.0; /* { dg-warning "conversion" } */
102 fuc (-500.0); /* { dg-warning "conversion" } */
103 uc = -500.0; /* { dg-warning "conversion" } */
105 fss (500.0);
106 ss = 500.0;
107 fss (-500.0);
108 ss = -500.0;
109 fus (500.0);
110 us = 500.0;
111 fus (-500.0); /* { dg-warning "conversion" } */
112 us = -500.0; /* { dg-warning "conversion" } */