From dffafded6c13a9b308433c85a1156501e65bb6e8 Mon Sep 17 00:00:00 2001 From: John McCall Date: Wed, 13 Jul 2011 18:26:47 +0000 Subject: [PATCH] Don't crash if defining -dealloc in a category. llvm-svn: 135054 --- clang/lib/CodeGen/CGObjC.cpp | 8 +++++--- clang/test/CodeGenObjC/arc.m | 10 ++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp index f64ff9766f9c..426cca00140c 100644 --- a/clang/lib/CodeGen/CGObjC.cpp +++ b/clang/lib/CodeGen/CGObjC.cpp @@ -220,11 +220,13 @@ namespace { struct FinishARCDealloc : EHScopeStack::Cleanup { void Emit(CodeGenFunction &CGF, Flags flags) { const ObjCMethodDecl *method = cast(CGF.CurCodeDecl); - const ObjCImplementationDecl *impl - = cast(method->getDeclContext()); + + const ObjCImplDecl *impl = cast(method->getDeclContext()); const ObjCInterfaceDecl *iface = impl->getClassInterface(); if (!iface->getSuperClass()) return; + bool isCategory = isa(impl); + // Call [super dealloc] if we have a superclass. llvm::Value *self = CGF.LoadObjCSelf(); @@ -233,7 +235,7 @@ struct FinishARCDealloc : EHScopeStack::Cleanup { CGF.getContext().VoidTy, method->getSelector(), iface, - /*is category*/ false, + isCategory, self, /*is class msg*/ false, args, diff --git a/clang/test/CodeGenObjC/arc.m b/clang/test/CodeGenObjC/arc.m index 2431866ef0fa..407b3eb77167 100644 --- a/clang/test/CodeGenObjC/arc.m +++ b/clang/test/CodeGenObjC/arc.m @@ -1542,3 +1542,13 @@ void test54(int first, ...) { // CHECK: call void @objc_release // CHECK: ret void } + +// PR10228 +@interface Test55Base @end +@interface Test55 : Test55Base @end +@implementation Test55 (Category) +- (void) dealloc {} +@end +// CHECK: define internal void @"\01-[Test55(Category) dealloc]"( +// CHECK-NOT: ret +// CHECK: call void bitcast (i8* ({{%.*}}*, i8*, ...)* @objc_msgSendSuper2 to void ({{%.*}}*, i8*)*)(