[cfe-commits] r149298 - in /cfe/trunk: lib/CodeGen/CGObjCMac.cpp test/CodeGenObjC/ns_consume_null_check.m
Fariborz Jahanian
fjahanian at apple.com
Mon Jan 30 15:39:30 PST 2012
Author: fjahanian
Date: Mon Jan 30 17:39:30 2012
New Revision: 149298
URL: http://llvm.org/viewvc/llvm-project?rev=149298&view=rev
Log:
test for a v-table dispatch that consumes an
argument. twik to support the test case.
// rdar://10444476
Added:
cfe/trunk/test/CodeGenObjC/ns_consume_null_check.m
Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=149298&r1=149297&r2=149298&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Mon Jan 30 17:39:30 2012
@@ -5816,6 +5816,20 @@
messageRef->setAlignment(16);
messageRef->setSection("__DATA, __objc_msgrefs, coalesced");
}
+
+ bool requiresnullCheck = false;
+ if (CGM.getLangOptions().ObjCAutoRefCount && method)
+ for (ObjCMethodDecl::param_const_iterator i = method->param_begin(),
+ e = method->param_end(); i != e; ++i) {
+ const ParmVarDecl *ParamDecl = (*i);
+ if (ParamDecl->hasAttr<NSConsumedAttr>()) {
+ if (!nullReturn.NullBB)
+ nullReturn.init(CGF, arg0);
+ requiresnullCheck = true;
+ break;
+ }
+ }
+
llvm::Value *mref =
CGF.Builder.CreateBitCast(messageRef, ObjCTypes.MessageRefPtrTy);
@@ -5833,8 +5847,8 @@
llvm::PointerType::getUnqual(fnType));
RValue result = CGF.EmitCall(fnInfo, callee, returnSlot, args);
- CallArgList CallArgs;
- return nullReturn.complete(CGF, result, resultType, CallArgs, 0);
+ return nullReturn.complete(CGF, result, resultType, formalArgs,
+ requiresnullCheck ? method : 0);
}
/// Generate code for a message send expression in the nonfragile abi.
Added: cfe/trunk/test/CodeGenObjC/ns_consume_null_check.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/ns_consume_null_check.m?rev=149298&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/ns_consume_null_check.m (added)
+++ cfe/trunk/test/CodeGenObjC/ns_consume_null_check.m Mon Jan 30 17:39:30 2012
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -fobjc-arc -fobjc-dispatch-method=mixed -o - %s | FileCheck %s
+// rdar://10444476
+
+ at interface NSObject
+- (id) new;
+ at end
+
+ at interface MyObject : NSObject
+- (char)isEqual:(id) __attribute__((ns_consumed)) object;
+ at end
+
+MyObject *x;
+
+void foo()
+{
+ id obj = [NSObject new];
+ [x isEqual : obj];
+}
+
+// CHECK: [[TMP:%.*]] = alloca i8
+// CHECK: [[FIVE:%.*]] = call i8* @objc_retain
+// CHECK-NEXT: [[SIX:%.*]] = bitcast
+// CHECK-NEXT: [[SEVEN:%.*]] = icmp eq i8* [[SIX]], null
+// CHECK-NEXT: br i1 [[SEVEN]], label [[NULLINIT:%.*]], label [[CALL_LABEL:%.*]]
+// CHECK: %msgSend_fn = load i8** getelementptr inbounds
+// CHECK-NEXT: [[EIGHT:%.*]] = bitcast i8* %msgSend_fn
+// CHECK-NEXT: [[CALL:%.*]] = call signext i8 [[EIGHT]]
+// CHECK-NEXT store i8 [[CALL]], i8* [[TMP]]
+// CHECK-NEXT br label [[CONT:%.*]]
+// CHECK: call void @objc_release(i8* [[FIVE]]) nounwind
+// CHECK-NEXT: call void @llvm.memset
+// CHECK-NEXT br label [[CONT]]
More information about the cfe-commits
mailing list