[clang-tools-extra] r213157 - [clang-tidy] As a simple heuristic don't emit a swap fixit that would create

Benjamin Kramer benny.kra at googlemail.com
Wed Jul 16 07:52:10 PDT 2014


Author: d0k
Date: Wed Jul 16 09:52:07 2014
New Revision: 213157

URL: http://llvm.org/viewvc/llvm-project?rev=213157&view=rev
Log:
[clang-tidy] As a simple heuristic don't emit a swap fixit that would create
negative-sized memsets.

memset(x, -1, 0) is still useless but swapping makes no sense here. Just emit
a warning.

Modified:
    clang-tools-extra/trunk/clang-tidy/google/MemsetZeroLengthCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/google-memset-zero-length.cpp

Modified: clang-tools-extra/trunk/clang-tidy/google/MemsetZeroLengthCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/MemsetZeroLengthCheck.cpp?rev=213157&r1=213156&r2=213157&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/MemsetZeroLengthCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/MemsetZeroLengthCheck.cpp Wed Jul 16 09:52:07 2014
@@ -63,7 +63,8 @@ void MemsetZeroLengthCheck::check(const
     return;
 
   // If both arguments evaluate to zero emit a warning without fix suggestions.
-  if (Arg1->EvaluateAsInt(Value1, *Result.Context) && Value1 == 0) {
+  if (Arg1->EvaluateAsInt(Value1, *Result.Context) &&
+      (Value1 == 0 || Value1.isNegative())) {
     diag(Call->getLocStart(), "memset of size zero");
     return;
   }

Modified: clang-tools-extra/trunk/test/clang-tidy/google-memset-zero-length.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-memset-zero-length.cpp?rev=213157&r1=213156&r2=213157&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-memset-zero-length.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-memset-zero-length.cpp Wed Jul 16 09:52:07 2014
@@ -49,5 +49,9 @@ void foo(void *a, int xsize, int ysize)
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero
 // CHECK-FIXES: memset(a, v, 0);
 
+  memset(a, -1, v);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero
+// CHECK-FIXES: memset(a, -1, v);
+
   memtmpl<0>();
 }





More information about the cfe-commits mailing list