diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2011-09-28 20:22:05 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2011-09-28 20:22:05 +0000 |
commit | 600ba208abad989710ff3ad7cbe3ab0a9f77ed06 (patch) | |
tree | a243afa564e4b0b88ed2f22c1eb21dcaf0ab8e0a | |
parent | 094d8e3b56e1e6ce1f0fdbccfc8ac1464e5095c7 (diff) | |
download | bcm5719-llvm-600ba208abad989710ff3ad7cbe3ab0a9f77ed06.tar.gz bcm5719-llvm-600ba208abad989710ff3ad7cbe3ab0a9f77ed06.zip |
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
llvm-svn: 140717
-rw-r--r-- | clang/lib/Sema/SemaOverload.cpp | 17 | ||||
-rw-r--r-- | clang/test/SemaObjCXX/arc-nsconsumed-errors.mm | 20 |
2 files changed, 37 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp index 07091e69620..63d4f5ade3f 100644 --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/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/clang/test/SemaObjCXX/arc-nsconsumed-errors.mm b/clang/test/SemaObjCXX/arc-nsconsumed-errors.mm new file mode 100644 index 00000000000..d1d4531c27d --- /dev/null +++ b/clang/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'}} |