aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2011-09-28 20:22:05 +0000
committerFariborz Jahanian <fjahanian@apple.com>2011-09-28 20:22:05 +0000
commitf9d9527a0f52937a1a99da465b42c3cfe080bc6a (patch)
treea1ff40e2c9405b5285d0f4264858c584af54fc87
parent9a9cddeaaebf3a84529a66c5e9212a555913084f (diff)
objc++ arc: Diagnose block pointer type mismatch when
some arguments types are ns_consumed and some otherwise matching types are not. This fixes the objc++ side only *auch*. // rdar://10187884 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140717 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaOverload.cpp17
-rw-r--r--test/SemaObjCXX/arc-nsconsumed-errors.mm20
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 07091e6962..63d4f5ade3 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -2074,6 +2074,23 @@ bool Sema::IsBlockPointerConversion(QualType FromType, QualType ToType,
// Argument types are too different. Abort.
return false;
}
+ if (LangOpts.ObjCAutoRefCount) {
+ if (FromFunctionType->hasAnyConsumedArgs() !=
+ ToFunctionType->hasAnyConsumedArgs())
+ return false;
+ FunctionProtoType::ExtProtoInfo FromEPI =
+ FromFunctionType->getExtProtoInfo();
+ FunctionProtoType::ExtProtoInfo ToEPI =
+ ToFunctionType->getExtProtoInfo();
+ if (FromEPI.ConsumedArguments && ToEPI.ConsumedArguments)
+ for (unsigned ArgIdx = 0, NumArgs = FromFunctionType->getNumArgs();
+ ArgIdx != NumArgs; ++ArgIdx) {
+ if (FromEPI.ConsumedArguments[ArgIdx] !=
+ ToEPI.ConsumedArguments[ArgIdx])
+ return false;
+ }
+ }
+
ConvertedType = ToType;
return true;
}
diff --git a/test/SemaObjCXX/arc-nsconsumed-errors.mm b/test/SemaObjCXX/arc-nsconsumed-errors.mm
new file mode 100644
index 0000000000..d1d4531c27
--- /dev/null
+++ b/test/SemaObjCXX/arc-nsconsumed-errors.mm
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fobjc-nonfragile-abi -fsyntax-only -fobjc-arc -verify -fblocks -triple x86_64-apple-darwin10.0.0 %s
+// rdar://10187884
+
+typedef void (^blk)(id, __attribute((ns_consumed)) id);
+typedef void (^blk1)(__attribute((ns_consumed))id, __attribute((ns_consumed)) id);
+blk a = ^void (__attribute((ns_consumed)) id, __attribute((ns_consumed)) id){}; // expected-error {{cannot initialize a variable of type '__strong blk'}}
+
+blk b = ^void (id, __attribute((ns_consumed)) id){};
+
+blk c = ^void (__attribute((ns_consumed)) id, __attribute((ns_consumed)) id){}; // expected-error {{cannot initialize a variable of type '__strong blk'}}
+
+blk d = ^void (id, id) {}; // expected-error {{cannot initialize a variable of type '__strong blk'}}
+
+blk1 a1 = ^void (__attribute((ns_consumed)) id, id){}; // expected-error {{cannot initialize a variable of type '__strong blk1'}}
+
+blk1 b2 = ^void (id, __attribute((ns_consumed)) id){}; // expected-error {{cannot initialize a variable of type '__strong blk1'}}
+
+blk1 c3 = ^void (__attribute((ns_consumed)) id, __attribute((ns_consumed)) id){};
+
+blk1 d4 = ^void (id, id) {}; // expected-error {{cannot initialize a variable of type '__strong blk1'}}