]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.dg/warn-abs-1.c
[testsuite] Further fixes to warn-abs-1.c
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / warn-abs-1.c
CommitLineData
daa809da 1/* { dg-do compile } */
f178ded7 2/* { dg-options "-Wabsolute-value" } */
3
4#include <stdlib.h>
5#include <inttypes.h>
6#include <math.h>
7#include <complex.h>
8
9void
10tst_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
19void
20test_int_size (long long *pll)
21{
22 *pll = abs (*pll); /* { dg-warning "may cause truncation of value" } */
23 *pll = abs ((int) *pll);
24}
25
26void
27tst_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
34void
35tst_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
42void
daa809da 43tst_float_size (double *pd, long double *pld)
f178ded7 44{
45 *pd = fabsf (*pd); /* { dg-warning "may cause truncation of value" } */
cebe6e17 46 *pld = fabs (*pld); /* { dg-warning "may cause truncation of value" "fabs trunc" { target { large_long_double } } } */
f178ded7 47 *pld = fabs ((double) *pld);
f178ded7 48}
49
50void 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
57void tst_cplx_size (complex double *pcd, complex long double *pcld)
58{
59 *pcd = cabsf (*pcd); /* { dg-warning "may cause truncation of value" } */
cebe6e17 60 *pcld = cabs (*pcld); /* { dg-warning "may cause truncation of value" "cabs trunc" { target { large_long_double } } } */
f178ded7 61 *pcld = cabs ((complex double) *pcld);
62}
63
64
65
66