[cfe-commits] r72733 - in /cfe/trunk: lib/AST/ASTContext.cpp test/SemaObjC/objc2-merge-gc-attribue-decl.m

Fariborz Jahanian fjahanian at apple.com
Tue Jun 2 11:32:00 PDT 2009


Author: fjahanian
Date: Tue Jun  2 13:32:00 2009
New Revision: 72733

URL: http://llvm.org/viewvc/llvm-project?rev=72733&view=rev
Log:
Issue diagnostics on __weak attribute mismatch.
Fixes an error recovery issue which caused a crash.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/test/SemaObjC/objc2-merge-gc-attribue-decl.m

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=72733&r1=72732&r2=72733&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Jun  2 13:32:00 2009
@@ -2785,7 +2785,7 @@
     }
     // Non-pointers have none gc'able attribute regardless of the attribute
     // set on them.
-    else if (!isObjCObjectPointerType(Ty) && !Ty->isPointerType())
+    else if (!Ty->isPointerType() && !isObjCObjectPointerType(Ty))
       return QualType::GCNone;
   }
   return GCAttrs;
@@ -3033,26 +3033,45 @@
   if (RHSClass == Type::ExtQual) {
     QualType::GCAttrTypes GCAttr = RHSCan.getObjCGCAttr();
     if (GCAttr != QualType::GCNone) {
+      // __weak attribute must appear on both declarations. 
+      // FIXME. __strong attribue is redundant if other decl is an objective-c 
+      // object pointer (or decorated with __strong attribute). We can't issue 
+      // diagnostic on __strong mismatch becuase 'id' may not be
+      // available but only with its canonical type at this point. Will 
+      // visit this when 'id' becomes a concrete type.
+      if (GCAttr == QualType::Weak && LHSCan.getObjCGCAttr() != GCAttr)
+        return QualType();
+          
       RHS = QualType(cast<ExtQualType>(RHS.getDesugaredType())->getBaseType(),
                      RHS.getCVRQualifiers());
       QualType Result = mergeTypes(LHS, RHS);
-      if (Result.getObjCGCAttr() == QualType::GCNone)
-        Result = getObjCGCQualType(Result, GCAttr);
-      else if (Result.getObjCGCAttr() != GCAttr)
-        Result = QualType();
+      if (!Result.isNull()) {
+        if (Result.getObjCGCAttr() == QualType::GCNone)
+          Result = getObjCGCQualType(Result, GCAttr);
+        else if (Result.getObjCGCAttr() != GCAttr)
+          Result = QualType();
+      }
       return Result;
     }
   }
   if (LHSClass == Type::ExtQual) {
     QualType::GCAttrTypes GCAttr = LHSCan.getObjCGCAttr();
     if (GCAttr != QualType::GCNone) {
+      QualType::GCAttrTypes GCRHSAttr = RHSCan.getObjCGCAttr();
+      // __weak attribute must appear on both declarations. __strong
+      // attribue is redundant if other decl is an objective-c object pointer.
+      // See above FIXME comment.
+      if (GCAttr == QualType::Weak && GCRHSAttr != GCAttr)
+        return QualType();
       LHS = QualType(cast<ExtQualType>(LHS.getDesugaredType())->getBaseType(),
                      LHS.getCVRQualifiers());
       QualType Result = mergeTypes(LHS, RHS);
-      if (Result.getObjCGCAttr() == QualType::GCNone)
-        Result = getObjCGCQualType(Result, GCAttr);
-      else if (Result.getObjCGCAttr() != GCAttr)
-        Result = QualType();
+      if (!Result.isNull()) {
+        if (Result.getObjCGCAttr() == QualType::GCNone)
+          Result = getObjCGCQualType(Result, GCAttr);
+        else if (Result.getObjCGCAttr() != GCAttr)
+          Result = QualType();
+      }
       return Result;
     }
   }

Modified: cfe/trunk/test/SemaObjC/objc2-merge-gc-attribue-decl.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/objc2-merge-gc-attribue-decl.m?rev=72733&r1=72732&r2=72733&view=diff

==============================================================================
--- cfe/trunk/test/SemaObjC/objc2-merge-gc-attribue-decl.m (original)
+++ cfe/trunk/test/SemaObjC/objc2-merge-gc-attribue-decl.m Tue Jun  2 13:32:00 2009
@@ -10,3 +10,9 @@
 extern id CFRunLoopGetMain();
 extern __strong id CFRunLoopGetMain();
 
+extern __weak id WLoopGetMain(); // expected-note {{previous declaration is here}}
+extern id WLoopGetMain();	// expected-error {{conflicting types for 'WLoopGetMain'}}
+
+extern id p3;	// expected-note {{previous definition is here}}
+extern __weak id p3;	// expected-error {{redefinition of 'p3' with a different type}}
+





More information about the cfe-commits mailing list