bruntib created this revision.
bruntib added reviewers: NoQ, george.karpenkov, Szelethus, xazax.hun, 
baloghadamsoftware.
Herald added subscribers: cfe-commits, dkrupp, donat.nagy, mikhail.ramalho, 
a.sidorin, rnkovacs, szepet.
Herald added a project: clang.

For self assignment checker it was necessary to force checking of assignment 
operators even if those are not called. The reason of this is to check whether 
"this" is equal to the address of the assignee object.

The buffer overlap checker checks if the intervals of the arguments of a 
memcpy() call are disjoint. If a class has an array member then the compiler 
generated assignment operator copies it with memcpy() function without checking 
self assignment at the beginning. Since the analyzer forces the check of 
assignment operators, the buffer overflow checker reported a false positive on 
classes with compiler generated assignment operator and array member.

This commit prevents the forced check of compiler generated assignment 
operators.


Repository:
  rC Clang

https://reviews.llvm.org/D57890

Files:
  lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp


Index: lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===================================================================
--- lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -450,7 +450,7 @@
   // where it may not. (cplusplus.SelfAssignmentChecker)
   if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
     if (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())
-      return false;
+      return !MD->isUserProvided();
   }
 
   // Otherwise, if we visited the function before, do not reanalyze it.


Index: lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
===================================================================
--- lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -450,7 +450,7 @@
   // where it may not. (cplusplus.SelfAssignmentChecker)
   if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
     if (MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())
-      return false;
+      return !MD->isUserProvided();
   }
 
   // Otherwise, if we visited the function before, do not reanalyze it.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to