1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -verify %s -Wabsolute-value
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only %s -Wabsolute-value -fdiagnostics-parseable-fixits 2>&1 | FileCheck %s
3*0a6a1f1dSLionel Sambuc
4*0a6a1f1dSLionel Sambuc int abs(int);
5*0a6a1f1dSLionel Sambuc
6*0a6a1f1dSLionel Sambuc // Wrong signature
7*0a6a1f1dSLionel Sambuc int fabsf(int);
8*0a6a1f1dSLionel Sambuc // expected-warning@-1{{incompatible redeclaration of library function 'fabsf'}}
9*0a6a1f1dSLionel Sambuc // expected-note@-2{{'fabsf' is a builtin with type 'float (float)'}}
10*0a6a1f1dSLionel Sambuc
test_int(int i,unsigned u,long long ll,float f,double d)11*0a6a1f1dSLionel Sambuc void test_int(int i, unsigned u, long long ll, float f, double d) {
12*0a6a1f1dSLionel Sambuc (void)abs(i);
13*0a6a1f1dSLionel Sambuc
14*0a6a1f1dSLionel Sambuc // Remove abs call
15*0a6a1f1dSLionel Sambuc (void)abs(u);
16*0a6a1f1dSLionel Sambuc // expected-warning@-1{{taking the absolute value of unsigned type 'unsigned int' has no effect}}
17*0a6a1f1dSLionel Sambuc // expected-note@-2{{remove the call to 'abs' since unsigned values cannot be negative}}
18*0a6a1f1dSLionel Sambuc // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:""
19*0a6a1f1dSLionel Sambuc
20*0a6a1f1dSLionel Sambuc int llabs;
21*0a6a1f1dSLionel Sambuc (void)llabs;
22*0a6a1f1dSLionel Sambuc // Conflict in names, no notes
23*0a6a1f1dSLionel Sambuc (void)abs(ll);
24*0a6a1f1dSLionel Sambuc // expected-warning@-1{{absolute value function 'abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value}}
25*0a6a1f1dSLionel Sambuc
26*0a6a1f1dSLionel Sambuc // Conflict in names, no notes
27*0a6a1f1dSLionel Sambuc (void)abs(f);
28*0a6a1f1dSLionel Sambuc // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}}
29*0a6a1f1dSLionel Sambuc
30*0a6a1f1dSLionel Sambuc // Suggest header.
31*0a6a1f1dSLionel Sambuc (void)abs(d);
32*0a6a1f1dSLionel Sambuc // expected-warning@-1{{using integer absolute value function 'abs' when argument is of floating point type}}
33*0a6a1f1dSLionel Sambuc // expected-note@-2{{use function 'fabs' instead}}
34*0a6a1f1dSLionel Sambuc // expected-note@-3{{include the header <math.h> or explicitly provide a declaration for 'fabs'}}
35*0a6a1f1dSLionel Sambuc // CHECK: fix-it:"{{.*}}":{[[@LINE-4]]:9-[[@LINE-4]]:12}:"fabs"
36*0a6a1f1dSLionel Sambuc }
37