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