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

Fariborz Jahanian fjahanian at apple.com
Tue Jun 2 13:58:59 PDT 2009


Author: fjahanian
Date: Tue Jun  2 15:58:58 2009
New Revision: 72737

URL: http://llvm.org/viewvc/llvm-project?rev=72737&view=rev
Log:
Diagnose misuse of __strong attribute in a redeclaration.

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=72737&r1=72736&r2=72737&view=diff

==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Tue Jun  2 15:58:58 2009
@@ -3033,13 +3033,15 @@
   if (RHSClass == Type::ExtQual) {
     QualType::GCAttrTypes GCAttr = RHSCan.getObjCGCAttr();
     if (GCAttr != QualType::GCNone) {
+      QualType::GCAttrTypes GCLHSAttr = LHSCan.getObjCGCAttr();
       // __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)
+      // __strong attribue is redundant if other decl is an objective-c 
+      // object pointer (or decorated with __strong attribute); otherwise
+      // issue error.
+      if ((GCAttr == QualType::Weak && GCLHSAttr != GCAttr) ||
+          (GCAttr == QualType::Strong && GCLHSAttr != GCAttr &&
+           LHSCan->isPointerType() && !isObjCObjectPointerType(LHSCan) &&
+           !isObjCIdStructType(LHSCan->getAsPointerType()->getPointeeType())))
         return QualType();
           
       RHS = QualType(cast<ExtQualType>(RHS.getDesugaredType())->getBaseType(),
@@ -3059,10 +3061,15 @@
     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)
+      // __strong attribue is redundant if other decl is an objective-c 
+      // object pointer (or decorated with __strong attribute); otherwise
+      // issue error.
+      if ((GCAttr == QualType::Weak && GCRHSAttr != GCAttr) ||
+          (GCAttr == QualType::Strong && GCRHSAttr != GCAttr &&
+           RHSCan->isPointerType() && !isObjCObjectPointerType(RHSCan) &&
+           !isObjCIdStructType(RHSCan->getAsPointerType()->getPointeeType())))
         return QualType();
+      
       LHS = QualType(cast<ExtQualType>(LHS.getDesugaredType())->getBaseType(),
                      LHS.getCVRQualifiers());
       QualType Result = mergeTypes(LHS, RHS);

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=72737&r1=72736&r2=72737&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 15:58:58 2009
@@ -16,3 +16,15 @@
 extern id p3;	// expected-note {{previous definition is here}}
 extern __weak id p3;	// expected-error {{redefinition of 'p3' with a different type}}
 
+extern void *p4; // expected-note {{previous definition is here}}
+extern void * __strong p4; // expected-error {{redefinition of 'p4' with a different type}}
+
+extern id p5;
+extern __strong id p5;
+
+extern char* __strong p6; // expected-note {{previous definition is here}}
+extern char* p6; // expected-error {{redefinition of 'p6' with a different type}}
+
+// FIXME. We do not issue error here because we don't put the attribute on the pointer type.
+extern __strong char* p7; 
+extern char* p7; 





More information about the cfe-commits mailing list