[PATCH] D106296: [analyer] Fix for faulty namespace test in SmartPtrModelling

Deep Majumder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 19 11:51:44 PDT 2021


RedDocMD updated this revision to Diff 359865.
RedDocMD added a comment.

Reformatted patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106296

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp


Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -249,8 +249,12 @@
 }
 
 bool isStdOstreamOperatorCall(const CallEvent &Call) {
-  if (Call.getNumArgs() != 2 ||
-      !Call.getDecl()->getDeclContext()->isStdNamespace())
+  if (Call.getNumArgs() != 2)
+    return false;
+  const auto *Decl = Call.getDecl();
+  if (!Decl)
+    return false;
+  if (!Decl->getDeclContext()->isStdNamespace())
     return false;
   const auto *FC = dyn_cast<SimpleFunctionCall>(&Call);
   if (!FC)
@@ -265,6 +269,18 @@
          isStdBasicOstream(Call.getArgExpr(0));
 }
 
+static bool isPotentiallyComparisionOpCall(const CallEvent &Call) {
+  if (Call.getNumArgs() != 2)
+    return false;
+  const auto *Decl = Call.getDecl();
+  if (!Decl)
+    return false;
+  if (!Decl->getDeclContext()->isStdNamespace())
+    return false;
+  return smartptr::isStdSmartPtr(Call.getArgExpr(0)) ||
+         smartptr::isStdSmartPtr(Call.getArgExpr(1));
+}
+
 bool SmartPtrModeling::evalCall(const CallEvent &Call,
                                 CheckerContext &C) const {
 
@@ -272,14 +288,11 @@
 
   // If any one of the arg is a unique_ptr, then
   // we can try this function
-  if (Call.getNumArgs() == 2 &&
-      Call.getDecl()->getDeclContext()->isStdNamespace())
-    if (smartptr::isStdSmartPtr(Call.getArgExpr(0)) ||
-        smartptr::isStdSmartPtr(Call.getArgExpr(1)))
-      if (handleComparisionOp(Call, C))
-        return true;
-
-  if (isStdOstreamOperatorCall(Call))
+  if (ModelSmartPtrDereference && isPotentiallyComparisionOpCall(Call))
+    if (handleComparisionOp(Call, C))
+      return true;
+
+  if (ModelSmartPtrDereference && isStdOstreamOperatorCall(Call))
     return handleOstreamOperator(Call, C);
 
   if (Call.isCalled(StdSwapCall)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106296.359865.patch
Type: text/x-patch
Size: 1946 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210719/bb346cc3/attachment-0001.bin>


More information about the cfe-commits mailing list