This revision was automatically updated to reflect the committed changes.
Closed by commit rG6780d53f41fb: [clang-tidy] Warn about arrays in 
bugprone-undefined-memory-manipulation (authored by fwolff, committed by 
PiotrZSL).

Changed prior to commit:
  https://reviews.llvm.org/D127036?vs=434283&id=557139#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127036/new/

https://reviews.llvm.org/D127036

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


Index: 
clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-memory-manipulation.cpp
===================================================================
--- 
clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-memory-manipulation.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-memory-manipulation.cpp
@@ -126,6 +126,12 @@
   ::memmove(&p, &vb, sizeof(int));
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source 
object type 'types::VirtualBase'
 
+  types::Copy ca[10];
+  memset(ca, 0, sizeof(ca));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination 
object type 'types::Copy[10]'
+  memset(&ca, 0, sizeof(ca));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination 
object type 'types::Copy[10]'
+
 #define MEMSET memset(&vf, 0, sizeof(int));
   MEMSET
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination 
object type 'types::VirtualFunc'
@@ -159,6 +165,17 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination 
object type 'aliases::Copy2'
   memset(pc3, 0, sizeof(int));
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination 
object type 'Copy3'
+  using Copy3Arr = Copy3[5];
+  Copy3Arr c3a;
+  memset(c3a, 0, sizeof(c3a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination 
object type 'Copy3Arr'
+  memset(&c3a, 0, sizeof(c3a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination 
object type 'Copy3Arr'
+
+  typedef Copy3 Copy3Arr2[5];
+  Copy3Arr2 c3a2;
+  memset(c3a2, 0, sizeof(c3a2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination 
object type 'Copy3Arr2'
 }
 
 void triviallyCopyable() {
Index: 
clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
@@ -22,9 +22,14 @@
 } // namespace
 
 void UndefinedMemoryManipulationCheck::registerMatchers(MatchFinder *Finder) {
-  const auto NotTriviallyCopyableObject =
-      hasType(ast_matchers::hasCanonicalType(
-          pointsTo(cxxRecordDecl(isNotTriviallyCopyable()))));
+  const auto HasNotTriviallyCopyableDecl =
+      hasDeclaration(cxxRecordDecl(isNotTriviallyCopyable()));
+  const auto ArrayOfNotTriviallyCopyable =
+      arrayType(hasElementType(HasNotTriviallyCopyableDecl));
+  const auto NotTriviallyCopyableObject = hasType(hasCanonicalType(
+      anyOf(pointsTo(qualType(anyOf(HasNotTriviallyCopyableDecl,
+                                    ArrayOfNotTriviallyCopyable))),
+            ArrayOfNotTriviallyCopyable)));
 
   // Check whether destination object is not TriviallyCopyable.
   // Applicable to all three memory manipulation functions.


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-memory-manipulation.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-memory-manipulation.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/undefined-memory-manipulation.cpp
@@ -126,6 +126,12 @@
   ::memmove(&p, &vb, sizeof(int));
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, source object type 'types::VirtualBase'
 
+  types::Copy ca[10];
+  memset(ca, 0, sizeof(ca));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'types::Copy[10]'
+  memset(&ca, 0, sizeof(ca));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'types::Copy[10]'
+
 #define MEMSET memset(&vf, 0, sizeof(int));
   MEMSET
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'types::VirtualFunc'
@@ -159,6 +165,17 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'aliases::Copy2'
   memset(pc3, 0, sizeof(int));
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'Copy3'
+  using Copy3Arr = Copy3[5];
+  Copy3Arr c3a;
+  memset(c3a, 0, sizeof(c3a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'Copy3Arr'
+  memset(&c3a, 0, sizeof(c3a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'Copy3Arr'
+
+  typedef Copy3 Copy3Arr2[5];
+  Copy3Arr2 c3a2;
+  memset(c3a2, 0, sizeof(c3a2));
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: undefined behavior, destination object type 'Copy3Arr2'
 }
 
 void triviallyCopyable() {
Index: clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/UndefinedMemoryManipulationCheck.cpp
@@ -22,9 +22,14 @@
 } // namespace
 
 void UndefinedMemoryManipulationCheck::registerMatchers(MatchFinder *Finder) {
-  const auto NotTriviallyCopyableObject =
-      hasType(ast_matchers::hasCanonicalType(
-          pointsTo(cxxRecordDecl(isNotTriviallyCopyable()))));
+  const auto HasNotTriviallyCopyableDecl =
+      hasDeclaration(cxxRecordDecl(isNotTriviallyCopyable()));
+  const auto ArrayOfNotTriviallyCopyable =
+      arrayType(hasElementType(HasNotTriviallyCopyableDecl));
+  const auto NotTriviallyCopyableObject = hasType(hasCanonicalType(
+      anyOf(pointsTo(qualType(anyOf(HasNotTriviallyCopyableDecl,
+                                    ArrayOfNotTriviallyCopyable))),
+            ArrayOfNotTriviallyCopyable)));
 
   // Check whether destination object is not TriviallyCopyable.
   // Applicable to all three memory manipulation functions.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to