[objc] Emit warnings when the implementation of a designated initializer calls on
super an initializer that is not a designated one or any initializer on self.

llvm-svn: 196317
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index c14cc4b..f243c0e 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9816,8 +9816,8 @@
     }
     if (getCurFunction()->ObjCWarnForNoDesignatedInitChain) {
       const ObjCMethodDecl *InitMethod = 0;
-      bool isDesignated = MD->getClassInterface()
-                      ->isDesignatedInitializer(MD->getSelector(), &InitMethod);
+      bool isDesignated =
+          MD->isDesignatedInitializerForTheInterface(&InitMethod);
       assert(isDesignated && InitMethod);
       (void)isDesignated;
       Diag(MD->getLocation(),
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 20f4b4f..c452306 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -2447,14 +2447,33 @@
     }
   }
 
-  if (SuperLoc.isValid() && getCurFunction()->ObjCIsDesignatedInit) {
-    if (const ObjCObjectPointerType *
-          OCIType = ReceiverType->getAsObjCInterfacePointerType()) {
-      if (const ObjCInterfaceDecl *ID = OCIType->getInterfaceDecl()) {
-        if (ID->isDesignatedInitializer(Sel))
-          getCurFunction()->ObjCWarnForNoDesignatedInitChain = false;
+  if (Method && Method->getMethodFamily() == OMF_init &&
+      getCurFunction()->ObjCIsDesignatedInit &&
+      (SuperLoc.isValid() || isSelfExpr(Receiver))) {
+    bool isDesignatedInitChain = false;
+    if (SuperLoc.isValid()) {
+      if (const ObjCObjectPointerType *
+            OCIType = ReceiverType->getAsObjCInterfacePointerType()) {
+        if (const ObjCInterfaceDecl *ID = OCIType->getInterfaceDecl()) {
+          if (ID->isDesignatedInitializer(Sel)) {
+            isDesignatedInitChain = true;
+            getCurFunction()->ObjCWarnForNoDesignatedInitChain = false;
+          }
+        }
       }
     }
+    if (!isDesignatedInitChain) {
+      const ObjCMethodDecl *InitMethod = 0;
+      bool isDesignated =
+        getCurMethodDecl()->isDesignatedInitializerForTheInterface(&InitMethod);
+      assert(isDesignated && InitMethod);
+      (void)isDesignated;
+      Diag(SelLoc, SuperLoc.isValid() ?
+             diag::warn_objc_designated_init_non_designated_init_call :
+             diag::warn_objc_designated_init_non_super_designated_init_call);
+      Diag(InitMethod->getLocation(),
+           diag::note_objc_designated_init_marked_here);
+    }
   }
 
   // Check the message arguments.