aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/warn-abs-1.c
blob: ccd61efbe1e15e0005d88c8a7567ccf96f129d8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* { dg-do compile { target c99_runtime } } */
/* { dg-options "-Wabsolute-value" } */

#include <stdlib.h>
#include <inttypes.h>
#include <math.h>
#include <complex.h>

void
tst_unsigned (unsigned *pu, unsigned long *pl, unsigned long long *pll,
	      uintmax_t *pm)
{
  *pu = abs (*pu);      /* { dg-warning "taking the absolute value of unsigned type" } */
  *pl = labs (*pl);     /* { dg-warning "taking the absolute value of unsigned type" } */
  *pll = llabs (*pll);  /* { dg-warning "taking the absolute value of unsigned type" } */
  *pm = imaxabs (*pm);      /* { dg-warning "taking the absolute value of unsigned type" } */
}

void
test_int_size (long long *pll)
{
  *pll = abs (*pll);  /* { dg-warning "may cause truncation of value" } */
  *pll = abs ((int) *pll);
}

void
tst_notint (float *pf, double *pd, _Complex double *pc)
{
  *pf = abs (*pf);    /* { dg-warning "using integer absolute value function" } */
  *pd = labs (*pd);   /* { dg-warning "using integer absolute value function" } */
  *pc = abs (*pc);    /* { dg-warning "using integer absolute value function" } */
}

void
tst_notfloat (int *pi, long *pl, complex double *pc)
{
  *pi = fabsf (*pi);  /* { dg-warning "using floating-point absolute value function" } */
  *pl = fabs (*pl);   /* { dg-warning "using floating-point absolute value function" } */
  *pc = fabs (*pc);   /* { dg-warning "using floating-point absolute value function" } */
}

void
tst_float_size (double *pd, long double *pld)
{
  *pd = fabsf (*pd);   /* { dg-warning "may cause truncation of value" } */
  *pld = fabs (*pld);  /* { dg-warning "may cause truncation of value" "fabs trunc" { target { large_long_double } } } */
  *pld = fabs ((double) *pld);
}

void tst_notcomplex (int *pi, long *pl, long double *pld)
{
  *pi = cabs (*pi);   /* { dg-warning "using complex absolute value function" } */
  *pl = cabs (*pl);   /* { dg-warning "using complex absolute value function" } */
  *pld = cabsl (*pld);/* { dg-warning "using complex absolute value function" } */
}

void tst_cplx_size (complex double *pcd, complex long double *pcld)
{
  *pcd = cabsf (*pcd);   /* { dg-warning "may cause truncation of value" } */
  *pcld = cabs (*pcld);  /* { dg-warning "may cause truncation of value" "cabs trunc" { target { large_long_double } } } */
  *pcld = cabs ((complex double) *pcld);
}