[cfe-commits] r91570 - in /cfe/trunk: lib/Sema/SemaOverload.cpp test/SemaObjCXX/objc-pointer-conv.mm
Fariborz Jahanian
fjahanian at apple.com
Wed Dec 16 15:13:33 PST 2009
Author: fjahanian
Date: Wed Dec 16 17:13:33 2009
New Revision: 91570
URL: http://llvm.org/viewvc/llvm-project?rev=91570&view=rev
Log:
Allow pointer convesion of an objective-c pointer to
'void *' to mimic gcc's behavior. (fixes radar 7477351).
Added:
cfe/trunk/test/SemaObjCXX/objc-pointer-conv.mm
Modified:
cfe/trunk/lib/Sema/SemaOverload.cpp
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=91570&r1=91569&r2=91570&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Dec 16 17:13:33 2009
@@ -915,6 +915,25 @@
Quals));
}
+/// BuildSimilarlyQualifiedObjCObjectPointerType - In a pointer conversion from
+/// the FromType, which is an objective-c pointer, to ToType, which may or may
+/// not have the right set of qualifiers.
+static QualType
+BuildSimilarlyQualifiedObjCObjectPointerType(QualType FromType,
+ QualType ToType,
+ ASTContext &Context) {
+ QualType CanonFromType = Context.getCanonicalType(FromType);
+ QualType CanonToType = Context.getCanonicalType(ToType);
+ Qualifiers Quals = CanonFromType.getQualifiers();
+
+ // Exact qualifier match -> return the pointer type we're converting to.
+ if (CanonToType.getLocalQualifiers() == Quals)
+ return ToType;
+
+ // Just build a canonical type that has the right qualifiers.
+ return Context.getQualifiedType(CanonToType.getLocalUnqualifiedType(), Quals);
+}
+
static bool isNullPointerConstantForConversion(Expr *Expr,
bool InOverloadResolution,
ASTContext &Context) {
@@ -992,13 +1011,20 @@
return true;
}
- // Beyond this point, both types need to be pointers.
+ // Beyond this point, both types need to be pointers
+ // , including objective-c pointers.
+ QualType ToPointeeType = ToTypePtr->getPointeeType();
+ if (FromType->isObjCObjectPointerType() && ToPointeeType->isVoidType()) {
+ ConvertedType = BuildSimilarlyQualifiedObjCObjectPointerType(FromType,
+ ToType, Context);
+ return true;
+
+ }
const PointerType *FromTypePtr = FromType->getAs<PointerType>();
if (!FromTypePtr)
return false;
QualType FromPointeeType = FromTypePtr->getPointeeType();
- QualType ToPointeeType = ToTypePtr->getPointeeType();
// An rvalue of type "pointer to cv T," where T is an object type,
// can be converted to an rvalue of type "pointer to cv void" (C++
Added: cfe/trunk/test/SemaObjCXX/objc-pointer-conv.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/objc-pointer-conv.mm?rev=91570&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/objc-pointer-conv.mm (added)
+++ cfe/trunk/test/SemaObjCXX/objc-pointer-conv.mm Wed Dec 16 17:13:33 2009
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+typedef const void * VoidStar;
+
+typedef struct __CFDictionary * CFMDRef;
+
+void RandomFunc(CFMDRef theDict, const void *key, const void *value);
+
+ at interface Foo
+- (void)_apply:(void (*)(const void *, const void *, void *))func context:(void *)context;
+- (void)a:(id *)objects b:(id *)keys;
+ at end
+
+ at implementation Foo
+- (void)_apply:(void (*)(const void *, const void *, void *))func context:(void *)context {
+ id item;
+ id obj;
+ func(item, obj, context);
+}
+
+- (void)a:(id *)objects b:(id *)keys {
+ VoidStar dict;
+ id key;
+ RandomFunc((CFMDRef)dict, key, objects[3]);
+}
+ at end
More information about the cfe-commits
mailing list