[PATCH] D35790: [clang-tidy] Handle incomplete types in bugprone-undefined-memory-manipulation check.

Reka Kovacs via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 24 01:58:15 PDT 2017


rnkovacs created this revision.
rnkovacs added a project: clang-tools-extra.
Herald added subscribers: whisperity, JDevlieghere.

`bugprone-undefined-memory-manipulation` check crashes on incomplete types. This diff fixes that by assuming they are `TriviallyCopyable` by default.


https://reviews.llvm.org/D35790

Files:
  clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
  test/clang-tidy/bugprone-undefined-memory-manipulation.cpp


Index: test/clang-tidy/bugprone-undefined-memory-manipulation.cpp
===================================================================
--- test/clang-tidy/bugprone-undefined-memory-manipulation.cpp
+++ test/clang-tidy/bugprone-undefined-memory-manipulation.cpp
@@ -52,6 +52,13 @@
   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));
Index: clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
===================================================================
--- clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
+++ clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
@@ -19,7 +19,8 @@
 
 namespace {
 AST_MATCHER(CXXRecordDecl, isNotTriviallyCopyable) {
-  return !Node.isTriviallyCopyable();
+  // For incomplete types, assume they are TriviallyCopyable.
+  return Node.hasDefinition() ? !Node.isTriviallyCopyable() : false;
 }
 } // namespace
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35790.107863.patch
Type: text/x-patch
Size: 1022 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170724/b14b1a1e/attachment.bin>


More information about the cfe-commits mailing list