]>
Commit | Line | Data |
---|---|---|
7a37fa90 MM |
1 | /* PR c/48956: Test for diagnostics for implicit conversions from complex |
2 | to real types and narrowing conversions of complex types. */ | |
3 | ||
4 | /* Architecture restrictions taken from Wconversion-real-integer.c. | |
5 | Likewise, the magic value 16777217. */ | |
6 | ||
7 | /* { dg-do compile } */ | |
8 | /* { dg-skip-if "doubles are floats,ints are 16bits" { "avr-*-*" } { "*" } { "" } } */ | |
9 | /* { dg-options " -std=c99 -pedantic -Wconversion " } */ | |
10 | /* { dg-require-effective-target int32plus } */ | |
11 | /* { dg-require-effective-target double64plus } */ | |
12 | ||
13 | /* A number which does not fit into float. */ | |
14 | #define MAX_FLOAT_PLUS 16777217. | |
15 | ||
16 | /* Other types could be added, but that won't affect test coverage. */ | |
17 | void ffloatc (float _Complex); | |
18 | void fdoublec (double _Complex); | |
19 | ||
20 | void ffloat (float); | |
21 | void fdouble (double); | |
22 | ||
23 | void fsi (int); | |
24 | void fui (unsigned); | |
25 | ||
26 | float _Complex vfloatc; | |
27 | double _Complex vdoublec; | |
28 | ||
29 | float vfloat; | |
30 | double vdouble; | |
31 | ||
32 | int vsi; | |
33 | unsigned vui; | |
34 | ||
35 | /* Check implicit conversions of complex values to reals. */ | |
36 | void | |
37 | var_complex_to_real (void) | |
38 | { | |
39 | float _Complex floatc = 0.; | |
40 | double _Complex doublec = 0.; | |
41 | ||
42 | ffloatc (floatc); | |
43 | fdoublec (doublec); | |
44 | vfloatc = floatc; | |
45 | vdoublec = doublec; | |
46 | ||
47 | ffloat (floatc); /* { dg-warning "conversion" } */ | |
48 | fdouble (floatc); /* { dg-warning "conversion" } */ | |
49 | vfloat = floatc; /* { dg-warning "conversion" } */ | |
50 | vdouble = floatc; /* { dg-warning "conversion" } */ | |
51 | ||
52 | ffloat (doublec); /* { dg-warning "conversion" } */ | |
53 | fdouble (doublec); /* { dg-warning "conversion" } */ | |
54 | vfloat = doublec; /* { dg-warning "conversion" } */ | |
55 | vdouble = doublec; /* { dg-warning "conversion" } */ | |
56 | } | |
57 | ||
58 | /* Check implicit narrowing conversions of complex values. */ | |
59 | void | |
60 | var_complex_narrowing (void) | |
61 | { | |
62 | float _Complex floatc = 0.; | |
63 | double _Complex doublec = 0.; | |
64 | ||
65 | vdoublec = floatc; | |
66 | vfloatc = doublec; /* { dg-warning "float-conversion" } */ | |
67 | ||
68 | fdoublec (floatc); | |
69 | ffloatc (doublec); /* { dg-warning "float-conversion" } */ | |
70 | } | |
71 | ||
72 | /* Check implicit conversions of complex values to integers. */ | |
73 | void | |
74 | var_complex_to_int (void) | |
75 | { | |
76 | float _Complex floatc = 0.; | |
77 | double _Complex doublec = 0.; | |
78 | ||
79 | fsi (floatc); /* { dg-warning "conversion" } */ | |
80 | fui (floatc); /* { dg-warning "conversion" } */ | |
81 | vsi = floatc; /* { dg-warning "conversion" } */ | |
82 | vui = floatc; /* { dg-warning "conversion" } */ | |
83 | ||
84 | fsi (doublec); /* { dg-warning "conversion" } */ | |
85 | fui (doublec); /* { dg-warning "conversion" } */ | |
86 | vsi = doublec; /* { dg-warning "conversion" } */ | |
87 | vui = doublec; /* { dg-warning "conversion" } */ | |
88 | } | |
89 | ||
90 | /* Check implicit conversion of constant complex values to floats. */ | |
91 | void | |
92 | const_complex_to_real (void) | |
93 | { | |
94 | ffloat (__builtin_complex (0., 1.)); /* { dg-warning "conversion" } */ | |
95 | fdouble (__builtin_complex (0., 1.)); /* { dg-warning "conversion" } */ | |
96 | ||
97 | vfloat = __builtin_complex (0., 1.); /* { dg-warning "conversion" } */ | |
98 | vdouble = __builtin_complex (0., 1.); /* { dg-warning "conversion" } */ | |
99 | ||
100 | vfloat = __builtin_complex (1., 0.) + __builtin_complex (1., 0.); | |
101 | vdouble = __builtin_complex (0., 0.) * __builtin_complex (1., 1.); | |
102 | ffloat (__builtin_complex (1., 0.) + __builtin_complex (1., 0.)); | |
103 | fdouble (__builtin_complex (1., 0.) + __builtin_complex (1., 0.)); | |
104 | ||
105 | vfloat = __builtin_complex (MAX_FLOAT_PLUS, 0.); /* { dg-warning "float-conversion" } */ | |
106 | ffloat (__builtin_complex (MAX_FLOAT_PLUS, 0.)); /* { dg-warning "float-conversion" } */ | |
107 | } | |
108 | ||
109 | /* Check implicit conversion of constant complex values to integers. */ | |
110 | void | |
111 | const_complex_to_int (void) | |
112 | { | |
113 | vsi = __builtin_complex (-1., 0.); | |
114 | vui = __builtin_complex (1., 0.); | |
115 | fsi (__builtin_complex (-1., 0.)); | |
116 | fui (__builtin_complex (1., 0.)); | |
117 | ||
118 | vui = __builtin_complex (-1., 0.); /* { dg-warning "overflow" } */ | |
119 | fui (__builtin_complex (-1., 0.)); /* { dg-warning "overflow" } */ | |
120 | ||
121 | vsi = __builtin_complex (0.5, 0.); /* { dg-warning "float-conversion" } */ | |
122 | fui (__builtin_complex (0.5, 0.)); /* { dg-warning "float-conversion" } */ | |
123 | ||
124 | vsi = __builtin_complex (-0.5, 0.); /* { dg-warning "float-conversion" } */ | |
125 | fui (__builtin_complex (-0.5, 0.)); /* { dg-warning "float-conversion" } */ | |
126 | } | |
127 | ||
128 | /* Check implicit narrowing conversion of constant complex values to. */ | |
129 | void | |
130 | const_complex_narrowing (void) | |
131 | { | |
132 | ffloatc (__builtin_complex (-100., 100.)); | |
133 | ||
134 | ffloatc (__builtin_complex (MAX_FLOAT_PLUS, 0.)); /* { dg-warning "float-conversion" } */ | |
135 | ffloatc (__builtin_complex (0., MAX_FLOAT_PLUS)); /* { dg-warning "float-conversion" } */ | |
136 | ffloatc (__builtin_complex (MAX_FLOAT_PLUS, MAX_FLOAT_PLUS)); /* { dg-warning "float-conversion" } */ | |
137 | } | |
138 |