builtin-has-attribute-4.c: Skip on 32-bit hppa*-*-hpux*.
[official-gcc.git] / gcc / testsuite / gcc.dg / Wsign-conversion.c
blobb2affd01912a790abaed10cfb1de85163f27b703
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" } */
7 #include <limits.h>
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);
15 void h (int x)
17 unsigned int ui = 3;
18 int si = 3;
19 __INT32_TYPE__ si32 = 3;
20 unsigned char uc = 3;
21 signed char sc = 3;
23 uc = ui;
24 uc = si;
25 sc = ui;
26 sc = si;
27 fuc (ui);
28 fuc (si);
29 fsc (ui);
30 fsc (si);
32 fsi (si);
33 fui (ui);
34 fsi (uc);
35 si = uc;
36 fui (uc);
37 ui = uc;
38 fui ('A');
39 ui = 'A';
40 fsi ('A');
41 si = 'A';
42 fuc ('A');
43 uc = 'A';
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" } */
73 fsi (UINT_MAX/3U);
74 si = UINT_MAX/3U;
75 fsi (UINT_MAX/3);
76 si = UINT_MAX/3;
77 fui (UINT_MAX - 1);
78 ui = UINT_MAX - 1;
80 uc = (unsigned char) -1;
81 ui = -1 * (1 * -1);
82 ui = (unsigned) -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" } */