[cfe-commits] r134273 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/Sema/Sema.h lib/AST/ASTContext.cpp lib/Parse/ParseExprCXX.cpp lib/Sema/SemaCXXCast.cpp lib/Sema/SemaType.cpp test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp test/SemaObjCXX/arc-type-conversion.mm

Argyrios Kyrtzidis kyrtzidis at apple.com
Fri Jul 1 15:58:29 PDT 2011


On Jul 1, 2011, at 3:39 PM, Douglas Gregor wrote:

> 
> On Jul 1, 2011, at 3:22 PM, Argyrios Kyrtzidis wrote:
> 
>> Author: akirtzidis
>> Date: Fri Jul  1 17:22:50 2011
>> New Revision: 134273
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=134273&view=rev
>> Log:
>> [ARC] When casting from a pointer to an objective-c object with known ownership, if the
>> cast type has no ownership specified, implicitly "transfer" the ownership of the cast'ed type
>> to the cast type:
>> 
>> id x;
>> static_cast<NSString**>(&x); // Casting as (__strong NSString**).
>> 
>> This currently only works for C++ named casts, C casts to follow.
> 
> Nice! One comment below.
> 
>> Modified:
>>   cfe/trunk/include/clang/AST/ASTContext.h
>>   cfe/trunk/include/clang/Sema/Sema.h
>>   cfe/trunk/lib/AST/ASTContext.cpp
>>   cfe/trunk/lib/Parse/ParseExprCXX.cpp
>>   cfe/trunk/lib/Sema/SemaCXXCast.cpp
>>   cfe/trunk/lib/Sema/SemaType.cpp
>>   cfe/trunk/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p5.cpp
>>   cfe/trunk/test/SemaObjCXX/arc-type-conversion.mm
>> 
>> Modified: cfe/trunk/include/clang/AST/ASTContext.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=134273&r1=134272&r2=134273&view=diff
>> ==============================================================================
>> --- cfe/trunk/include/clang/AST/ASTContext.h (original)
>> +++ cfe/trunk/include/clang/AST/ASTContext.h Fri Jul  1 17:22:50 2011
>> @@ -1347,6 +1347,10 @@
>>  /// integer type.
>>  QualType getPromotedIntegerType(QualType PromotableType) const;
>> 
>> +  /// \brief Recurses in pointer/array types until it finds an objc retainable
>> +  /// type and returns its ownership.
>> +  Qualifiers::ObjCLifetime getInnerObjCOwnership(QualType T) const;
>> +
>>  /// \brief Whether this is a promotable bitfield reference according
>>  /// to C99 6.3.1.1p2, bullet 2 (and GCC extensions).
>>  ///
>> 
>> Modified: cfe/trunk/include/clang/Sema/Sema.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=134273&r1=134272&r2=134273&view=diff
>> ==============================================================================
>> --- cfe/trunk/include/clang/Sema/Sema.h (original)
>> +++ cfe/trunk/include/clang/Sema/Sema.h Fri Jul  1 17:22:50 2011
>> @@ -783,6 +783,7 @@
>>  QualType BuildParenType(QualType T);
>> 
>>  TypeSourceInfo *GetTypeForDeclarator(Declarator &D, Scope *S);
>> +  TypeSourceInfo *GetTypeForDeclaratorCast(Declarator &D, QualType FromTy);
>>  TypeSourceInfo *GetTypeSourceInfoForDeclarator(Declarator &D, QualType T,
>>                                               TypeSourceInfo *ReturnTypeInfo);
>>  /// \brief Package the given type and TSI into a ParsedType.
>> @@ -2825,7 +2826,7 @@
>>  ExprResult ActOnCXXNamedCast(SourceLocation OpLoc,
>>                               tok::TokenKind Kind,
>>                               SourceLocation LAngleBracketLoc,
>> -                               ParsedType Ty,
>> +                               Declarator &D,
>>                               SourceLocation RAngleBracketLoc,
>>                               SourceLocation LParenLoc,
>>                               Expr *E,
>> 
>> Modified: cfe/trunk/lib/AST/ASTContext.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=134273&r1=134272&r2=134273&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/AST/ASTContext.cpp (original)
>> +++ cfe/trunk/lib/AST/ASTContext.cpp Fri Jul  1 17:22:50 2011
>> @@ -3512,6 +3512,25 @@
>>  return (PromotableSize != IntSize) ? IntTy : UnsignedIntTy;
>> }
>> 
>> +/// \brief Recurses in pointer/array types until it finds an objc retainable
>> +/// type and returns its ownership.
>> +Qualifiers::ObjCLifetime ASTContext::getInnerObjCOwnership(QualType T) const {
>> +  while (!T.isNull()) {
>> +    if (T.getObjCLifetime() != Qualifiers::OCL_None)
>> +      return T.getObjCLifetime();
>> +    if (T->isArrayType())
>> +      T = getBaseElementType(T);
>> +    else if (const PointerType *PT = T->getAs<PointerType>())
>> +      T = PT->getPointeeType();
>> +    else if (const ReferenceType *RT = T->getAs<ReferenceType>())
>> +      RT->getPointeeType();
> 
> You meant "T = RT->getPointeeType();" here.

Oops, thanks for reviewing!

> 
> 	- Doug
> 




More information about the cfe-commits mailing list