]> granicus.if.org Git - clang/commitdiff
objc++ arc: Diagnose block pointer type mismatch when
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 28 Sep 2011 20:22:05 +0000 (20:22 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 28 Sep 2011 20:22:05 +0000 (20:22 +0000)
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

lib/Sema/SemaOverload.cpp
test/SemaObjCXX/arc-nsconsumed-errors.mm [new file with mode: 0644]

index 07091e696202183453adc41c38d8f7ccefaf81d3..63d4f5ade3fca55dde31539fbf6b4fb5eb5ae345 100644 (file)
@@ -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 (file)
index 0000000..d1d4531
--- /dev/null
@@ -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'}}