[analyzer] [RetainCountChecker] Do not invalidate references passed to constructors...
authorGeorge Karpenkov <ekarpenkov@apple.com>
Thu, 25 Oct 2018 23:38:41 +0000 (23:38 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Thu, 25 Oct 2018 23:38:41 +0000 (23:38 +0000)
Differential Revision: https://reviews.llvm.org/D53660

llvm-svn: 345340

clang/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h
clang/lib/StaticAnalyzer/Core/RetainSummaryManager.cpp
clang/test/Analysis/osobject-retain-release.cpp

index 486e2aca84a19d3eb9756258d5964450b6670ffe..9b71011a54d2a7c9c5a7b916c3719e60c8bca15b 100644 (file)
@@ -139,7 +139,7 @@ public:
     OwnedWhenTrackedReceiver,
     // Treat this function as returning a non-tracked symbol even if
     // the function has been inlined. This is used where the call
-    // site summary is more presise than the summary indirectly produced
+    // site summary is more precise than the summary indirectly produced
     // by inlining the function
     NoRetHard
   };
index 1a2dc28a5713d3520387beafa31899b05329aa32..efaab64c77038367ef987492f3ee31fc9601abc3 100644 (file)
@@ -478,8 +478,12 @@ RetainSummaryManager::getSummary(const CallEvent &Call,
     Summ = getFunctionSummary(cast<CXXMemberCall>(Call).getDecl());
     break;
   case CE_CXXMemberOperator:
-  case CE_Block:
+    Summ = getFunctionSummary(cast<CXXMemberOperatorCall>(Call).getDecl());
+    break;
   case CE_CXXConstructor:
+    Summ = getFunctionSummary(cast<CXXConstructorCall>(Call).getDecl());
+    break;
+  case CE_Block:
   case CE_CXXDestructor:
   case CE_CXXAllocator:
     // FIXME: These calls are currently unsupported.
index 4e26c03bc26ea7ed5263bd8c39fc95fafd2c1767..17360ac3220272c0540ed5b3aeb075753a1dc561 100644 (file)
@@ -43,6 +43,7 @@ struct OSArray : public OSObject {
 
 struct OtherStruct {
   static void doNothingToArray(OSArray *array);
+  OtherStruct(OSArray *arr);
 };
 
 struct OSMetaClassBase {
@@ -55,6 +56,12 @@ void check_no_invalidation() {
 } // expected-warning{{Potential leak of an object stored into 'arr'}}
   // expected-note@-1{{Object leaked}}
 
+void check_no_invalidation_other_struct() {
+  OSArray *arr = OSArray::withCapacity(10); // expected-note{{Call to function 'withCapacity' returns an OSObject of type struct OSArray * with a +1 retain count}}
+  OtherStruct other(arr); // expected-warning{{Potential leak}}
+                          // expected-note@-1{{Object leaked}}
+}
+
 void check_rc_consumed() {
   OSArray *arr = OSArray::withCapacity(10);
   OSArray::consumeArray(arr);