[cfe-commits] r60842 - in /cfe/trunk: lib/AST/ASTContext.cpp test/Sema/block-call.c test/SemaObjC/blocks.m
Steve Naroff
snaroff at apple.com
Wed Dec 10 09:50:35 PST 2008
Author: snaroff
Date: Wed Dec 10 11:49:55 2008
New Revision: 60842
URL: http://llvm.org/viewvc/llvm-project?rev=60842&view=rev
Log:
Fix <rdar://problem/6418623> Bogus block type compatibility warning.
Added:
cfe/trunk/test/SemaObjC/blocks.m
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/test/Sema/block-call.c
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=60842&r1=60841&r2=60842&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Dec 10 11:49:55 2008
@@ -1920,7 +1920,13 @@
/// FIXME: When the dust settles on this integration, fold this into mergeTypes.
///
bool ASTContext::typesAreBlockCompatible(QualType lhs, QualType rhs) {
- return getCanonicalType(lhs) == getCanonicalType(rhs);
+ const FunctionType *lbase = lhs->getAsFunctionType();
+ const FunctionType *rbase = rhs->getAsFunctionType();
+ const FunctionTypeProto *lproto = dyn_cast<FunctionTypeProto>(lbase);
+ const FunctionTypeProto *rproto = dyn_cast<FunctionTypeProto>(rbase);
+ if (lproto && rproto)
+ return !mergeTypes(lhs, rhs).isNull();
+ return false;
}
/// areCompatVectorTypes - Return true if the two specified vector types are
@@ -2179,6 +2185,19 @@
return RHS;
return getPointerType(ResultType);
}
+ case Type::BlockPointer:
+ {
+ // Merge two block pointer types, while trying to preserve typedef info
+ QualType LHSPointee = LHS->getAsBlockPointerType()->getPointeeType();
+ QualType RHSPointee = RHS->getAsBlockPointerType()->getPointeeType();
+ QualType ResultType = mergeTypes(LHSPointee, RHSPointee);
+ if (ResultType.isNull()) return QualType();
+ if (getCanonicalType(LHSPointee) == getCanonicalType(ResultType))
+ return LHS;
+ if (getCanonicalType(RHSPointee) == getCanonicalType(ResultType))
+ return RHS;
+ return getBlockPointerType(ResultType);
+ }
case Type::ConstantArray:
{
const ConstantArrayType* LCAT = getAsConstantArrayType(LHS);
Modified: cfe/trunk/test/Sema/block-call.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-call.c?rev=60842&r1=60841&r2=60842&view=diff
==============================================================================
--- cfe/trunk/test/Sema/block-call.c (original)
+++ cfe/trunk/test/Sema/block-call.c Wed Dec 10 11:49:55 2008
@@ -24,7 +24,7 @@
int * (^IPCC2) () = IPCC; // expected-warning {{incompatible block pointer types initializing 'int *const (^)()', expected 'int *(^)()'}}
- int (^IPCC3) (const int) = PFR; // expected-warning {{incompatible block pointer types initializing 'int (^)(int)', expected 'int (^)(int const)'}}
+ int (^IPCC3) (const int) = PFR;
int (^IPCC4) (int, char (^CArg) (double));
Added: cfe/trunk/test/SemaObjC/blocks.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/blocks.m?rev=60842&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/blocks.m (added)
+++ cfe/trunk/test/SemaObjC/blocks.m Wed Dec 10 11:49:55 2008
@@ -0,0 +1,22 @@
+// RUN: clang -fsyntax-only -verify -fblocks %s
+ at protocol NSObject;
+
+void bar(id(^)(void));
+void foo(id <NSObject>(^objectCreationBlock)(void)) {
+ return bar(objectCreationBlock);
+}
+
+void bar2(id(*)(void));
+void foo2(id <NSObject>(*objectCreationBlock)(void)) {
+ return bar2(objectCreationBlock);
+}
+
+void bar3(id(*)());
+void foo3(id (*objectCreationBlock)(int)) {
+ return bar3(objectCreationBlock);
+}
+
+void bar4(id(^)());
+void foo4(id (^objectCreationBlock)(int)) {
+ return bar4(objectCreationBlock); // expected-warning{{incompatible block pointer types passing 'id (^)(int)', expected 'id (^)()'}}
+}
More information about the cfe-commits
mailing list