summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-12-03 21:11:36 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2013-12-03 21:11:36 +0000
commit22bfa2c28bdbca09949ba4cf8670c310d3e42c71 (patch)
tree27e9efff069b7c1a7bb8b948c83913b77a67fd76 /clang/lib/Sema
parent9ed9e5f31c1fe946a5c6c1ffb651052925570fd4 (diff)
downloadbcm5719-llvm-22bfa2c28bdbca09949ba4cf8670c310d3e42c71.tar.gz
bcm5719-llvm-22bfa2c28bdbca09949ba4cf8670c310d3e42c71.zip
[objc] Emit a warning when the implementation of a designated initializer does not chain to
an init method that is a designated initializer for the superclass. llvm-svn: 196316
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r--clang/lib/Sema/ScopeInfo.cpp4
-rw-r--r--clang/lib/Sema/SemaDecl.cpp12
-rw-r--r--clang/lib/Sema/SemaDeclObjC.cpp6
-rw-r--r--clang/lib/Sema/SemaExprObjC.cpp10
4 files changed, 32 insertions, 0 deletions
diff --git a/clang/lib/Sema/ScopeInfo.cpp b/clang/lib/Sema/ScopeInfo.cpp
index 8b3493ebfef..cf2b5ebe0e5 100644
--- a/clang/lib/Sema/ScopeInfo.cpp
+++ b/clang/lib/Sema/ScopeInfo.cpp
@@ -26,6 +26,10 @@ void FunctionScopeInfo::Clear() {
HasBranchProtectedScope = false;
HasBranchIntoScope = false;
HasIndirectGoto = false;
+ HasDroppedStmt = false;
+ ObjCShouldCallSuper = false;
+ ObjCIsDesignatedInit = false;
+ ObjCWarnForNoDesignatedInitChain = false;
SwitchStack.clear();
Returns.clear();
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 8229a6224a2..c14cc4b8619 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9814,6 +9814,18 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body,
<< MD->getSelector().getAsString();
getCurFunction()->ObjCShouldCallSuper = false;
}
+ if (getCurFunction()->ObjCWarnForNoDesignatedInitChain) {
+ const ObjCMethodDecl *InitMethod = 0;
+ bool isDesignated = MD->getClassInterface()
+ ->isDesignatedInitializer(MD->getSelector(), &InitMethod);
+ assert(isDesignated && InitMethod);
+ (void)isDesignated;
+ Diag(MD->getLocation(),
+ diag::warn_objc_designated_init_missing_super_call);
+ Diag(InitMethod->getLocation(),
+ diag::note_objc_designated_init_marked_here);
+ getCurFunction()->ObjCWarnForNoDesignatedInitChain = false;
+ }
} else {
return 0;
}
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index d9b6378269a..53c11d59e66 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -391,6 +391,9 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) {
MDecl->getLocation(), 0);
}
+ if (MDecl->isDesignatedInitializerForTheInterface())
+ getCurFunction()->ObjCIsDesignatedInit = true;
+
// If this is "dealloc" or "finalize", set some bit here.
// Then in ActOnSuperMessage() (SemaExprObjC), set it back to false.
// Finally, in ActOnFinishFunctionBody() (SemaDecl), warn if flag is set.
@@ -413,6 +416,9 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) {
getCurFunction()->ObjCShouldCallSuper =
(SuperMethod && SuperMethod->hasAttr<ObjCRequiresSuperAttr>());
}
+
+ if (getCurFunction()->ObjCIsDesignatedInit)
+ getCurFunction()->ObjCWarnForNoDesignatedInitChain = true;
}
}
}
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index a60749b0224..20f4b4f7248 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -2447,6 +2447,16 @@ ExprResult Sema::BuildInstanceMessage(Expr *Receiver,
}
}
+ if (SuperLoc.isValid() && getCurFunction()->ObjCIsDesignatedInit) {
+ if (const ObjCObjectPointerType *
+ OCIType = ReceiverType->getAsObjCInterfacePointerType()) {
+ if (const ObjCInterfaceDecl *ID = OCIType->getInterfaceDecl()) {
+ if (ID->isDesignatedInitializer(Sel))
+ getCurFunction()->ObjCWarnForNoDesignatedInitChain = false;
+ }
+ }
+ }
+
// Check the message arguments.
unsigned NumArgs = ArgsIn.size();
Expr **Args = ArgsIn.data();
OpenPOWER on IntegriCloud