[clang-tools-extra] r213238 - [clang-tidy] MemsetZeroLenghtChecker: Don't crash trying to evaluate dependent values.
Benjamin Kramer
benny.kra at googlemail.com
Thu Jul 17 01:56:55 PDT 2014
Author: d0k
Date: Thu Jul 17 03:56:55 2014
New Revision: 213238
URL: http://llvm.org/viewvc/llvm-project?rev=213238&view=rev
Log:
[clang-tidy] MemsetZeroLenghtChecker: Don't crash trying to evaluate dependent values.
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=213238&r1=213237&r2=213238&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/MemsetZeroLengthCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/MemsetZeroLengthCheck.cpp Thu Jul 17 03:56:55 2014
@@ -59,11 +59,13 @@ void MemsetZeroLengthCheck::check(const
// Try to evaluate the second argument so we can also find values that are not
// just literals.
llvm::APSInt Value1, Value2;
- if (!Arg2->EvaluateAsInt(Value2, *Result.Context) || Value2 != 0)
+ if (Arg2->isValueDependent() ||
+ !Arg2->EvaluateAsInt(Value2, *Result.Context) || Value2 != 0)
return;
// If both arguments evaluate to zero emit a warning without fix suggestions.
- if (Arg1->EvaluateAsInt(Value1, *Result.Context) &&
+ if (!Arg1->isValueDependent() &&
+ 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=213238&r1=213237&r2=213238&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 Thu Jul 17 03:56:55 2014
@@ -7,9 +7,13 @@ namespace std {
using ::memset;
}
-template <int i>
+template <int i, typename T>
void memtmpl() {
memset(0, sizeof(int), i);
+ memset(0, sizeof(T), sizeof(T));
+ memset(0, sizeof(T), 0);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
+// CHECK-FIXES: memset(0, 0, sizeof(T));
memset(0, sizeof(int), 0);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero, potentially swapped argument
// CHECK-FIXES: memset(0, 0, sizeof(int));
@@ -53,5 +57,5 @@ void foo(void *a, int xsize, int ysize)
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: memset of size zero
// CHECK-FIXES: memset(a, -1, v);
- memtmpl<0>();
+ memtmpl<0, int>();
}
More information about the cfe-commits
mailing list