Szelethus created this revision.
Szelethus added reviewers: NoQ, george.karpenkov, xazax.hun, rnkovacs.
Herald added subscribers: cfe-commits, mikhail.ramalho, a.sidorin, szepet, 
whisperity.

Repository:
  rC Clang

https://reviews.llvm.org/D48325

Files:
  lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
  test/Analysis/cxx-uninitialized-object-ptr-ref.cpp


Index: test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===================================================================
--- test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -416,14 +416,12 @@
 
 #ifdef PEDANTIC
 struct PointerToMemberFunctionTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  void (UsefulFunctions::*f)(void); // no-note
+  void (UsefulFunctions::*f)(void); // expected-note{{uninitialized field 
'this->f'}}
   PointerToMemberFunctionTest1() {}
 };
 
 void fPointerToMemberFunctionTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberFunctionTest1(); // no-warning
+  PointerToMemberFunctionTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberFunctionTest2 {
@@ -460,14 +458,12 @@
 }
 
 struct PointerToMemberDataTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  int UsefulFunctions::*d; // no-note
+  int UsefulFunctions::*d; // expected-note{{uninitialized field 'this->d'}}
   PointerToMemberDataTest1() {}
 };
 
 void fPointerToMemberDataTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberDataTest1(); // no-warning
+  PointerToMemberDataTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberDataTest2 {
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -389,15 +389,14 @@
       continue;
     }
 
-    if (T->isMemberPointerType()) {
-      if (isMemberPointerUninit(FR, LocalChain))
+    if (T->isPointerType() || T->isReferenceType()) {
+      if (isPointerOrReferenceUninit(FR, LocalChain))
         ContainsUninitField = true;
       continue;
     }
 
-    // If this is a pointer or reference type.
-    if (T->isPointerType() || T->isReferenceType()) {
-      if (isPointerOrReferenceUninit(FR, LocalChain))
+    if (T->isMemberPointerType()) {
+      if (isMemberPointerUninit(FR, LocalChain))
         ContainsUninitField = true;
       continue;
     }
@@ -521,6 +520,12 @@
       }
     }
 
+    if (T->isMemberPointerType()) {
+      if (isMemberPointerUninit(FR, LocalChain))
+        return addFieldToUninits({LocalChain, FR, /*IsDereferenced*/ true});
+      return false;
+    }
+
     if (T->isArrayType()) {
       IsAnyFieldInitialized = true;
       return false;
@@ -543,7 +548,12 @@
                                                     FieldChainInfo LocalChain) 
{
   assert(FR->getDecl()->getType()->isMemberPointerType() &&
          "This function only checks regions that hold MemberPointerTypes!");
-  // TODO: Implement support for MemberPointerTypes.
+
+  SVal V = State->getSVal(FR);
+  if (V.isUndef())
+    return addFieldToUninits({LocalChain, FR});
+
+  IsAnyFieldInitialized = true;
   return false;
 }
 


Index: test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
===================================================================
--- test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
+++ test/Analysis/cxx-uninitialized-object-ptr-ref.cpp
@@ -416,14 +416,12 @@
 
 #ifdef PEDANTIC
 struct PointerToMemberFunctionTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  void (UsefulFunctions::*f)(void); // no-note
+  void (UsefulFunctions::*f)(void); // expected-note{{uninitialized field 'this->f'}}
   PointerToMemberFunctionTest1() {}
 };
 
 void fPointerToMemberFunctionTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberFunctionTest1(); // no-warning
+  PointerToMemberFunctionTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberFunctionTest2 {
@@ -460,14 +458,12 @@
 }
 
 struct PointerToMemberDataTest1 {
-  // TODO: we'd expect the note {{uninitialized field 'this->f'}}
-  int UsefulFunctions::*d; // no-note
+  int UsefulFunctions::*d; // expected-note{{uninitialized field 'this->d'}}
   PointerToMemberDataTest1() {}
 };
 
 void fPointerToMemberDataTest1() {
-  // TODO: we'd expect the warning {{1 uninitialized field}}
-  PointerToMemberDataTest1(); // no-warning
+  PointerToMemberDataTest1(); // expected-warning{{1 uninitialized field}}
 }
 
 struct PointerToMemberDataTest2 {
Index: lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
+++ lib/StaticAnalyzer/Checkers/UninitializedObjectChecker.cpp
@@ -389,15 +389,14 @@
       continue;
     }
 
-    if (T->isMemberPointerType()) {
-      if (isMemberPointerUninit(FR, LocalChain))
+    if (T->isPointerType() || T->isReferenceType()) {
+      if (isPointerOrReferenceUninit(FR, LocalChain))
         ContainsUninitField = true;
       continue;
     }
 
-    // If this is a pointer or reference type.
-    if (T->isPointerType() || T->isReferenceType()) {
-      if (isPointerOrReferenceUninit(FR, LocalChain))
+    if (T->isMemberPointerType()) {
+      if (isMemberPointerUninit(FR, LocalChain))
         ContainsUninitField = true;
       continue;
     }
@@ -521,6 +520,12 @@
       }
     }
 
+    if (T->isMemberPointerType()) {
+      if (isMemberPointerUninit(FR, LocalChain))
+        return addFieldToUninits({LocalChain, FR, /*IsDereferenced*/ true});
+      return false;
+    }
+
     if (T->isArrayType()) {
       IsAnyFieldInitialized = true;
       return false;
@@ -543,7 +548,12 @@
                                                     FieldChainInfo LocalChain) {
   assert(FR->getDecl()->getType()->isMemberPointerType() &&
          "This function only checks regions that hold MemberPointerTypes!");
-  // TODO: Implement support for MemberPointerTypes.
+
+  SVal V = State->getSVal(FR);
+  if (V.isUndef())
+    return addFieldToUninits({LocalChain, FR});
+
+  IsAnyFieldInitialized = true;
   return false;
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to