r175850 - objective-C arc: Diagnostic can not say to use bridge
Fariborz Jahanian
fjahanian at apple.com
Thu Feb 21 17:22:48 PST 2013
Author: fjahanian
Date: Thu Feb 21 19:22:48 2013
New Revision: 175850
URL: http://llvm.org/viewvc/llvm-project?rev=175850&view=rev
Log:
objective-C arc: Diagnostic can not say to use bridge
casts with c++ named casts. Change notes to say use
bridge with c-style cast instead. // rdar://12788838
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/SemaObjCXX/arc-unbridged-cast.mm
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=175850&r1=175849&r2=175850&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Feb 21 19:22:48 2013
@@ -3854,12 +3854,20 @@ def err_arc_cast_requires_bridge : Error
"requires a bridged cast">;
def note_arc_bridge : Note<
"use __bridge to convert directly (no change in ownership)">;
+def note_arc_cstyle_bridge : Note<
+ "use __bridge with C-style cast to convert directly (no change in ownership)">;
def note_arc_bridge_transfer : Note<
"use %select{__bridge_transfer|CFBridgingRelease call}1 to transfer "
"ownership of a +1 %0 into ARC">;
+def note_arc_cstyle_bridge_transfer : Note<
+ "use __bridge_transfer with C-style cast to transfer "
+ "ownership of a +1 %0 into ARC">;
def note_arc_bridge_retained : Note<
"use %select{__bridge_retained|CFBridgingRetain call}1 to make an "
"ARC object available as a +1 %0">;
+def note_arc_cstyle_bridge_retained : Note<
+ "use __bridge_retained with C-style cast to make an "
+ "ARC object available as a +1 %0">;
} // ARC Casting category
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=175850&r1=175849&r2=175850&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Thu Feb 21 19:22:48 2013
@@ -2925,15 +2925,22 @@ diagnoseObjCARCConversion(Sema &S, Sourc
assert(CreateRule != ACC_bottom && "This cast should already be accepted.");
if (CreateRule != ACC_plusOne)
{
- DiagnosticBuilder DiagB = S.Diag(noteLoc, diag::note_arc_bridge);
+ DiagnosticBuilder DiagB =
+ (CCK != Sema::CCK_OtherCast) ? S.Diag(noteLoc, diag::note_arc_bridge)
+ : S.Diag(noteLoc, diag::note_arc_cstyle_bridge);
+
addFixitForObjCARCConversion(S, DiagB, CCK, afterLParen,
castType, castExpr, "__bridge ", 0);
}
if (CreateRule != ACC_plusZero)
{
- DiagnosticBuilder DiagB = S.Diag(br ? castExpr->getExprLoc() : noteLoc,
- diag::note_arc_bridge_transfer)
- << castExprType << br;
+ DiagnosticBuilder DiagB =
+ (CCK == Sema::CCK_OtherCast && !br) ?
+ S.Diag(noteLoc, diag::note_arc_cstyle_bridge_transfer) << castExprType :
+ S.Diag(br ? castExpr->getExprLoc() : noteLoc,
+ diag::note_arc_bridge_transfer)
+ << castExprType << br;
+
addFixitForObjCARCConversion(S, DiagB, CCK, afterLParen,
castType, castExpr, "__bridge_transfer ",
br ? "CFBridgingRelease" : 0);
@@ -2958,15 +2965,21 @@ diagnoseObjCARCConversion(Sema &S, Sourc
assert(CreateRule != ACC_bottom && "This cast should already be accepted.");
if (CreateRule != ACC_plusOne)
{
- DiagnosticBuilder DiagB = S.Diag(noteLoc, diag::note_arc_bridge);
+ DiagnosticBuilder DiagB =
+ (CCK != Sema::CCK_OtherCast) ? S.Diag(noteLoc, diag::note_arc_bridge)
+ : S.Diag(noteLoc, diag::note_arc_cstyle_bridge);
addFixitForObjCARCConversion(S, DiagB, CCK, afterLParen,
castType, castExpr, "__bridge ", 0);
}
if (CreateRule != ACC_plusZero)
{
- DiagnosticBuilder DiagB = S.Diag(br ? castExpr->getExprLoc() : noteLoc,
- diag::note_arc_bridge_retained)
- << castType << br;
+ DiagnosticBuilder DiagB =
+ (CCK == Sema::CCK_OtherCast && !br) ?
+ S.Diag(noteLoc, diag::note_arc_cstyle_bridge_retained) << castType :
+ S.Diag(br ? castExpr->getExprLoc() : noteLoc,
+ diag::note_arc_bridge_retained)
+ << castType << br;
+
addFixitForObjCARCConversion(S, DiagB, CCK, afterLParen,
castType, castExpr, "__bridge_retained ",
br ? "CFBridgingRetain" : 0);
Modified: cfe/trunk/test/SemaObjCXX/arc-unbridged-cast.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/arc-unbridged-cast.mm?rev=175850&r1=175849&r2=175850&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/arc-unbridged-cast.mm (original)
+++ cfe/trunk/test/SemaObjCXX/arc-unbridged-cast.mm Thu Feb 21 19:22:48 2013
@@ -108,3 +108,12 @@ void testTakerFunctions(id string) {
takeCFVariadicAudited(1, (CFStringRef) string);
takeCFConsumedAudited((CFStringRef) string); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'CFStringRef'}} expected-note {{use __bridge to}} expected-note {{use CFBridgingRetain call to}}
}
+
+// rdar://12788838
+id obj;
+
+void rdar12788838() {
+ void *foo = reinterpret_cast<void *>(obj); // expected-error {{cast of Objective-C pointer type 'id' to C pointer type 'void *' requires a bridged cast}} \
+ // expected-note {{use __bridge with C-style cast to convert directly}} \
+ // expected-note {{use CFBridgingRetain call to make an ARC object available as a +1 'void *'}}
+}
More information about the cfe-commits
mailing list