[cfe-commits] r95245 - in /cfe/trunk: lib/Sema/SemaCXXCast.cpp test/SemaObjCXX/reinterpret-cast-objc-pointertype.mm
Fariborz Jahanian
fjahanian at apple.com
Wed Feb 3 12:32:31 PST 2010
Author: fjahanian
Date: Wed Feb 3 14:32:31 2010
New Revision: 95245
URL: http://llvm.org/viewvc/llvm-project?rev=95245&view=rev
Log:
Patch to allow reinterpret_cast on objective-c pointers.
(partial fix for radar 7591784).
Added:
cfe/trunk/test/SemaObjCXX/reinterpret-cast-objc-pointertype.mm
Modified:
cfe/trunk/lib/Sema/SemaCXXCast.cpp
Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=95245&r1=95244&r2=95245&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Wed Feb 3 14:32:31 2010
@@ -204,7 +204,30 @@
T2 = T2PtrType->getPointeeType();
return true;
}
-
+ const ObjCObjectPointerType *T1ObjCPtrType =
+ T1->getAs<ObjCObjectPointerType>(),
+ *T2ObjCPtrType =
+ T2->getAs<ObjCObjectPointerType>();
+ if (T1ObjCPtrType) {
+ if (T2ObjCPtrType) {
+ T1 = T1ObjCPtrType->getPointeeType();
+ T2 = T2ObjCPtrType->getPointeeType();
+ return true;
+ }
+ else if (T2PtrType) {
+ T1 = T1ObjCPtrType->getPointeeType();
+ T2 = T2PtrType->getPointeeType();
+ return true;
+ }
+ }
+ else if (T2ObjCPtrType) {
+ if (T1PtrType) {
+ T2 = T2ObjCPtrType->getPointeeType();
+ T1 = T1PtrType->getPointeeType();
+ return true;
+ }
+ }
+
const MemberPointerType *T1MPType = T1->getAs<MemberPointerType>(),
*T2MPType = T2->getAs<MemberPointerType>();
if (T1MPType && T2MPType) {
@@ -225,9 +248,9 @@
// C++ 4.4. We piggyback on Sema::IsQualificationConversion for this, since
// the rules are non-trivial. So first we construct Tcv *...cv* as described
// in C++ 5.2.11p8.
- assert((SrcType->isPointerType() || SrcType->isMemberPointerType()) &&
+ assert((SrcType->isAnyPointerType() || SrcType->isMemberPointerType()) &&
"Source type is not pointer or pointer to member.");
- assert((DestType->isPointerType() || DestType->isMemberPointerType()) &&
+ assert((DestType->isAnyPointerType() || DestType->isMemberPointerType()) &&
"Destination type is not pointer or pointer to member.");
QualType UnwrappedSrcType = Self.Context.getCanonicalType(SrcType),
@@ -1083,10 +1106,8 @@
return TC_Failed;
}
- bool destIsPtr =
- CStyle? DestType->isAnyPointerType() : DestType->isPointerType();
- bool srcIsPtr =
- CStyle ? SrcType->isAnyPointerType() : SrcType->isPointerType();
+ bool destIsPtr = DestType->isAnyPointerType();
+ bool srcIsPtr = SrcType->isAnyPointerType();
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.
Added: cfe/trunk/test/SemaObjCXX/reinterpret-cast-objc-pointertype.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/reinterpret-cast-objc-pointertype.mm?rev=95245&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/reinterpret-cast-objc-pointertype.mm (added)
+++ cfe/trunk/test/SemaObjCXX/reinterpret-cast-objc-pointertype.mm Wed Feb 3 14:32:31 2010
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+ at interface NSString @end
+
+typedef const struct __CFString * CFStringRef;
+const NSString* fRef;
+
+CFStringRef func() {
+ return reinterpret_cast<CFStringRef>(fRef);
+}
+
+CFStringRef fRef1;
+
+const NSString* func1() {
+ return reinterpret_cast<const NSString*>(fRef1);
+}
+
+ at interface I @end
+const I *fRef2;
+
+const NSString* func2() {
+ return reinterpret_cast<const NSString*>(fRef2);
+}
More information about the cfe-commits
mailing list