]> granicus.if.org Git - clang/commitdiff
[analyzer] Fix UninitializedObjectChecker to not crash on uninitialized "id" fields
authorGeorge Karpenkov <ekarpenkov@apple.com>
Mon, 13 Aug 2018 23:32:15 +0000 (23:32 +0000)
committerGeorge Karpenkov <ekarpenkov@apple.com>
Mon, 13 Aug 2018 23:32:15 +0000 (23:32 +0000)
Differential Revision: https://reviews.llvm.org/D50673

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@339631 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedPointee.cpp
test/Analysis/objcpp-uninitialized-object.mm

index 4da5fa5461b2101f9209135c2f9b0f5b2de55f83..810e0661782b12067c5c0e0ed8ad04968c47bc29 100644 (file)
@@ -265,7 +265,7 @@ bool FindUninitializedFields::isNonUnionUninit(const TypedValueRegion *R,
       continue;
     }
 
-    if (T->isPointerType() || T->isReferenceType() || T->isBlockPointerType()) {
+    if (T->isAnyPointerType() || T->isReferenceType() || T->isBlockPointerType()) {
       if (isPointerOrReferenceUninit(FR, LocalChain))
         ContainsUninitField = true;
       continue;
index 7f08d028942d5ce0264fe61eb89d939ebfe665d3..6c83b2e146d1fe91811391f4ee61fc1301ef362f 100644 (file)
@@ -78,7 +78,7 @@ static bool isVoidPointer(QualType T);
 bool FindUninitializedFields::isPointerOrReferenceUninit(
     const FieldRegion *FR, FieldChainInfo LocalChain) {
 
-  assert((FR->getDecl()->getType()->isPointerType() ||
+  assert((FR->getDecl()->getType()->isAnyPointerType() ||
           FR->getDecl()->getType()->isReferenceType() ||
           FR->getDecl()->getType()->isBlockPointerType()) &&
          "This method only checks pointer/reference objects!");
index 3ec1eb75182ef9833ce6237b540adaffa88037c0..c1afb726389ef5055d09ebabb60791b0c3b51620 100644 (file)
@@ -20,3 +20,13 @@ void warnOnUninitializedBlock() {
 void noWarningWhenInitialized() {
   StructWithBlock a;
 }
+
+struct StructWithId {
+  int a;
+  id z; // expected-note{{uninitialized pointer 'this->z'}}
+  StructWithId() : a(0) {} // expected-warning{{1 uninitialized field at the end of the constructor call}}
+};
+
+void warnOnUninitializedId() {
+  StructWithId s;
+}