diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 1 | ||||
-rw-r--r-- | lib/Sema/SemaCXXCast.cpp | 22 |
2 files changed, 15 insertions, 8 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index 0ad139af4c..f19aa273d9 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -798,6 +798,7 @@ Value *ScalarExprEmitter::EmitCastExpr(CastExpr *CE) { //assert(0 && "Unknown cast kind!"); break; + case CastExpr::CK_AnyPointerToObjCPointerCast: case CastExpr::CK_BitCast: { Value *Src = Visit(const_cast<Expr*>(E)); return Builder.CreateBitCast(Src, ConvertType(DestTy)); diff --git a/lib/Sema/SemaCXXCast.cpp b/lib/Sema/SemaCXXCast.cpp index c11b5fdd75..f9138902a6 100644 --- a/lib/Sema/SemaCXXCast.cpp +++ b/lib/Sema/SemaCXXCast.cpp @@ -539,6 +539,11 @@ static TryCastResult TryStaticCast(Sema &Self, Expr *&SrcExpr, return TC_Success; } } + else if (CStyle && DestType->isObjCObjectPointerType()) { + // allow c-style cast of objective-c pointers as they are pervasive. + Kind = CastExpr::CK_AnyPointerToObjCPointerCast; + return TC_Success; + } } } @@ -1053,8 +1058,10 @@ static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr, return TC_Failed; } - bool destIsPtr = DestType->isPointerType(); - bool srcIsPtr = SrcType->isPointerType(); + bool destIsPtr = + CStyle? DestType->isAnyPointerType() : DestType->isPointerType(); + bool srcIsPtr = + CStyle ? SrcType->isAnyPointerType() : SrcType->isPointerType(); if (!destIsPtr && !srcIsPtr) { // Except for std::nullptr_t->integer and lvalue->reference, which are // handled above, at least one of the two arguments must be a pointer. @@ -1106,7 +1113,11 @@ static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr, msg = diag::err_bad_cxx_cast_const_away; return TC_Failed; } - + if (CStyle && DestType->isObjCObjectPointerType()) { + Kind = CastExpr::CK_AnyPointerToObjCPointerCast; + return TC_Success; + } + // Not casting away constness, so the only remaining check is for compatible // pointer categories. Kind = CastExpr::CK_BitCast; @@ -1141,7 +1152,6 @@ static TryCastResult TryReinterpretCast(Sema &Self, Expr *SrcExpr, // Void pointers are not specified, but supported by every compiler out there. // So we finish by allowing everything that remains - it's got to be two // object pointers. - Kind = CastExpr::CK_BitCast; return TC_Success; } @@ -1160,10 +1170,6 @@ bool Sema::CXXCheckCStyleCast(SourceRange R, QualType CastTy, Expr *&CastExpr, if (CastTy->isDependentType() || CastExpr->isTypeDependent()) return false; - // allow c-style cast of objective-c pointers as they are pervasive. - if (CastTy->isObjCObjectPointerType()) - return false; - if (!CastTy->isLValueReferenceType() && !CastTy->isRecordType()) DefaultFunctionArrayConversion(CastExpr); |