OSDN Git Service

2009-01-10 Sebastian Pop <sebastian.pop@amd.com>
[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   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" } */
29
30   fsi (si);
31   fui (ui);
32   fsi (uc);
33   si = uc;
34   fui (uc);
35   ui = uc;
36   fui ('A');
37   ui = 'A';
38   fsi ('A');
39   si = 'A';
40   fuc ('A');
41   uc = 'A';
42
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" } */
56
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" } */
67
68
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;
79
80   uc = (unsigned char) -1;
81   ui = -1 * (1 * -1);
82   ui = (unsigned) -1;
83
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" } */
94 }
95
96 unsigned fui (unsigned a) { return a + -1; } /* { dg-warning "negative integer implicitly converted to unsigned type" } */
97
98