aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaExprObjC.cpp
diff options
context:
space:
mode:
authorJordy Rose <jediknil@belkadan.com>2012-05-12 15:53:41 +0000
committerJordy Rose <jediknil@belkadan.com>2012-05-12 15:53:41 +0000
commit99446d934c85e8b705cc6b8624e65b8eb8c22985 (patch)
treedfc0c0bc823370cc8d24bf39f701b23aae671e68 /lib/Sema/SemaExprObjC.cpp
parent70fdbc366da85880aae5baebd3351e993ca05603 (diff)
Don't crash on boxed strings when +stringWithUTF8String: is missing.
Also, unify some diagnostics for boxed expressions that have the same form. Fixes PR12804. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156713 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExprObjC.cpp')
-rw-r--r--lib/Sema/SemaExprObjC.cpp33
1 files changed, 28 insertions, 5 deletions
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index ed71eb128c..24f4437b61 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -214,7 +214,9 @@ static ObjCMethodDecl *getNSNumberFactoryMethod(Sema &S, SourceLocation Loc,
}
if (!Method) {
- S.Diag(Loc, diag::err_undeclared_nsnumber_method) << Sel;
+ // FIXME: Is there a better way to avoid quotes than using getName()?
+ S.Diag(Loc, diag::err_undeclared_boxing_method)
+ << Sel << S.NSNumberDecl->getName();
return 0;
}
@@ -471,8 +473,25 @@ ExprResult Sema::BuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
M->setMethodParams(Context, value, ArrayRef<SourceLocation>());
StringWithUTF8StringMethod = M;
}
- assert(StringWithUTF8StringMethod &&
- "StringWithUTF8StringMethod should not be NULL");
+
+ // FIXME: Copied from getNSNumberFactoryMethod().
+ if (!StringWithUTF8StringMethod) {
+ // FIXME: Is there a better way to avoid quotes than using getName()?
+ Diag(SR.getBegin(), diag::err_undeclared_boxing_method)
+ << stringWithUTF8String << NSStringDecl->getName();
+ return ExprError();
+ }
+
+ // Make sure the return type is reasonable.
+ QualType ResultType = StringWithUTF8StringMethod->getResultType();
+ if (!ResultType->isObjCObjectPointerType()) {
+ Diag(SR.getBegin(), diag::err_objc_literal_method_sig)
+ << stringWithUTF8String;
+ Diag(StringWithUTF8StringMethod->getLocation(),
+ diag::note_objc_literal_method_return)
+ << ResultType;
+ return ExprError();
+ }
}
BoxingMethod = StringWithUTF8StringMethod;
@@ -633,7 +652,9 @@ ExprResult Sema::BuildObjCArrayLiteral(SourceRange SR, MultiExprArg Elements) {
}
if (!ArrayWithObjectsMethod) {
- Diag(SR.getBegin(), diag::err_undeclared_arraywithobjects) << Sel;
+ // FIXME: Is there a better way to avoid quotes than using getName()?
+ Diag(SR.getBegin(), diag::err_undeclared_boxing_method)
+ << Sel << NSArrayDecl->getName();
return ExprError();
}
}
@@ -773,7 +794,9 @@ ExprResult Sema::BuildObjCDictionaryLiteral(SourceRange SR,
}
if (!DictionaryWithObjectsMethod) {
- Diag(SR.getBegin(), diag::err_undeclared_dictwithobjects) << Sel;
+ // FIXME: Is there a better way to avoid quotes than using getName()?
+ Diag(SR.getBegin(), diag::err_undeclared_boxing_method)
+ << Sel << NSDictionaryDecl->getName();
return ExprError();
}
}