Skip to content

Commit

Permalink
Only accept __bridge_retain in system headers, as Doug suggested.
Browse files Browse the repository at this point in the history
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133300 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rjmccall committed Jun 17, 2011
1 parent 1816442 commit b64915a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
5 changes: 5 additions & 0 deletions include/clang/Basic/DiagnosticParseKinds.td
Expand Up @@ -263,6 +263,11 @@ def warn_objc_protocol_qualifier_missing_id : Warning<
def err_objc_unknown_at : Error<"expected an Objective-C directive after '@'">;
def err_illegal_super_cast : Error<
"cannot cast 'super' (it isn't an expression)">;

let CategoryName = "Automatic Reference Counting Issue" in {
def err_arc_bridge_retain : Error<
"unknown cast annotation __bridge_retain; did you mean __bridge_retained?">;
}

def err_objc_illegal_visibility_spec : Error<
"illegal visibility specification">;
Expand Down
22 changes: 17 additions & 5 deletions lib/Parse/ParseExpr.cpp
Expand Up @@ -1781,17 +1781,29 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
(Tok.is(tok::kw___bridge) ||
Tok.is(tok::kw___bridge_transfer) ||
Tok.is(tok::kw___bridge_retained) ||
Tok.is(tok::kw___bridge_retain))) { // FIXME: temporary workaround
Tok.is(tok::kw___bridge_retain))) {
tok::TokenKind tokenKind = Tok.getKind();
SourceLocation BridgeKeywordLoc = ConsumeToken();

// Parse an Objective-C ARC ownership cast expression.
ObjCBridgeCastKind Kind;
if (Tok.is(tok::kw___bridge))
if (tokenKind == tok::kw___bridge)
Kind = OBC_Bridge;
else if (Tok.is(tok::kw___bridge_transfer))
else if (tokenKind == tok::kw___bridge_transfer)
Kind = OBC_BridgeTransfer;
else
else if (tokenKind == tok::kw___bridge_retained)
Kind = OBC_BridgeRetained;
else {
// As a hopefully temporary workaround, allow __bridge_retain as
// a synonym for __bridge_retained, but only in system headers.
assert(tokenKind == tok::kw___bridge_retain);
Kind = OBC_BridgeRetained;
if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc))
Diag(BridgeKeywordLoc, diag::err_arc_bridge_retain)
<< FixItHint::CreateReplacement(BridgeKeywordLoc,
"__bridge_retained");
}

SourceLocation BridgeKeywordLoc = ConsumeToken();
TypeResult Ty = ParseTypeName();
SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, OpenLoc);
ExprResult SubExpr = ParseCastExpression(false, false, ParsedType());
Expand Down
10 changes: 10 additions & 0 deletions test/SemaObjC/Inputs/arc-system-header.h
Expand Up @@ -40,3 +40,13 @@ extern struct Test6 *const kMagicConstant;
@interface Test7
@property id *prop;
@end







static inline void *test8(id ptr) {
return (__bridge_retain void*) ptr;
}
2 changes: 1 addition & 1 deletion test/SemaObjC/arc-bridged-cast.m
Expand Up @@ -30,7 +30,7 @@ void to_cf(id obj) {
CFStringRef cf4 = (__bridge CFStringRef)CreateNSString();

// rdar://problem/9629566 - temporary workaround
CFTypeRef cf5 = (__bridge_retain CFTypeRef)CreateSomething();
CFTypeRef cf5 = (__bridge_retain CFTypeRef)CreateSomething(); // expected-error {{unknown cast annotation __bridge_retain; did you mean __bridge_retained?}}
}

void fixits() {
Expand Down
2 changes: 2 additions & 0 deletions test/SemaObjC/arc-system-header.m
Expand Up @@ -46,3 +46,5 @@ void test7(Test7 *p) {
[p setProp: 0]; // expected-error {{'setProp:' is unavailable: this system declaration uses an unsupported type}}
}
#endif

// test8 in header

0 comments on commit b64915a

Please sign in to comment.