[PATCH] Warn on suspicious use of absolute value function
Richard Smith
richard at metafoo.co.uk
Thu Jan 23 13:28:34 PST 2014
================
Comment at: lib/Sema/SemaChecking.cpp:3593
@@ +3592,3 @@
+// does not exist.
+static unsigned GetLargerAbsoluteValueFunction(unsigned abs_function) {
+ switch (abs_function) {
----------------
Lowercase first letter, please. Also, AbsFunction, not abs_function.
================
Comment at: lib/Sema/SemaChecking.cpp:3684-3688
@@ +3683,7 @@
+
+enum AbsoluteValueKind {
+ ABS_INTEGER,
+ ABS_FLOATING,
+ ABS_COMPLEX
+};
+
----------------
This'd be more in keeping with our usual style as AVK_Integer, AVK_Floating, AVK_Complex
================
Comment at: lib/Sema/SemaChecking.cpp:3767
@@ +3766,3 @@
+
+unsigned getAbsoluteValueFunctionKind(const FunctionDecl* FDecl) {
+ const IdentifierInfo *FnInfo = FDecl->getIdentifier();
----------------
`*` on the right.
================
Comment at: test/Sema/warn-absolute-value.c:215-219
@@ +214,7 @@
+
+void test_float(float x) {
+ (void)abs(x);
+ // expected-warning at -1 {{using integer absolute value function when argument is of floating point type}}
+ // expected-note at -2 {{use function 'fabsf' instead}}
+ // CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:9-[[@LINE-3]]:12}:"fabsf"
+ (void)labs(x);
----------------
In this case, we should probably suggest that the user `#include <cmath>`, which provides the appropriate overloads of `abs` for floating-point types, if we're in C++ mode.
http://llvm-reviews.chandlerc.com/D2224
More information about the cfe-commits
mailing list