OSDN Git Service

* gcc.dg/torture/pr26565.c: Expect warning on packed field for
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / Wconversion-integer.c
1 /* Test for diagnostics for implicit conversions between integer types
2    These tests come from gcc/testsuite/gcc.dg/overflow-warn-2.c  */
3
4 /* { dg-do compile } */
5 /* { dg-options "-std=c99 -fsigned-char -Wconversion" } */
6
7 #include <limits.h>
8
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
14 void h (int x)
15 {
16   unsigned int ui = 3;
17   int   si = 3;
18   unsigned char uc = 3;
19   signed char   sc = 3;
20
21   fuc (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
22   uc = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
23   fuc ('\xa0'); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
24   uc = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
25   uc = x ? 1U : -1; /* { dg-warning "conversion" } */
26   /* { dg-warning "negative integer implicitly converted to unsigned type" "" { target *-*-* } 25 } */
27   uc = x ? SCHAR_MIN : 1U; /* { dg-warning "conversion" } */
28   /* { dg-warning "negative integer implicitly converted to unsigned type" "" { target *-*-* } 27 } */
29
30   uc = x ? 1 : -1; /* { dg-warning "conversion" } */
31
32   uc = x ? SCHAR_MIN : 1; /* { dg-warning "conversion" } */
33
34   fuc ('A');
35   uc = 'A';
36   uc = (unsigned char) -1;
37
38   fui (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
39   ui = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
40   ui = x ? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
41   ui = x ? INT_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
42   ui = ui ? SCHAR_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
43   ui = 1U * -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
44   ui = ui + INT_MIN; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
45   ui = x ? 1 : -1; /* { dg-warning "conversion" } */
46   ui = ui ? SCHAR_MIN : 1; /* { dg-warning "conversion" } */
47
48   ui = -1 * (1 * -1);
49   ui = (unsigned) -1;
50
51   fsc (uc); /* { dg-warning "conversion" } */
52   sc = uc;  /* { dg-warning "conversion" } */
53   fuc (sc); /* { dg-warning "conversion" } */
54   uc = sc;  /* { dg-warning "conversion" } */
55   fsi (ui); /* { dg-warning "conversion" } */
56   si = ui;  /* { dg-warning "conversion" } */
57   fui (si); /* { dg-warning "conversion" } */ 
58   ui = si;  /* { dg-warning "conversion" } */ 
59   fui (sc); /* { dg-warning "conversion" } */
60   ui = sc;  /* { dg-warning "conversion" } */
61
62   fui ('\xa0');/* { dg-warning "negative integer implicitly converted to unsigned type" } */
63   ui = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
64
65   fsi (si);
66   fui (ui);
67   fsi (uc);
68   si = uc;
69   fui (uc);
70   ui = uc;
71   fui ('A');
72   ui = 'A';
73   fsi ('A');
74   si = 'A';
75   
76
77   fsi (UINT_MAX - 1);  /* { dg-warning "conversion" } */
78   si = UINT_MAX - 1;   /* { dg-warning "conversion" } */
79   fsi (UINT_MAX - 1U); /* { dg-warning "conversion" } */
80   si = UINT_MAX - 1U;  /* { dg-warning "conversion" } */
81   fsi (UINT_MAX/3U);
82   si = UINT_MAX/3U;
83   fsi (UINT_MAX/3);
84   si = UINT_MAX/3;
85   fui (UINT_MAX - 1);
86   ui = UINT_MAX - 1;
87
88   fsi (0x80000000); /* { dg-warning "conversion" } */
89   si = 0x80000000;  /* { dg-warning "conversion" } */
90 }
91
92
93 unsigned fui (unsigned a) { return a + -1; } /* { dg-warning "negative integer implicitly converted to unsigned type" } */
94
95