1 /* { dg-do compile { target c99_runtime } } */
2 /* { dg-options "-Wabsolute-value" } */
3
4 #include <stdlib.h>
5 #include <inttypes.h>
6 #include <math.h>
7 #include <complex.h>
8
9 void
tst_unsigned(unsigned * pu,unsigned long * pl,unsigned long long * pll,uintmax_t * pm)10 tst_unsigned (unsigned *pu, unsigned long *pl, unsigned long long *pll,
11 uintmax_t *pm)
12 {
13 *pu = abs (*pu); /* { dg-warning "taking the absolute value of unsigned type" } */
14 *pl = labs (*pl); /* { dg-warning "taking the absolute value of unsigned type" } */
15 *pll = llabs (*pll); /* { dg-warning "taking the absolute value of unsigned type" } */
16 *pm = imaxabs (*pm); /* { dg-warning "taking the absolute value of unsigned type" } */
17 }
18
19 void
test_int_size(long long * pll)20 test_int_size (long long *pll)
21 {
22 *pll = abs (*pll); /* { dg-warning "may cause truncation of value" } */
23 *pll = abs ((int) *pll);
24 }
25
26 void
tst_notint(float * pf,double * pd,_Complex double * pc)27 tst_notint (float *pf, double *pd, _Complex double *pc)
28 {
29 *pf = abs (*pf); /* { dg-warning "using integer absolute value function" } */
30 *pd = labs (*pd); /* { dg-warning "using integer absolute value function" } */
31 *pc = abs (*pc); /* { dg-warning "using integer absolute value function" } */
32 }
33
34 void
tst_notfloat(int * pi,long * pl,complex double * pc)35 tst_notfloat (int *pi, long *pl, complex double *pc)
36 {
37 *pi = fabsf (*pi); /* { dg-warning "using floating-point absolute value function" } */
38 *pl = fabs (*pl); /* { dg-warning "using floating-point absolute value function" } */
39 *pc = fabs (*pc); /* { dg-warning "using floating-point absolute value function" } */
40 }
41
42 void
tst_float_size(double * pd,long double * pld)43 tst_float_size (double *pd, long double *pld)
44 {
45 *pd = fabsf (*pd); /* { dg-warning "may cause truncation of value" } */
46 *pld = fabs (*pld); /* { dg-warning "may cause truncation of value" "fabs trunc" { target { large_long_double } } } */
47 *pld = fabs ((double) *pld);
48 }
49
tst_notcomplex(int * pi,long * pl,long double * pld)50 void tst_notcomplex (int *pi, long *pl, long double *pld)
51 {
52 *pi = cabs (*pi); /* { dg-warning "using complex absolute value function" } */
53 *pl = cabs (*pl); /* { dg-warning "using complex absolute value function" } */
54 *pld = cabsl (*pld);/* { dg-warning "using complex absolute value function" } */
55 }
56
tst_cplx_size(complex double * pcd,complex long double * pcld)57 void tst_cplx_size (complex double *pcd, complex long double *pcld)
58 {
59 *pcd = cabsf (*pcd); /* { dg-warning "may cause truncation of value" } */
60 *pcld = cabs (*pcld); /* { dg-warning "may cause truncation of value" "cabs trunc" { target { large_long_double } } } */
61 *pcld = cabs ((complex double) *pcld);
62 }
63
64
65
66
67