From: Fariborz Jahanian Date: Wed, 18 Jun 2014 23:52:49 +0000 (+0000) Subject: Objective-C ARC. Allow conversion of (void*) pointers to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=88a39adcf6cc703c363bcdf0ad979f2220e92ee9;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211243 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Sema.h b/include/clang/Sema/Sema.h index 085a482b13..953c90b15f 100644 --- a/include/clang/Sema/Sema.h +++ b/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/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 4b4cb6c7c0..58a0c76769 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/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/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 57e1681fe4..9fbf656b55 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/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/test/SemaObjC/arc.m b/test/SemaObjC/arc.m index 060af24fa0..ba7c09f4f9 100644 --- a/test/SemaObjC/arc.m +++ b/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); +}