b2101076f9383de72883b68d988b429b807a2a69
1 /* Test for diagnostics for implicit conversions between integer types
2 These tests come from gcc/testsuite/gcc.dg/overflow-warn-2.c */
4 /* { dg-do compile } */
5 /* { dg-options "-std=c99 -fsigned-char -Wconversion" } */
9 void fsc (signed char sc
);
10 void fuc (unsigned char uc
);
11 unsigned fui (unsigned int ui
);
12 void fsi (signed int ui
);
21 uc
= ui
; /* { dg-warning "conversion" } */
22 uc
= si
; /* { dg-warning "conversion" } */
23 sc
= ui
; /* { dg-warning "conversion" } */
24 sc
= si
; /* { dg-warning "conversion" } */
25 fuc (ui
); /* { dg-warning "conversion" } */
26 fuc (si
); /* { dg-warning "conversion" } */
27 fsc (ui
); /* { dg-warning "conversion" } */
28 fsc (si
); /* { dg-warning "conversion" } */
43 uc
= x
? 1U : -1; /* { dg-warning "conversion" } */
44 /* { dg-warning "negative integer implicitly converted to unsigned type" "" { target *-*-* } 43 } */
45 uc
= x
? SCHAR_MIN
: 1U; /* { dg-warning "conversion" } */
46 /* { dg-warning "negative integer implicitly converted to unsigned type" "" { target *-*-* } 45 } */
47 uc
= x
? 1 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
48 uc
= x
? SCHAR_MIN
: 1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
49 ui
= x
? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
50 ui
= x
? INT_MIN
: 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
51 ui
= ui
? SCHAR_MIN
: 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
52 ui
= 1U * -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
53 ui
= ui
+ INT_MIN
; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
54 ui
= x
? 1 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
55 ui
= ui
? SCHAR_MIN
: 1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
57 fuc (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
58 uc
= -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
59 fui (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
60 ui
= -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
61 fuc ('\xa0'); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
62 uc
= '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
63 fui ('\xa0');/* { dg-warning "negative integer implicitly converted to unsigned type" } */
64 ui
= '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
65 fsi (0x80000000); /* { dg-warning "conversion" } */
66 si
= 0x80000000; /* { dg-warning "conversion" } */
69 fsi (UINT_MAX
- 1); /* { dg-warning "conversion" } */
70 si
= UINT_MAX
- 1; /* { dg-warning "conversion" } */
71 fsi (UINT_MAX
- 1U); /* { dg-warning "conversion" } */
72 si
= UINT_MAX
- 1U; /* { dg-warning "conversion" } */
80 uc
= (unsigned char) -1;
84 fsc (uc
); /* { dg-warning "conversion" } */
85 sc
= uc
; /* { dg-warning "conversion" } */
86 fuc (sc
); /* { dg-warning "conversion" } */
87 uc
= sc
; /* { dg-warning "conversion" } */
88 fsi (ui
); /* { dg-warning "conversion" } */
89 si
= ui
; /* { dg-warning "conversion" } */
90 fui (si
); /* { dg-warning "conversion" } */
91 ui
= si
; /* { dg-warning "conversion" } */
92 fui (sc
); /* { dg-warning "conversion" } */
93 ui
= sc
; /* { dg-warning "conversion" } */
96 unsigned fui (unsigned a
) { return a
+ -1; } /* { dg-warning "negative integer implicitly converted to unsigned type" } */