[cfe-commits] r156713 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaExprObjC.cpp test/SemaObjC/objc-literal-nsnumber.m test/SemaObjC/objc-literal-sig.m
Jordy Rose
jediknil at belkadan.com
Sat May 12 08:53:41 PDT 2012
Author: jrose
Date: Sat May 12 10:53:41 2012
New Revision: 156713
URL: http://llvm.org/viewvc/llvm-project?rev=156713&view=rev
Log:
Don't crash on boxed strings when +stringWithUTF8String: is missing.
Also, unify some diagnostics for boxed expressions that have the same form.
Fixes PR12804.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m
cfe/trunk/test/SemaObjC/objc-literal-sig.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=156713&r1=156712&r2=156713&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat May 12 10:53:41 2012
@@ -1545,12 +1545,8 @@
def err_undeclared_nsdictionary : Error<
"NSDictionary must be available to use Objective-C dictionary "
"literals">;
-def err_undeclared_arraywithobjects : Error<
- "declaration of %0 is missing in NSArray class">;
-def err_undeclared_dictwithobjects : Error<
- "declaration of %0 is missing in NSDictionary class">;
-def err_undeclared_nsnumber_method : Error<
- "declaration of %0 is missing in NSNumber class">;
+def err_undeclared_boxing_method : Error<
+ "declaration of %0 is missing in %1 class">;
def err_objc_literal_method_sig : Error<
"literal construction method %0 has incompatible signature">;
def note_objc_literal_method_param : Note<
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=156713&r1=156712&r2=156713&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Sat May 12 10:53:41 2012
@@ -214,7 +214,9 @@
}
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 @@
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 @@
}
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 @@
}
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();
}
}
Modified: cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m?rev=156713&r1=156712&r2=156713&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m (original)
+++ cfe/trunk/test/SemaObjC/objc-literal-nsnumber.m Sat May 12 10:53:41 2012
@@ -83,3 +83,7 @@
BOOL radar11231426() {
return __objc_yes;
}
+
+id stringBoxingNoSuchMethod(const char *str) {
+ return @(str); // expected-error {{declaration of 'stringWithUTF8String:' is missing in NSString class}}
+}
Modified: cfe/trunk/test/SemaObjC/objc-literal-sig.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objc-literal-sig.m?rev=156713&r1=156712&r2=156713&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/objc-literal-sig.m (original)
+++ cfe/trunk/test/SemaObjC/objc-literal-sig.m Sat May 12 10:53:41 2012
@@ -19,6 +19,10 @@
+ (int)numberWithBool:(BOOL)value; // expected-note{{method returns unexpected type 'int' (should be an object type)}}
@end
+ at interface NSString
++ (char)stringWithUTF8String:(const char *)value; // expected-note{{method returns unexpected type 'char' (should be an object type)}}
+ at end
+
@interface NSArray
@end
@@ -37,4 +41,5 @@
(void)@__objc_yes; // expected-error{{literal construction method 'numberWithBool:' has incompatible signature}}
id array = @[ @17 ]; // expected-error{{literal construction method 'arrayWithObjects:count:' has incompatible signature}}
id dict = @{ @"hello" : @17 }; // expected-error{{literal construction method 'dictionaryWithObjects:forKeys:count:' has incompatible signature}}
+ id str = @("hello"); // expected-error{{literal construction method 'stringWithUTF8String:' has incompatible signature}}
}
More information about the cfe-commits
mailing list