[cfe-commits] r68873 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaObjC/blocks.m test/SemaObjC/invalid-objc-decls-1.m test/SemaObjC/method-bad-param.m
Chris Lattner
sabre at nondot.org
Sat Apr 11 12:17:25 PDT 2009
Author: lattner
Date: Sat Apr 11 14:17:25 2009
New Revision: 68873
URL: http://llvm.org/viewvc/llvm-project?rev=68873&view=rev
Log:
diagnose attempts to return objc interfaces by-value from C functions.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaObjC/blocks.m
cfe/trunk/test/SemaObjC/invalid-objc-decls-1.m
cfe/trunk/test/SemaObjC/method-bad-param.m
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=68873&r1=68872&r2=68873&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Apr 11 14:17:25 2009
@@ -1891,7 +1891,15 @@
R->getAsFunctionType()->getResultType(),
diag::err_abstract_type_in_decl,
AbstractReturnType))
- InvalidDecl = true;
+ InvalidDecl = true;
+
+ // Do not allow returning a objc interface by-value.
+ if (R->getAsFunctionType()->getResultType()->isObjCInterfaceType()) {
+ Diag(D.getIdentifierLoc(),
+ diag::err_object_cannot_be_passed_returned_by_value) << 0
+ << R->getAsFunctionType()->getResultType();
+ InvalidDecl = true;
+ }
bool isVirtualOkay = false;
FunctionDecl *NewFD;
Modified: cfe/trunk/test/SemaObjC/blocks.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/blocks.m?rev=68873&r1=68872&r2=68873&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/blocks.m (original)
+++ cfe/trunk/test/SemaObjC/blocks.m Sat Apr 11 14:17:25 2009
@@ -31,6 +31,13 @@
return bar6(objectCreationBlock); // expected-warning{{incompatible block pointer types passing 'id (^)()', expected 'id (^)(int)'}}
}
-void foo67(id (^x)(int)) {
+void foo7(id (^x)(int)) {
if (x) { }
}
+
+ at interface itf
+ at end
+
+void foo8() {
+ ^(itf x) {};
+}
Modified: cfe/trunk/test/SemaObjC/invalid-objc-decls-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/invalid-objc-decls-1.m?rev=68873&r1=68872&r2=68873&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/invalid-objc-decls-1.m (original)
+++ cfe/trunk/test/SemaObjC/invalid-objc-decls-1.m Sat Apr 11 14:17:25 2009
@@ -27,7 +27,8 @@
}
@end
-Super foo(Super parm1) { // expected-error{{Objective-C interface type 'Super' cannot be passed by value}}
+Super foo( // expected-error{{Objective-C interface type 'Super' cannot be returned by value}}
+ 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;
}
Modified: cfe/trunk/test/SemaObjC/method-bad-param.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-bad-param.m?rev=68873&r1=68872&r2=68873&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/method-bad-param.m (original)
+++ cfe/trunk/test/SemaObjC/method-bad-param.m Sat Apr 11 14:17:25 2009
@@ -21,3 +21,4 @@
@end
void somefunc(foo x) {} // expected-error {{Objective-C interface type 'foo' cannot be passed by value}}
+foo somefunc2() {} // expected-error {{Objective-C interface type 'foo' cannot be returned by value}}
More information about the cfe-commits
mailing list