[cfe-commits] r44897 - in /cfe/trunk: AST/ASTContext.cpp include/clang/AST/ASTContext.h test/Sema/incompatible-protocol-qualified-types.m
Fariborz Jahanian
fjahanian at apple.com
Tue Dec 11 17:00:24 PST 2007
Author: fjahanian
Date: Tue Dec 11 19:00:23 2007
New Revision: 44897
URL: http://llvm.org/viewvc/llvm-project?rev=44897&view=rev
Log:
Implemented type checking for pointer of objects of protocol-qualified types.
Note that incompatible-protocol-qualified-types.m is currently failing. This is
unrelated to this patch and Steve is looking at the general problem of not reporting
incompitible pointer types in return stetement..
Added:
cfe/trunk/test/Sema/incompatible-protocol-qualified-types.m
Modified:
cfe/trunk/AST/ASTContext.cpp
cfe/trunk/include/clang/AST/ASTContext.h
Modified: cfe/trunk/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/ASTContext.cpp?rev=44897&r1=44896&r2=44897&view=diff
==============================================================================
--- cfe/trunk/AST/ASTContext.cpp (original)
+++ cfe/trunk/AST/ASTContext.cpp Tue Dec 11 19:00:23 2007
@@ -1168,6 +1168,34 @@
return true; // FIXME: IMPLEMENT.
}
+bool ASTContext::QualifiedInterfaceTypesAreCompatible(QualType lhs,
+ QualType rhs) {
+ ObjcQualifiedInterfaceType *lhsQI =
+ dyn_cast<ObjcQualifiedInterfaceType>(lhs.getCanonicalType().getTypePtr());
+ assert(lhsQI && "QualifiedInterfaceTypesAreCompatible - bad lhs type");
+ ObjcQualifiedInterfaceType *rhsQI =
+ dyn_cast<ObjcQualifiedInterfaceType>(rhs.getCanonicalType().getTypePtr());
+ assert(rhsQI && "QualifiedInterfaceTypesAreCompatible - bad rhs type");
+ if (!interfaceTypesAreCompatible(QualType(lhsQI->getInterfaceType(), 0),
+ QualType(rhsQI->getInterfaceType(), 0)))
+ return false;
+ /* All protocols in lhs must have a presense in rhs. */
+ for (unsigned i =0; i < lhsQI->getNumProtocols(); i++) {
+ bool match = false;
+ ObjcProtocolDecl *lhsProto = lhsQI->getProtocols(i);
+ for (unsigned j = 0; j < rhsQI->getNumProtocols(); j++) {
+ ObjcProtocolDecl *rhsProto = rhsQI->getProtocols(j);
+ if (lhsProto == rhsProto) {
+ match = true;
+ break;
+ }
+ }
+ if (!match)
+ return false;
+ }
+ return true;
+}
+
bool ASTContext::vectorTypesAreCompatible(QualType lhs, QualType rhs) {
const VectorType *lVector = lhs->getAsVectorType();
const VectorType *rVector = rhs->getAsVectorType();
@@ -1331,6 +1359,8 @@
case Type::Vector:
case Type::OCUVector:
return vectorTypesAreCompatible(lcanon, rcanon);
+ case Type::ObjcQualifiedInterface:
+ return QualifiedInterfaceTypesAreCompatible(lcanon, rcanon);
default:
assert(0 && "unexpected type");
}
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=44897&r1=44896&r2=44897&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Tue Dec 11 19:00:23 2007
@@ -284,6 +284,7 @@
/// Objective-C specific type checking.
bool interfaceTypesAreCompatible(QualType, QualType);
+ bool QualifiedInterfaceTypesAreCompatible(QualType, QualType);
bool objcTypesAreCompatible(QualType, QualType);
bool isObjcIdType(QualType T) const {
if (!IdStructType) // ObjC isn't enabled
Added: cfe/trunk/test/Sema/incompatible-protocol-qualified-types.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/incompatible-protocol-qualified-types.m?rev=44897&view=auto
==============================================================================
--- cfe/trunk/test/Sema/incompatible-protocol-qualified-types.m (added)
+++ cfe/trunk/test/Sema/incompatible-protocol-qualified-types.m Tue Dec 11 19:00:23 2007
@@ -0,0 +1,40 @@
+// RUN: clang -fsyntax-only -verify %s
+
+ at protocol MyProto1
+ at end
+
+ at protocol MyProto2
+ at end
+
+ at interface INTF @end
+
+INTF <MyProto1> * Func(INTF <MyProto1, MyProto2> *p2)
+{
+ return p2;
+}
+
+
+INTF <MyProto1> * Func1(INTF <MyProto1, MyProto2> *p2)
+{
+ return p2;
+}
+
+INTF <MyProto1, MyProto2> * Func2(INTF <MyProto1> *p2)
+{
+ Func(p2); // expected-warning {{incompatible pointer types passing}}
+ return p2; // expected-warning {{incompatible pointer types passing}}
+}
+
+
+
+INTF <MyProto1> * Func3(INTF <MyProto2> *p2)
+{
+ return p2; // expected-warning {{incompatible pointer types passing}}
+}
+
+
+INTF <MyProto1, MyProto2> * Func4(INTF <MyProto2, MyProto1> *p2)
+{
+ return p2;
+}
+
More information about the cfe-commits
mailing list