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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [gcc.dg/] [overflow-warn-4.c] - Diff between revs 154 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
/* Test for diagnostics for constant overflow.  Test with -pedantic-errors.  */
/* Test for diagnostics for constant overflow.  Test with -pedantic-errors.  */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* Origin: Joseph Myers <joseph@codesourcery.com> */
/* { dg-do compile } */
/* { dg-do compile } */
/* { dg-options "-std=c99 -pedantic-errors" } */
/* { dg-options "-std=c99 -pedantic-errors" } */
 
 
#include <limits.h>
#include <limits.h>
 
 
enum e {
enum e {
  E0 = INT_MAX,
  E0 = INT_MAX,
  /* Unsigned overflow wraps around.  */
  /* Unsigned overflow wraps around.  */
  E1 = UINT_MAX + 1,
  E1 = UINT_MAX + 1,
  /* Overflow in an unevaluated part of an expression is OK (example
  /* Overflow in an unevaluated part of an expression is OK (example
     in the standard).  */
     in the standard).  */
  E2 = 2 || 1 / 0,
  E2 = 2 || 1 / 0,
  E3 = 1 / 0, /* { dg-warning "warning: division by zero" } */
  E3 = 1 / 0, /* { dg-warning "warning: division by zero" } */
  /* { dg-error "error: enumerator value for 'E3' is not an integer constant" "enum error" { target *-*-* } 15 } */
  /* { dg-error "error: enumerator value for 'E3' is not an integer constant" "enum error" { target *-*-* } 15 } */
  /* But as in DR#031, the 1/0 in an evaluated subexpression means the
  /* But as in DR#031, the 1/0 in an evaluated subexpression means the
     whole expression violates the constraints.  */
     whole expression violates the constraints.  */
  E4 = 0 * (1 / 0), /* { dg-warning "warning: division by zero" } */
  E4 = 0 * (1 / 0), /* { dg-warning "warning: division by zero" } */
  /* { dg-error "error: enumerator value for 'E4' is not an integer constant" "enum error" { xfail *-*-* } 19 } */
  /* { dg-error "error: enumerator value for 'E4' is not an integer constant" "enum error" { xfail *-*-* } 19 } */
  E5 = INT_MAX + 1, /* { dg-warning "warning: integer overflow in expression" } */
  E5 = INT_MAX + 1, /* { dg-warning "warning: integer overflow in expression" } */
  /* { dg-error "error: overflow in constant expression" "constant" { target *-*-* } 21 } */
  /* { dg-error "error: overflow in constant expression" "constant" { target *-*-* } 21 } */
  /* Again, overflow in evaluated subexpression.  */
  /* Again, overflow in evaluated subexpression.  */
  E6 = 0 * (INT_MAX + 1), /* { dg-warning "warning: integer overflow in expression" } */
  E6 = 0 * (INT_MAX + 1), /* { dg-warning "warning: integer overflow in expression" } */
  /* { dg-error "error: overflow in constant expression" "constant" { target *-*-* } 24 } */
  /* { dg-error "error: overflow in constant expression" "constant" { target *-*-* } 24 } */
  /* A cast does not constitute overflow in conversion.  */
  /* A cast does not constitute overflow in conversion.  */
  E7 = (char) INT_MAX
  E7 = (char) INT_MAX
};
};
 
 
struct s {
struct s {
  int a;
  int a;
  int : 0 * (1 / 0); /* { dg-warning "warning: division by zero" } */
  int : 0 * (1 / 0); /* { dg-warning "warning: division by zero" } */
  int : 0 * (INT_MAX + 1); /* { dg-warning "warning: integer overflow in expression" } */
  int : 0 * (INT_MAX + 1); /* { dg-warning "warning: integer overflow in expression" } */
  /* { dg-error "error: overflow in constant expression" "constant" { target *-*-* } 33 } */
  /* { dg-error "error: overflow in constant expression" "constant" { target *-*-* } 33 } */
};
};
 
 
void
void
f (void)
f (void)
{
{
  /* This expression is not required to be a constant expression, so
  /* This expression is not required to be a constant expression, so
     it should just involve undefined behavior at runtime.  */
     it should just involve undefined behavior at runtime.  */
  int c = INT_MAX + 1; /* { dg-warning "warning: integer overflow in expression" } */
  int c = INT_MAX + 1; /* { dg-warning "warning: integer overflow in expression" } */
  /* { dg-bogus "error: overflow in constant expression" "constant" { xfail *-*-* } 42 } */
  /* { dg-bogus "error: overflow in constant expression" "constant" { xfail *-*-* } 42 } */
}
}
 
 
/* But this expression does need to be constant.  */
/* But this expression does need to be constant.  */
static int sc = INT_MAX + 1; /* { dg-warning "warning: integer overflow in expression" } */
static int sc = INT_MAX + 1; /* { dg-warning "warning: integer overflow in expression" } */
/* { dg-error "error: overflow in constant expression" "constant" { target *-*-* } 47 } */
/* { dg-error "error: overflow in constant expression" "constant" { target *-*-* } 47 } */
 
 
/* The first two of these involve overflow, so are not null pointer
/* The first two of these involve overflow, so are not null pointer
   constants.  The third has the overflow in an unevaluated
   constants.  The third has the overflow in an unevaluated
   subexpression, so is a null pointer constant.  */
   subexpression, so is a null pointer constant.  */
