summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2014-06-18 23:52:49 +0000
committerFariborz Jahanian <fjahanian@apple.com>2014-06-18 23:52:49 +0000
commitc03ef578eba2f43ee757bef205fd5a540076414f (patch)
treeb6a115ed50b84cccdcdeea57cbb1a8dddebcc825
parent2dfa00f6f276c700c479c1e1e3cb927c626cabe2 (diff)
downloadbcm5719-llvm-c03ef578eba2f43ee757bef205fd5a540076414f.tar.gz
bcm5719-llvm-c03ef578eba2f43ee757bef205fd5a540076414f.zip
Objective-C ARC. Allow conversion of (void*) pointers to
retainable ObjC pointers without requiring a bridge-cast in the context of pointer comparison as this is in effect a +0 context. // rdar://16627903 llvm-svn: 211243
-rw-r--r--clang/include/clang/Sema/Sema.h4
-rw-r--r--clang/lib/Sema/SemaExpr.cpp3
-rw-r--r--clang/lib/Sema/SemaExprObjC.cpp9
-rw-r--r--clang/test/SemaObjC/arc.m18
4 files changed, 28 insertions, 6 deletions
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 085a482b133..953c90b15fb 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7820,7 +7820,9 @@ public:
ARCConversionResult CheckObjCARCConversion(SourceRange castRange,
QualType castType, Expr *&op,
CheckedConversionKind CCK,
- bool DiagnoseCFAudited = false);
+ bool DiagnoseCFAudited = false,
+ BinaryOperatorKind Opc = BO_PtrMemD
+ );
Expr *stripARCUnbridgedCast(Expr *e);
void diagnoseARCUnbridgedCast(Expr *e);
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4b4cb6c7c0d..58a0c76769f 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -8149,7 +8149,8 @@ QualType Sema::CheckCompareOperands(ExprResult &LHS, ExprResult &RHS,
else {
Expr *E = RHS.get();
if (getLangOpts().ObjCAutoRefCount)
- CheckObjCARCConversion(SourceRange(), LHSType, E, CCK_ImplicitConversion);
+ CheckObjCARCConversion(SourceRange(), LHSType, E, CCK_ImplicitConversion, false,
+ Opc);
RHS = ImpCastExprToType(E, LHSType,
LPT ? CK_BitCast :CK_CPointerToObjCPointerCast);
}
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 57e1681fe4c..9fbf656b55a 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -3624,7 +3624,8 @@ Sema::CheckObjCBridgeRelatedConversions(SourceLocation Loc,
Sema::ARCConversionResult
Sema::CheckObjCARCConversion(SourceRange castRange, QualType castType,
Expr *&castExpr, CheckedConversionKind CCK,
- bool DiagnoseCFAudited) {
+ bool DiagnoseCFAudited,
+ BinaryOperatorKind Opc) {
QualType castExprType = castExpr->getType();
// For the purposes of the classification, we assume reference types
@@ -3718,8 +3719,10 @@ Sema::CheckObjCARCConversion(SourceRange castRange, QualType castType,
// instead.
if (!DiagnoseCFAudited || exprACTC != ACTC_retainable ||
castACTC != ACTC_coreFoundation)
- diagnoseObjCARCConversion(*this, castRange, castType, castACTC,
- castExpr, castExpr, exprACTC, CCK);
+ if (!(exprACTC == ACTC_voidPtr && castACTC == ACTC_retainable &&
+ (Opc == BO_NE || Opc == BO_EQ)))
+ diagnoseObjCARCConversion(*this, castRange, castType, castACTC,
+ castExpr, castExpr, exprACTC, CCK);
return ACR_okay;
}
diff --git a/clang/test/SemaObjC/arc.m b/clang/test/SemaObjC/arc.m
index 060af24fa0d..ba7c09f4f9d 100644
--- a/clang/test/SemaObjC/arc.m
+++ b/clang/test/SemaObjC/arc.m
@@ -285,7 +285,7 @@ void test11(id op, void *vp) {
b = (nil == vp);
b = (vp == op); // expected-error {{implicit conversion of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use CFBridgingRetain call}}
- b = (op == vp); // expected-error {{implicit conversion of C pointer type 'void *' to Objective-C pointer type 'id' requires a bridged cast}} expected-note {{use __bridge}} expected-note {{use CFBridgingRelease call}}
+ b = (op == vp);
}
void test12(id collection) {
@@ -782,3 +782,19 @@ void foo(NSArray *array) {
}
}
}
+
+// rdar://16627903
+extern void abort();
+#define TKAssertEqual(a, b) do{\
+ __typeof(a) a_res = (a);\
+ __typeof(b) b_res = (b);\
+ if ((a_res) != (b_res)) {\
+ abort();\
+ }\
+}while(0)
+
+int garf() {
+ id object;
+ TKAssertEqual(object, nil);
+ TKAssertEqual(object, (id)nil);
+}
OpenPOWER on IntegriCloud