aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-11 19:08:56 +0000
committerChris Lattner <sabre@nondot.org>2009-04-11 19:08:56 +0000
commit2dd979fbd59938babbed76e2376116511b403c93 (patch)
tree8ff66db20db265fdb95647cfa8bd1e0987519f82
parente294d3fbaffcbc0cf5f16067ab31d2b2763d25e9 (diff)
Improve the 'cannot pass objc interface by value' diagnostic:
1) improve localizability by not passing english strings in. 2) improve location for arguments. 3) print the objc type being passed. Before: method-bad-param.m:15:1: error: Objective-C type cannot be passed by value -(void) my_method:(foo) my_param ^ after: method-bad-param.m:15:25: error: Objective-C interface type 'foo' cannot be passed by value -(void) my_method:(foo) my_param ^ git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68872 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td4
-rw-r--r--lib/Sema/SemaDecl.cpp4
-rw-r--r--lib/Sema/SemaDeclObjC.cpp35
-rw-r--r--test/Parser/objc-init.m2
-rw-r--r--test/SemaObjC/invalid-objc-decls-1.m2
-rw-r--r--test/SemaObjC/method-bad-param.m9
6 files changed, 28 insertions, 28 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 11a16a279f..1ed8098ad3 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -107,8 +107,8 @@ def err_builtin_definition : Error<"definition of builtin function %0">;
def ext_typedef_without_a_name : ExtWarn<"typedef requires a name">;
def err_statically_allocated_object : Error<
"Objective-C type cannot be statically allocated">;
-def err_object_cannot_be_by_value : Error<
- "Objective-C type cannot be %0 by value">;
+def err_object_cannot_be_passed_returned_by_value : Error<
+ "Objective-C interface type %1 cannot be %select{returned|passed}0 by value">;
def warn_enum_value_overflow : Warning<"overflow in enumeration value">;
def warn_pragma_pack_invalid_alignment : Warning<
"expected #pragma pack parameter to be '1', '2', '4', '8', or '16'">;
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 474c1e490e..5fe44d3089 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -2705,8 +2705,8 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
// Parameter declarators cannot be interface types. All ObjC objects are
// passed by reference.
if (T->isObjCInterfaceType()) {
- Diag(D.getIdentifierLoc(), diag::err_object_cannot_be_by_value)
- << "passed";
+ Diag(D.getIdentifierLoc(),
+ diag::err_object_cannot_be_passed_returned_by_value) << 1 << T;
New->setInvalidDecl();
}
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index d12fe63df1..7d4e6026a1 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -1415,8 +1415,8 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration(
// Methods cannot return interface types. All ObjC objects are
// passed by reference.
if (resultDeclType->isObjCInterfaceType()) {
- Diag(MethodLoc, diag::err_object_cannot_be_by_value)
- << "returned";
+ Diag(MethodLoc, diag::err_object_cannot_be_passed_returned_by_value)
+ << 0 << resultDeclType;
return DeclPtrTy();
}
} else // get the type for "id".
@@ -1435,38 +1435,37 @@ Sema::DeclPtrTy Sema::ActOnMethodDeclaration(
for (unsigned i = 0; i < Sel.getNumArgs(); i++) {
// FIXME: arg->AttrList must be stored too!
- QualType argType, originalArgType;
+ QualType ArgType, UnpromotedArgType;
if (ArgInfo[i].Type == 0) {
- argType = Context.getObjCIdType();
+ UnpromotedArgType = ArgType = Context.getObjCIdType();
} else {
- argType = QualType::getFromOpaquePtr(ArgInfo[i].Type);
+ UnpromotedArgType = ArgType = QualType::getFromOpaquePtr(ArgInfo[i].Type);
// Perform the default array/function conversions (C99 6.7.5.3p[7,8]).
- if (argType->isArrayType()) { // (char *[]) -> (char **)
- originalArgType = argType;
- argType = Context.getArrayDecayedType(argType);
- } else if (argType->isFunctionType())
- argType = Context.getPointerType(argType);
- else if (argType->isObjCInterfaceType()) {
- // FIXME: improve message to include type!
- Diag(MethodLoc, diag::err_object_cannot_be_by_value)
- << "passed";
+ if (ArgType->isArrayType()) { // (char *[]) -> (char **)
+ ArgType = Context.getArrayDecayedType(ArgType);
+ } else if (ArgType->isFunctionType())
+ ArgType = Context.getPointerType(ArgType);
+ else if (ArgType->isObjCInterfaceType()) {
+ Diag(ArgInfo[i].NameLoc,
+ diag::err_object_cannot_be_passed_returned_by_value)
+ << 1 << ArgType;
ObjCMethod->setInvalidDecl();
return DeclPtrTy();
}
}
ParmVarDecl* Param;
- if (originalArgType.isNull())
+ if (ArgType == UnpromotedArgType)
Param = ParmVarDecl::Create(Context, ObjCMethod,
SourceLocation(/*FIXME*/),
- ArgInfo[i].Name, argType,
+ ArgInfo[i].Name, ArgType,
VarDecl::None, 0);
else
Param = OriginalParmVarDecl::Create(Context, ObjCMethod,
SourceLocation(/*FIXME*/),
- ArgInfo[i].Name, argType,
- originalArgType,
+ ArgInfo[i].Name, ArgType,
+ UnpromotedArgType,
VarDecl::None, 0);
Param->setObjCDeclQualifier(
diff --git a/test/Parser/objc-init.m b/test/Parser/objc-init.m
index 8d74dfecbd..a91ac9cf28 100644
--- a/test/Parser/objc-init.m
+++ b/test/Parser/objc-init.m
@@ -14,7 +14,7 @@ void test1() {
id objects[] = {[NSNumber METH]};
}
-void test2(NSNumber x) { // expected-error {{Objective-C type cannot be passed by value}}
+void test2(NSNumber x) { // expected-error {{Objective-C interface type 'NSNumber' cannot be passed by value}}
id objects[] = {[x METH]};
}
diff --git a/test/SemaObjC/invalid-objc-decls-1.m b/test/SemaObjC/invalid-objc-decls-1.m
index b65c061546..1ef22a0851 100644
--- a/test/SemaObjC/invalid-objc-decls-1.m
+++ b/test/SemaObjC/invalid-objc-decls-1.m
@@ -27,7 +27,7 @@ struct whatever {
}
@end
-Super foo(Super parm1) { // expected-error{{Objective-C type cannot be passed by value}}
+Super foo(Super parm1) { // expected-error{{Objective-C interface type 'Super' cannot be passed by value}}
Super p1; // expected-error{{Objective-C type cannot be statically allocated}}
return p1;
}
diff --git a/test/SemaObjC/method-bad-param.m b/test/SemaObjC/method-bad-param.m
index 23fc675a4e..3667427d1a 100644
--- a/test/SemaObjC/method-bad-param.m
+++ b/test/SemaObjC/method-bad-param.m
@@ -7,16 +7,17 @@
@end
@interface bar
--(void) my_method:(foo) my_param; // expected-error {{Objective-C type cannot be passed by value}}
-- (foo)cccccc:(long)ddddd; // expected-error {{Objective-C type cannot be returned by value}}
+-(void) my_method:(foo) my_param; // expected-error {{Objective-C interface type 'foo' cannot be passed by value}}
+- (foo)cccccc:(long)ddddd; // expected-error {{Objective-C interface type 'foo' cannot be returned by value}}
@end
@implementation bar
--(void) my_method:(foo) my_param // expected-error {{Objective-C type cannot be passed by value}}
+-(void) my_method:(foo) my_param // expected-error {{Objective-C interface type 'foo' cannot be passed by value}}
{
}
-- (foo)cccccc:(long)ddddd // expected-error {{Objective-C type cannot be returned by value}}
+- (foo)cccccc:(long)ddddd // expected-error {{Objective-C interface type 'foo' cannot be returned by value}}
{
}
@end
+void somefunc(foo x) {} // expected-error {{Objective-C interface type 'foo' cannot be passed by value}}