[clang-tools-extra] r308954 - [clang-tidy] Handle incomplete types in bugprone-undefined-memory-manipulation

Gabor Horvath via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 24 23:52:09 PDT 2017


Author: xazax
Date: Mon Jul 24 23:52:08 2017
New Revision: 308954

URL: http://llvm.org/viewvc/llvm-project?rev=308954&view=rev
Log:
[clang-tidy] Handle incomplete types in bugprone-undefined-memory-manipulation
check

Patch by: Reka Nikolett Kovacs

Differential Revision: https://reviews.llvm.org/D35790

Modified:
    clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/bugprone-undefined-memory-manipulation.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp?rev=308954&r1=308953&r2=308954&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp Mon Jul 24 23:52:08 2017
@@ -19,7 +19,8 @@ namespace bugprone {
 
 namespace {
 AST_MATCHER(CXXRecordDecl, isNotTriviallyCopyable) {
-  return !Node.isTriviallyCopyable();
+  // For incomplete types, assume they are TriviallyCopyable.
+  return Node.hasDefinition() ? !Node.isTriviallyCopyable() : false;
 }
 } // namespace
 

Modified: clang-tools-extra/trunk/test/clang-tidy/bugprone-undefined-memory-manipulation.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-undefined-memory-manipulation.cpp?rev=308954&r1=308953&r2=308954&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-undefined-memory-manipulation.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-undefined-memory-manipulation.cpp Mon Jul 24 23:52:08 2017
@@ -52,6 +52,13 @@ struct VirtualBase : virtual Base {
   int vb;
 };
 
+// Incomplete type, assume it is TriviallyCopyable.
+struct NoDef;
+
+void f(NoDef *s) {
+  memset(s, 0, 5);
+}
+
 template <typename T>
 void memset_temp(T *b) {
   memset(b, 0, sizeof(T));




More information about the cfe-commits mailing list