[cfe-commits] r156832 - in /cfe/trunk: lib/Sema/SemaObjCProperty.cpp test/SemaObjC/property-ivar-mismatch.m
Fariborz Jahanian
fjahanian at apple.com
Tue May 15 11:12:52 PDT 2012
Author: fjahanian
Date: Tue May 15 13:12:51 2012
New Revision: 156832
URL: http://llvm.org/viewvc/llvm-project?rev=156832&view=rev
Log:
objc: avoid duplicate diagnostics on certain type mismatches
between property and its backing ivar.
Modified:
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/test/SemaObjC/property-ivar-mismatch.m
Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=156832&r1=156831&r2=156832&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Tue May 15 13:12:51 2012
@@ -658,6 +658,7 @@
}
ObjCIvarDecl *Ivar = 0;
bool CompleteTypeErr = false;
+ bool compat = true;
// Check that we have a valid, previously declared ivar for @synthesize
if (Synthesize) {
// @synthesize
@@ -773,8 +774,8 @@
QualType IvarType = Context.getCanonicalType(Ivar->getType());
// Check that type of property and its ivar are type compatible.
- if (Context.getCanonicalType(PropertyIvarType) != IvarType) {
- bool compat = false;
+ if (!Context.hasSameType(PropertyIvarType, IvarType)) {
+ compat = false;
if (isa<ObjCObjectPointerType>(PropertyIvarType)
&& isa<ObjCObjectPointerType>(IvarType))
compat =
@@ -794,19 +795,20 @@
// Note! I deliberately want it to fall thru so, we have a
// a property implementation and to avoid future warnings.
}
-
- // FIXME! Rules for properties are somewhat different that those
- // for assignments. Use a new routine to consolidate all cases;
- // specifically for property redeclarations as well as for ivars.
- QualType lhsType =Context.getCanonicalType(PropertyIvarType).getUnqualifiedType();
- QualType rhsType =Context.getCanonicalType(IvarType).getUnqualifiedType();
- if (lhsType != rhsType &&
- lhsType->isArithmeticType()) {
- Diag(PropertyDiagLoc, diag::error_property_ivar_type)
- << property->getDeclName() << PropType
- << Ivar->getDeclName() << IvarType;
- Diag(Ivar->getLocation(), diag::note_ivar_decl);
- // Fall thru - see previous comment
+ else {
+ // FIXME! Rules for properties are somewhat different that those
+ // for assignments. Use a new routine to consolidate all cases;
+ // specifically for property redeclarations as well as for ivars.
+ QualType lhsType =Context.getCanonicalType(PropertyIvarType).getUnqualifiedType();
+ QualType rhsType =Context.getCanonicalType(IvarType).getUnqualifiedType();
+ if (lhsType != rhsType &&
+ lhsType->isArithmeticType()) {
+ Diag(PropertyDiagLoc, diag::error_property_ivar_type)
+ << property->getDeclName() << PropType
+ << Ivar->getDeclName() << IvarType;
+ Diag(Ivar->getLocation(), diag::note_ivar_decl);
+ // Fall thru - see previous comment
+ }
}
// __weak is explicit. So it works on Canonical type.
if ((PropType.isObjCGCWeak() && !IvarType.isObjCGCWeak() &&
@@ -840,7 +842,7 @@
: ObjCPropertyImplDecl::Dynamic),
Ivar, PropertyIvarLoc);
- if (CompleteTypeErr)
+ if (CompleteTypeErr || !compat)
PIDecl->setInvalidDecl();
if (ObjCMethodDecl *getterMethod = property->getGetterMethodDecl()) {
Modified: cfe/trunk/test/SemaObjC/property-ivar-mismatch.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/property-ivar-mismatch.m?rev=156832&r1=156831&r2=156832&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/property-ivar-mismatch.m (original)
+++ cfe/trunk/test/SemaObjC/property-ivar-mismatch.m Tue May 15 13:12:51 2012
@@ -12,3 +12,15 @@
@synthesize prop = ivar; // expected-error {{type of property 'prop' ('int') does not match type of ivar 'ivar' ('char')}}
@end
+
+ at interface Test5
+{
+ void * _P; // expected-note {{ivar is declared here}}
+}
+ at property int P;
+ at end
+
+ at implementation Test5
+ at synthesize P=_P; // expected-error {{ype of property 'P' ('int') does not match type of ivar '_P' ('void *')}}
+ at end
+
More information about the cfe-commits
mailing list