]> granicus.if.org Git - clang/commit
Add -Wabsolute-value, warnings about absolute value functions.
authorRichard Trieu <rtrieu@google.com>
Wed, 26 Feb 2014 01:17:28 +0000 (01:17 +0000)
committerRichard Trieu <rtrieu@google.com>
Wed, 26 Feb 2014 01:17:28 +0000 (01:17 +0000)
commit4a7f7947a3f66658d68926182842e08d40d93d45
treeb29a7fcf3e27dd699fc4f002ddba2b4e215cb873
parent23eb67333460fca42cc99892eb69e1fe24e5f93a
Add -Wabsolute-value, warnings about absolute value functions.

The warnings fall into three groups.
1) Using an absolute value function of the wrong type, for instance, using the
int absolute value function when the argument is a floating point type.
2) Using the improper sized absolute value function, for instance, using abs
when the argument is a long long.  llabs should be used instead.

From these two cases, an implicit conversion will occur which may cause
unexpected behavior.  Where possible, suggest the proper absolute value
function to use, and which header to include if the function is not available.

3) Taking the absolute value of an unsigned value.  In addition to this warning,
suggest to remove the function call.  This usually indicates a logic error
since the programmer assumed negative values would have been possible.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202211 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
include/clang/Sema/Sema.h
lib/Sema/SemaChecking.cpp
test/Sema/warn-absolute-value-header.c [new file with mode: 0644]
test/Sema/warn-absolute-value.c [new file with mode: 0644]
test/SemaCXX/warn-absolute-value-header.cpp [new file with mode: 0644]