OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [gcc.dg/] [Wsign-conversion.c] - Blame information for rev 318

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 298 jeremybenn
/* 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  */
4
 
5
/* { dg-do compile } */
6
/* { dg-options "-std=c99 -fsigned-char -Wsign-conversion" } */
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;
22
  uc = si;
23
  sc = ui;
24
  sc = si;
25
  fuc (ui);
26
  fuc (si);
27
  fsc (ui);
28
  fsc (si);
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 "negative integer implicitly converted to unsigned type" } */
44
  uc = x ? SCHAR_MIN : 1U;  /* { dg-warning "negative integer implicitly converted to unsigned type" } */
45
  uc = x ? 1 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
46
  uc = x ? SCHAR_MIN : 1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
47
  ui = x ? 1U : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
48
  ui = x ? INT_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
49
  ui = ui ? SCHAR_MIN : 1U; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
50
  ui = 1U * -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
51
  ui = ui + INT_MIN; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
52
  ui = x ? 1 : -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
53
  ui = ui ? SCHAR_MIN : 1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
54
 
55
  fuc (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
56
  uc = -1;  /* { dg-warning "negative integer implicitly converted to unsigned type" } */
57
  fui (-1); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
58
  ui = -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
59
  fuc ('\xa0'); /* { dg-warning "negative integer implicitly converted to unsigned type" } */
60
  uc = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
61
  fui ('\xa0');/* { dg-warning "negative integer implicitly converted to unsigned type" } */
62
  ui = '\xa0'; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
63
  fsi (0x80000000); /* { dg-warning "conversion" } */
64
  si = 0x80000000;  /* { dg-warning "conversion" } */
65
 
66
 
67
  fsi (UINT_MAX - 1);  /* { dg-warning "conversion" } */
68
  si = UINT_MAX - 1;   /* { dg-warning "conversion" } */
69
  fsi (UINT_MAX - 1U); /* { dg-warning "conversion" } */
70
  si = UINT_MAX - 1U;  /* { dg-warning "conversion" } */
71
  fsi (UINT_MAX/3U);
72
  si = UINT_MAX/3U;
73
  fsi (UINT_MAX/3);
74
  si = UINT_MAX/3;
75
  fui (UINT_MAX - 1);
76
  ui = UINT_MAX - 1;
77
 
78
  uc = (unsigned char) -1;
79
  ui = -1 * (1 * -1);
80
  ui = (unsigned) -1;
81
 
82
  fsc (uc); /* { dg-warning "conversion" } */
83
  sc = uc;  /* { dg-warning "conversion" } */
84
  fuc (sc); /* { dg-warning "conversion" } */
85
  uc = sc;  /* { dg-warning "conversion" } */
86
  fsi (ui); /* { dg-warning "conversion" } */
87
  si = ui;  /* { dg-warning "conversion" } */
88
  fui (si); /* { dg-warning "conversion" } */
89
  ui = si;  /* { dg-warning "conversion" } */
90
  fui (sc); /* { dg-warning "conversion" } */
91
  ui = sc;  /* { dg-warning "conversion" } */
92
}
93
 
94
unsigned fui (unsigned a) { return a + -1; } /* { dg-warning "negative integer implicitly converted to unsigned type" } */
95
 
96
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.