forked from OSchip/llvm-project
objective-c arc: ARC IRGen correctly assumes result
type of generated call to super dealloc is 'void' and asserts if user's dealloc is not of 'void type. This rule must be enforced in clang front-end (with a fixit) if this is not the case, instead of asserting in CodeGen. // rdar://11987838 llvm-svn: 160993
This commit is contained in:
parent
63282aefb9
commit
b7f03c191c
|
@ -731,6 +731,9 @@ def warn_objc_property_attr_mutually_exclusive : Warning<
|
|||
def warn_objc_missing_super_dealloc : Warning<
|
||||
"method possibly missing a [super dealloc] call">,
|
||||
InGroup<ObjCMissingSuperCalls>;
|
||||
def error_dealloc_bad_result_type : Error<
|
||||
"dealloc return type must be correctly specified as 'void' under ARC, "
|
||||
"instead of %0">;
|
||||
def warn_objc_missing_super_finalize : Warning<
|
||||
"method possibly missing a [super finalize] call">,
|
||||
InGroup<ObjCMissingSuperCalls>;
|
||||
|
|
|
@ -197,7 +197,6 @@ static bool CheckARCMethodDecl(Sema &S, ObjCMethodDecl *method) {
|
|||
ObjCMethodFamily family = method->getMethodFamily();
|
||||
switch (family) {
|
||||
case OMF_None:
|
||||
case OMF_dealloc:
|
||||
case OMF_finalize:
|
||||
case OMF_retain:
|
||||
case OMF_release:
|
||||
|
@ -207,6 +206,24 @@ static bool CheckARCMethodDecl(Sema &S, ObjCMethodDecl *method) {
|
|||
case OMF_performSelector:
|
||||
return false;
|
||||
|
||||
case OMF_dealloc:
|
||||
if (!S.Context.hasSameType(method->getResultType(), S.Context.VoidTy)) {
|
||||
SourceRange ResultTypeRange;
|
||||
if (const TypeSourceInfo *ResultTypeInfo
|
||||
= method->getResultTypeSourceInfo())
|
||||
ResultTypeRange = ResultTypeInfo->getTypeLoc().getSourceRange();
|
||||
if (ResultTypeRange.isInvalid())
|
||||
S.Diag(method->getLocation(), diag::error_dealloc_bad_result_type)
|
||||
<< method->getResultType()
|
||||
<< FixItHint::CreateInsertion(method->getSelectorLoc(0), "(void)");
|
||||
else
|
||||
S.Diag(method->getLocation(), diag::error_dealloc_bad_result_type)
|
||||
<< method->getResultType()
|
||||
<< FixItHint::CreateReplacement(ResultTypeRange, "void");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
case OMF_init:
|
||||
// If the method doesn't obey the init rules, don't bother annotating it.
|
||||
if (S.checkInitMethod(method, QualType()))
|
||||
|
|
|
@ -53,9 +53,8 @@ void func(Foo *p) {
|
|||
@end
|
||||
|
||||
@implementation Baz
|
||||
- dealloc {
|
||||
- (void) dealloc {
|
||||
[_foo release];
|
||||
return 0;
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
|
@ -49,9 +49,6 @@ void func(Foo *p) {
|
|||
@end
|
||||
|
||||
@implementation Baz
|
||||
- dealloc {
|
||||
return 0;
|
||||
}
|
||||
@end
|
||||
|
||||
#define RELEASE_MACRO(x) [x release]
|
||||
|
|
|
@ -58,9 +58,8 @@ void func(Foo *p) {
|
|||
@end
|
||||
|
||||
@implementation Baz
|
||||
- dealloc {
|
||||
- (void) dealloc {
|
||||
[_foo release];
|
||||
return 0;
|
||||
}
|
||||
@end
|
||||
|
||||
|
|
|
@ -54,9 +54,6 @@ void func(Foo *p) {
|
|||
@end
|
||||
|
||||
@implementation Baz
|
||||
- dealloc {
|
||||
return 0;
|
||||
}
|
||||
@end
|
||||
|
||||
void block_test(Foo *p) {
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -verify %s
|
||||
// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fsyntax-only -fobjc-arc -fblocks -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
|
||||
// rdar://11987838
|
||||
|
||||
@protocol NSObject
|
||||
- dealloc; // expected-error {{return type must be correctly specified as 'void' under ARC, instead of 'id'}}
|
||||
// CHECK: fix-it:"{{.*}}":{6:3-6:3}:"(void)"
|
||||
@end
|
||||
|
||||
@protocol Foo <NSObject> @end
|
||||
|
||||
@interface Root <Foo>
|
||||
@end
|
||||
|
||||
@interface Baz : Root {
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation Baz
|
||||
- (id) dealloc { // expected-error {{return type must be correctly specified as 'void' under ARC, instead of 'id'}}
|
||||
// CHECK: fix-it:"{{.*}}":{20:5-20:7}:"void"
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in New Issue