1 /* Test for diagnostics for implicit conversions between signed and
2 unsigned integer types.
3 These tests come from gcc/testsuite/gcc.dg/overflow-warn-2.c */
5 /* { dg-do compile } */
6 /* { dg-options "-std=c99 -fsigned-char -Wsign-conversion" } */
9 void fsc (signed char sc
);
10 void fuc (unsigned char uc
);
11 unsigned fui (unsigned int ui
);
12 void fsi (signed int ui
);
13 void fsi32 (__INT32_TYPE__ ui
);
19 __INT32_TYPE__ si32
= 3;
45 uc
= x
? 1U : -1; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value from .-1. to .\[0-9\]+." } */
46 uc
= x
? SCHAR_MIN
: 1U; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value from .-\[0-9\]+. to .\[0-9\]+." } */
47 uc
= x
? 1 : -1; /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes the value of .-1." } */
48 uc
= x
? SCHAR_MIN
: 1; /* { dg-warning "unsigned conversion from .int. to .unsigned char. changes the value of .-\[0-9\]+." } */
49 ui
= x
? 1U : -1; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value from .-1. to .\[0-9\]+." } */
50 ui
= x
? INT_MIN
: 1U; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value from .-\[0-9\]+. to .\[0-9\]+." } */
51 ui
= ui
? SCHAR_MIN
: 1U; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value " } */
52 ui
= 1U * -1; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value " } */
53 ui
= ui
+ INT_MIN
; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes value " } */
54 ui
= x
? 1 : -1; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes the value of .-1." } */
55 ui
= ui
? SCHAR_MIN
: 1; /* { dg-warning "unsigned conversion from .int. to .unsigned int. changes the value of " } */
57 fuc (-1); /* { dg-warning "unsigned conversion" } */
58 uc
= -1; /* { dg-warning "unsigned conversion" } */
59 fui (-1); /* { dg-warning "unsigned conversion" } */
60 ui
= -1; /* { dg-warning "unsigned conversion" } */
61 fuc ('\xa0'); /* { dg-warning "unsigned conversion" } */
62 uc
= '\xa0'; /* { dg-warning "unsigned conversion" } */
63 fui ('\xa0');/* { dg-warning "unsigned conversion" } */
64 ui
= '\xa0'; /* { dg-warning "unsigned conversion" } */
65 fsi32 (0x80000000); /* { dg-warning "signed conversion" } */
66 si32
= 0x80000000; /* { dg-warning "signed 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 "unsigned conversion from .int. to .unsigned int. changes value" } */