[cfe-commits] r136103 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/FixIt/fixit-static-object-decl.m

Fariborz Jahanian fjahanian at apple.com
Tue Jul 26 10:58:54 PDT 2011


Author: fjahanian
Date: Tue Jul 26 12:58:54 2011
New Revision: 136103

URL: http://llvm.org/viewvc/llvm-project?rev=136103&view=rev
Log:
Provide fixit for static use of objective-c type
in few more places and in each instance, fix up
the type to the expected type. // rdar://9603056

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/FixIt/fixit-static-object-decl.m

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=136103&r1=136102&r2=136103&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Jul 26 12:58:54 2011
@@ -3939,7 +3939,8 @@
   if (T->isObjCObjectType()) {
     Diag(NewVD->getLocation(), diag::err_statically_allocated_object)
       << FixItHint::CreateInsertion(NewVD->getLocation(), "*");
-    return NewVD->setInvalidDecl();
+    T = Context.getObjCObjectPointerType(T);
+    NewVD->setType(T);
   }
 
   // Emit an error if an address space was applied to decl with local storage.
@@ -4179,8 +4180,18 @@
   if (R->getAs<FunctionType>()->getResultType()->isObjCObjectType()) {
     Diag(D.getIdentifierLoc(),
          diag::err_object_cannot_be_passed_returned_by_value) << 0
-    << R->getAs<FunctionType>()->getResultType();
-    D.setInvalidType();
+    << R->getAs<FunctionType>()->getResultType()
+    << FixItHint::CreateInsertion(D.getIdentifierLoc(), "*");
+    
+    QualType T = R->getAs<FunctionType>()->getResultType();
+    T = Context.getObjCObjectPointerType(T);
+    if (const FunctionProtoType *FPT = dyn_cast<FunctionProtoType>(R)) {
+      FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo();
+      R = Context.getFunctionType(T, FPT->arg_type_begin(),
+                                  FPT->getNumArgs(), EPI);
+    }
+    else if (isa<FunctionNoProtoType>(R))
+      R = Context.getFunctionNoProtoType(T);
   }
   
   FunctionDecl *NewFD;
@@ -6195,8 +6206,10 @@
   // passed by reference.
   if (T->isObjCObjectType()) {
     Diag(NameLoc,
-         diag::err_object_cannot_be_passed_returned_by_value) << 1 << T;
-    New->setInvalidDecl();
+         diag::err_object_cannot_be_passed_returned_by_value) << 1 << T
+      << FixItHint::CreateInsertion(NameLoc, "*");
+    T = Context.getObjCObjectPointerType(T);
+    New->setType(T);
   }
 
   // ISO/IEC TR 18037 S6.7.3: "The type of an object with automatic storage 
@@ -8403,10 +8416,10 @@
         Record->setHasObjectMember(true);
     } else if (FDTy->isObjCObjectType()) {
       /// A field cannot be an Objective-c object
-      Diag(FD->getLocation(), diag::err_statically_allocated_object);
-      FD->setInvalidDecl();
-      EnclosingDecl->setInvalidDecl();
-      continue;
+      Diag(FD->getLocation(), diag::err_statically_allocated_object)
+        << FixItHint::CreateInsertion(FD->getLocation(), "*");
+      QualType T = Context.getObjCObjectPointerType(FD->getType());
+      FD->setType(T);
     } 
     else if (!getLangOptions().CPlusPlus) {
       if (getLangOptions().ObjCAutoRefCount && Record && !ARCErrReported) {

Modified: cfe/trunk/test/FixIt/fixit-static-object-decl.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/FixIt/fixit-static-object-decl.m?rev=136103&r1=136102&r2=136103&view=diff
==============================================================================
--- cfe/trunk/test/FixIt/fixit-static-object-decl.m (original)
+++ cfe/trunk/test/FixIt/fixit-static-object-decl.m Tue Jul 26 12:58:54 2011
@@ -9,10 +9,21 @@
 // RUN: %clang_cc1 -fsyntax-only -Werror -x objective-c++ %t
 // rdar://9603056
 
+ at interface S @end
+
 @interface NSArray
+{
+ at public
+  S iS;
+}
 + (id) arrayWithObjects;
 @end
 
+NSArray func() {
+  NSArray P;
+  return P;
+}
+
 int main() {
   	NSArray pluginNames = [NSArray arrayWithObjects];
 }





More information about the cfe-commits mailing list