void *p = 0 * (INT_MAX + 1); /* { dg-warning "warning: integer overflow in expression" } */
void *p = 0 * (INT_MAX + 1); /* { dg-warning "warning: integer overflow in expression" } */
/* { dg-error "error: overflow in constant expression" "constant" { target *-*-* } 53 } */
/* { dg-error "error: overflow in constant expression" "constant" { target *-*-* } 53 } */
/* { dg-error "error: initialization makes pointer from integer without a cast" "null" { target *-*-* } 53 } */
/* { dg-error "error: initialization makes pointer from integer without a cast" "null" { target *-*-* } 53 } */
void *q = 0 * (1 / 0); /* { dg-warning "warning: division by zero" } */
void *q = 0 * (1 / 0); /* { dg-warning "warning: division by zero" } */
/* { dg-error "error: initialization makes pointer from integer without a cast" "null" { xfail *-*-* } 56 } */
/* { dg-error "error: initialization makes pointer from integer without a cast" "null" { xfail *-*-* } 56 } */
void *r = (1 ? 0 : INT_MAX+1);
void *r = (1 ? 0 : INT_MAX+1);
 
 
void
void
g (int i)
g (int i)
{
{
  switch (i)
  switch (i)
    {
    {
    case 0 * (1/0): /* { dg-warning "warning: division by zero" } */
    case 0 * (1/0): /* { dg-warning "warning: division by zero" } */
      ;
      ;
    case 1 + 0 * (INT_MAX + 1): /* { dg-warning "warning: integer overflow in expression" } */
    case 1 + 0 * (INT_MAX + 1): /* { dg-warning "warning: integer overflow in expression" } */
      /* { dg-error "error: overflow in constant expression" "constant" { target *-*-* } 67 } */
      /* { dg-error "error: overflow in constant expression" "constant" { target *-*-* } 67 } */
      ;
      ;
    }
    }
}
}
 
 
int
int
h (void)
h (void)
{
{
  return INT_MAX + 1; /* { dg-warning "warning: integer overflow in expression" } */
  return INT_MAX + 1; /* { dg-warning "warning: integer overflow in expression" } */
}
}
 
 
int
int
h1 (void)
h1 (void)
{
{
  return INT_MAX + 1 - INT_MAX; /* { dg-warning "warning: integer overflow in expression" } */
  return INT_MAX + 1 - INT_MAX; /* { dg-warning "warning: integer overflow in expression" } */
}
}
 
 
void fuc (unsigned char);
void fuc (unsigned char);
void fsc (signed char);
void fsc (signed char);
 
 
void
void
h2 (void)
h2 (void)
{
{
  fsc (SCHAR_MAX + 1); /* { dg-warning "warning: overflow in implicit constant conversion" } */
  fsc (SCHAR_MAX + 1); /* { dg-warning "warning: overflow in implicit constant conversion" } */
  fsc (SCHAR_MIN - 1); /* { dg-warning "warning: overflow in implicit constant conversion" } */
  fsc (SCHAR_MIN - 1); /* { dg-warning "warning: overflow in implicit constant conversion" } */
  fsc (UCHAR_MAX); /* { dg-warning "warning: overflow in implicit constant conversion" } */
  fsc (UCHAR_MAX); /* { dg-warning "warning: overflow in implicit constant conversion" } */
  fsc (UCHAR_MAX + 1); /* { dg-warning "warning: overflow in implicit constant conversion" } */
  fsc (UCHAR_MAX + 1); /* { dg-warning "warning: overflow in implicit constant conversion" } */
  fuc (-1);
  fuc (-1);
  fuc (UCHAR_MAX + 1); /* { dg-warning "warning: large integer implicitly truncated to unsigned type" } */
  fuc (UCHAR_MAX + 1); /* { dg-warning "warning: large integer implicitly truncated to unsigned type" } */
  fuc (SCHAR_MIN);
  fuc (SCHAR_MIN);
  fuc (SCHAR_MIN - 1); /* { dg-warning "warning: large integer implicitly truncated to unsigned type" } */
  fuc (SCHAR_MIN - 1); /* { dg-warning "warning: large integer implicitly truncated to unsigned type" } */
  fuc (-UCHAR_MAX); /* { dg-warning "warning: large integer implicitly truncated to unsigned type" } */
  fuc (-UCHAR_MAX); /* { dg-warning "warning: large integer implicitly truncated to unsigned type" } */
}
}
 
 
void fui (unsigned int);
void fui (unsigned int);
void fsi (signed int);
void fsi (signed int);
 
 
int si;
int si;
unsigned ui;
unsigned ui;
 
 
void
void
h2i (int x)
h2i (int x)
{
{
  /* For some reason, we only give certain warnings for implicit
  /* For some reason, we only give certain warnings for implicit
     conversions among values of the same precision with -Wconversion,
     conversions among values of the same precision with -Wconversion,
     while we don't give others at all.  */
     while we don't give others at all.  */
  fsi ((unsigned)INT_MAX + 1);
  fsi ((unsigned)INT_MAX + 1);
  si = (unsigned)INT_MAX + 1;
  si = (unsigned)INT_MAX + 1;
  si = x ? (unsigned)INT_MAX + 1 : 1;
  si = x ? (unsigned)INT_MAX + 1 : 1;
  fsi ((unsigned)INT_MAX + 2);
  fsi ((unsigned)INT_MAX + 2);
  si = (unsigned)INT_MAX + 2;
  si = (unsigned)INT_MAX + 2;
  si = x ? (unsigned)INT_MAX + 2 : 1;
  si = x ? (unsigned)INT_MAX + 2 : 1;
  fsi (UINT_MAX);
  fsi (UINT_MAX);
  si = UINT_MAX;
  si = UINT_MAX;
  fui (-1);
  fui (-1);
  ui = -1;
  ui = -1;
  ui = x ? -1 : 1U;
  ui = x ? -1 : 1U;
  fui (INT_MIN);
  fui (INT_MIN);
  ui = INT_MIN;
  ui = INT_MIN;
  ui = x ? INT_MIN : 1U;
  ui = x ? INT_MIN : 1U;
}
}
 
 

powered by: WebSVN 2.1.0

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