[llvm-branch-commits] [cfe-branch] r81026 - in /cfe/branches/Apple/Dib: include/clang/AST/Decl.h lib/AST/Decl.cpp lib/CodeGen/CGExprAgg.cpp lib/CodeGen/CGObjCGNU.cpp lib/CodeGen/CGObjCMac.cpp lib/CodeGen/CGObjCRuntime.h lib/CodeGen/CodeGenFunction.h lib/Frontend/PCHReaderDecl.cpp lib/Frontend/PCHWriterDecl.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExpr.cpp test/CodeGenObjC/objc-gc-aggr-assign.m test/SemaObjC/invalid-objc-decls-1.m test/SemaObjC/property-expression-error.m

Fariborz Jahanian fjahanian at apple.com
Fri Sep 4 12:22:18 PDT 2009


Author: fjahanian
Date: Fri Sep  4 14:22:18 2009
New Revision: 81026

URL: http://llvm.org/viewvc/llvm-project?rev=81026&view=rev
Log:
radars 7030914, 7030927 and 7136038
brought over from mainline.


Added:
    cfe/branches/Apple/Dib/test/CodeGenObjC/objc-gc-aggr-assign.m
    cfe/branches/Apple/Dib/test/SemaObjC/property-expression-error.m
Modified:
    cfe/branches/Apple/Dib/include/clang/AST/Decl.h
    cfe/branches/Apple/Dib/lib/AST/Decl.cpp
    cfe/branches/Apple/Dib/lib/CodeGen/CGExprAgg.cpp
    cfe/branches/Apple/Dib/lib/CodeGen/CGObjCGNU.cpp
    cfe/branches/Apple/Dib/lib/CodeGen/CGObjCMac.cpp
    cfe/branches/Apple/Dib/lib/CodeGen/CGObjCRuntime.h
    cfe/branches/Apple/Dib/lib/CodeGen/CodeGenFunction.h
    cfe/branches/Apple/Dib/lib/Frontend/PCHReaderDecl.cpp
    cfe/branches/Apple/Dib/lib/Frontend/PCHWriterDecl.cpp
    cfe/branches/Apple/Dib/lib/Sema/SemaDecl.cpp
    cfe/branches/Apple/Dib/lib/Sema/SemaDeclObjC.cpp
    cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp
    cfe/branches/Apple/Dib/test/SemaObjC/invalid-objc-decls-1.m

Modified: cfe/branches/Apple/Dib/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/include/clang/AST/Decl.h?rev=81026&r1=81025&r2=81026&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/include/clang/AST/Decl.h (original)
+++ cfe/branches/Apple/Dib/include/clang/AST/Decl.h Fri Sep  4 14:22:18 2009
@@ -1028,6 +1028,10 @@
   /// AnonymousStructOrUnion - Whether this is the type of an
   /// anonymous struct or union.
   bool AnonymousStructOrUnion : 1;
+  
+  /// HasObjectMember - This is true if this struct has at least one
+  /// member containing an object 
+  bool HasObjectMember : 1;
 
 protected:
   RecordDecl(Kind DK, TagKind TK, DeclContext *DC,
@@ -1061,6 +1065,9 @@
     AnonymousStructOrUnion = Anon;
   }
 
+  bool hasObjectMember() const { return HasObjectMember; }
+  void setHasObjectMember (bool val) { HasObjectMember = val; }
+  
   /// \brief Determines whether this declaration represents the
   /// injected class name.
   ///

Modified: cfe/branches/Apple/Dib/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/AST/Decl.cpp?rev=81026&r1=81025&r2=81026&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/AST/Decl.cpp (original)
+++ cfe/branches/Apple/Dib/lib/AST/Decl.cpp Fri Sep  4 14:22:18 2009
@@ -537,6 +537,7 @@
   : TagDecl(DK, TK, DC, L, Id) {
   HasFlexibleArrayMember = false;
   AnonymousStructOrUnion = false;
+  HasObjectMember = false;
   assert(classof(static_cast<Decl*>(this)) && "Invalid Kind!");
 }
 

Modified: cfe/branches/Apple/Dib/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/CodeGen/CGExprAgg.cpp?rev=81026&r1=81025&r2=81026&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/branches/Apple/Dib/lib/CodeGen/CGExprAgg.cpp Fri Sep  4 14:22:18 2009
@@ -13,6 +13,7 @@
 
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
+#include "CGObjCRuntime.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/StmtVisitor.h"
@@ -244,6 +245,17 @@
     CGF.EmitObjCPropertySet(LHS.getKVCRefExpr(), 
                             RValue::getAggregate(AggLoc));
   } else {
+    if (CGF.getContext().getLangOptions().NeXTRuntime) {
+      QualType LHSTy = E->getLHS()->getType();
+      if (const RecordType *FDTTy = LHSTy.getTypePtr()->getAsRecordType())
+        if (FDTTy->getDecl()->hasObjectMember()) {
+          LValue RHS = CGF.EmitLValue(E->getRHS());
+          CGF.CGM.getObjCRuntime().EmitGCMemmoveCollectable(CGF, LHS.getAddress(), 
+                                      RHS.getAddress(),
+                                      CGF.getContext().getTypeSize(LHSTy) / 8);
+          return;
+        }
+    }
     // Codegen the RHS so that it stores directly into the LHS.
     CGF.EmitAggExpr(E->getRHS(), LHS.getAddress(), false /*FIXME: VOLATILE LHS*/);
     

Modified: cfe/branches/Apple/Dib/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/CodeGen/CGObjCGNU.cpp?rev=81026&r1=81025&r2=81026&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/branches/Apple/Dib/lib/CodeGen/CGObjCGNU.cpp Fri Sep  4 14:22:18 2009
@@ -146,6 +146,10 @@
                                     llvm::Value *src, llvm::Value *dest);
   virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
                                         llvm::Value *src, llvm::Value *dest);
+  virtual void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF,
+                                        llvm::Value *DestPtr, 
+                                        llvm::Value *SrcPtr,
+                                        unsigned long size);
   virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
                                       QualType ObjectTy,
                                       llvm::Value *BaseValue,
@@ -1116,6 +1120,13 @@
   return;
 }
 
+void CGObjCGNU::EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF,
+                                         llvm::Value *DestPtr, 
+                                         llvm::Value *SrcPtr,
+                                         unsigned long size) {
+  return;
+}
+
 LValue CGObjCGNU::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
                                        QualType ObjectTy,
                                        llvm::Value *BaseValue,

Modified: cfe/branches/Apple/Dib/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/CodeGen/CGObjCMac.cpp?rev=81026&r1=81025&r2=81026&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/branches/Apple/Dib/lib/CodeGen/CGObjCMac.cpp Fri Sep  4 14:22:18 2009
@@ -272,6 +272,16 @@
     return CGM.CreateRuntimeFunction(FTy, "objc_assign_ivar");
   }
   
+  /// GcMemmoveCollectableFn -- LLVM objc_memmove_collectable function.
+  llvm::Constant *GcMemmoveCollectableFn() {
+    // void *objc_memmove_collectable(void *dst, const void *src, size_t size)
+    std::vector<const llvm::Type*> Args(1, Int8PtrTy);
+    Args.push_back(Int8PtrTy);
+    Args.push_back(LongTy);
+    llvm::FunctionType *FTy = llvm::FunctionType::get(Int8PtrTy, Args, false);
+    return CGM.CreateRuntimeFunction(FTy, "objc_memmove_collectable");
+  }
+  
   /// GcAssignStrongCastFn -- LLVM objc_assign_strongCast function.
   llvm::Constant *getGcAssignStrongCastFn() {
     // id objc_assign_global(id, id *)
@@ -1064,6 +1074,9 @@
                                   llvm::Value *src, llvm::Value *dest);
   virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
                                         llvm::Value *src, llvm::Value *dest);
+  virtual void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF,
+                                        llvm::Value *dest, llvm::Value *src,
+                                        unsigned long size);
   
   virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
                                       QualType ObjectTy,
@@ -1264,6 +1277,9 @@
                                   llvm::Value *src, llvm::Value *dest);
   virtual void EmitObjCStrongCastAssign(CodeGen::CodeGenFunction &CGF,
                                         llvm::Value *src, llvm::Value *dest);
+  virtual void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF,
+                                        llvm::Value *dest, llvm::Value *src,
+                                        unsigned long size);
   virtual LValue EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
                                       QualType ObjectTy,
                                       llvm::Value *BaseValue,
@@ -2676,6 +2692,18 @@
   return;
 }
 
+void CGObjCMac::EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF,
+                                               llvm::Value *DestPtr, 
+                                               llvm::Value *SrcPtr,
+                                               unsigned long size) {
+  SrcPtr = CGF.Builder.CreateBitCast(SrcPtr, ObjCTypes.Int8PtrTy);
+  DestPtr = CGF.Builder.CreateBitCast(DestPtr, ObjCTypes.Int8PtrTy);
+  llvm::Value *N = llvm::ConstantInt::get(ObjCTypes.LongTy, size);
+  CGF.Builder.CreateCall3(ObjCTypes.GcMemmoveCollectableFn(),
+                          DestPtr, SrcPtr, N);
+  return;
+}
+
 /// EmitObjCValueForIvar - Code Gen for ivar reference.
 ///
 LValue CGObjCMac::EmitObjCValueForIvar(CodeGen::CodeGenFunction &CGF,
@@ -5225,6 +5253,19 @@
   return;
 }
 
+void CGObjCNonFragileABIMac::EmitGCMemmoveCollectable(
+                                         CodeGen::CodeGenFunction &CGF,
+                                         llvm::Value *DestPtr, 
+                                         llvm::Value *SrcPtr,
+                                         unsigned long size) {
+  SrcPtr = CGF.Builder.CreateBitCast(SrcPtr, ObjCTypes.Int8PtrTy);
+  DestPtr = CGF.Builder.CreateBitCast(DestPtr, ObjCTypes.Int8PtrTy);
+  llvm::Value *N = llvm::ConstantInt::get(ObjCTypes.LongTy, size);
+  CGF.Builder.CreateCall3(ObjCTypes.GcMemmoveCollectableFn(),
+                          DestPtr, SrcPtr, N);
+  return;
+}
+
 /// EmitObjCWeakRead - Code gen for loading value of a __weak
 /// object: objc_read_weak (id *src)
 ///

Modified: cfe/branches/Apple/Dib/lib/CodeGen/CGObjCRuntime.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/CodeGen/CGObjCRuntime.h?rev=81026&r1=81025&r2=81026&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/CodeGen/CGObjCRuntime.h (original)
+++ cfe/branches/Apple/Dib/lib/CodeGen/CGObjCRuntime.h Fri Sep  4 14:22:18 2009
@@ -189,6 +189,10 @@
   virtual llvm::Value *EmitIvarOffset(CodeGen::CodeGenFunction &CGF,
                                       const ObjCInterfaceDecl *Interface,
                                       const ObjCIvarDecl *Ivar) = 0;
+  virtual void EmitGCMemmoveCollectable(CodeGen::CodeGenFunction &CGF,
+                                        llvm::Value *DestPtr, 
+                                        llvm::Value *SrcPtr,
+                                        unsigned long) = 0;
 };
 
 /// Creates an instance of an Objective-C runtime class.  

Modified: cfe/branches/Apple/Dib/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/CodeGen/CodeGenFunction.h?rev=81026&r1=81025&r2=81026&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/branches/Apple/Dib/lib/CodeGen/CodeGenFunction.h Fri Sep  4 14:22:18 2009
@@ -728,6 +728,11 @@
   /// DestPtr is null, the value of the aggregate expression is not needed.
   void EmitAggExpr(const Expr *E, llvm::Value *DestPtr, bool VolatileDest);
 
+  /// EmitGCMemmoveCollectable - Emit special API for structs with object
+  /// pointers.
+  void EmitGCMemmoveCollectable(llvm::Value *DestPtr, llvm::Value *SrcPtr,
+                                unsigned long);
+
   /// EmitComplexExpr - Emit the computation of the specified expression of
   /// complex type, returning the result.
   ComplexPairTy EmitComplexExpr(const Expr *E);

Modified: cfe/branches/Apple/Dib/lib/Frontend/PCHReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Frontend/PCHReaderDecl.cpp?rev=81026&r1=81025&r2=81026&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Frontend/PCHReaderDecl.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Frontend/PCHReaderDecl.cpp Fri Sep  4 14:22:18 2009
@@ -126,6 +126,7 @@
   VisitTagDecl(RD);
   RD->setHasFlexibleArrayMember(Record[Idx++]);
   RD->setAnonymousStructOrUnion(Record[Idx++]);
+  RD->setHasObjectMember(Record[Idx++]);
 }
 
 void PCHDeclReader::VisitValueDecl(ValueDecl *VD) {

Modified: cfe/branches/Apple/Dib/lib/Frontend/PCHWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Frontend/PCHWriterDecl.cpp?rev=81026&r1=81025&r2=81026&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Frontend/PCHWriterDecl.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Frontend/PCHWriterDecl.cpp Fri Sep  4 14:22:18 2009
@@ -123,6 +123,7 @@
   VisitTagDecl(D);
   Record.push_back(D->hasFlexibleArrayMember());
   Record.push_back(D->isAnonymousStructOrUnion());
+  Record.push_back(D->hasObjectMember());
   Code = pch::DECL_RECORD;
 }
 

Modified: cfe/branches/Apple/Dib/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Sema/SemaDecl.cpp?rev=81026&r1=81025&r2=81026&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Sema/SemaDecl.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Sema/SemaDecl.cpp Fri Sep  4 14:22:18 2009
@@ -3959,6 +3959,8 @@
           }
         }
       }
+      if (Record && FDTTy->getDecl()->hasObjectMember())
+        Record->setHasObjectMember(true);
     } else if (FDTy->isObjCInterfaceType()) {
       /// A field cannot be an Objective-c object
       Diag(FD->getLocation(), diag::err_statically_allocated_object);
@@ -3966,6 +3968,12 @@
       EnclosingDecl->setInvalidDecl();
       continue;
     }
+    else if (getLangOptions().ObjC1 &&
+             getLangOptions().getGCMode() != LangOptions::NonGC &&
+             Record &&
+             (Context.isObjCObjectPointerType(FD->getType()) ||
+              FD->getType().isObjCGCStrong()))
+      Record->setHasObjectMember(true);
     // Keep track of the number of named members.
     if (FD->getIdentifier())
       ++NumNamedMembers;

Modified: cfe/branches/Apple/Dib/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Sema/SemaDeclObjC.cpp?rev=81026&r1=81025&r2=81026&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Sema/SemaDeclObjC.cpp Fri Sep  4 14:22:18 2009
@@ -1846,6 +1846,9 @@
       } 
     }
 
+  if (T->isObjCInterfaceType())
+    Diag(FD.D.getIdentifierLoc(), diag::err_statically_allocated_object);
+
   DeclContext *DC = dyn_cast<DeclContext>(ClassDecl);
   assert(DC && "ClassDecl is not a DeclContext");
   ObjCPropertyDecl *PDecl = ObjCPropertyDecl::Create(Context, DC,

Modified: cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp?rev=81026&r1=81025&r2=81026&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp (original)
+++ cfe/branches/Apple/Dib/lib/Sema/SemaExpr.cpp Fri Sep  4 14:22:18 2009
@@ -4310,6 +4310,11 @@
     Diag(OpLoc, diag::err_typecheck_address_of)
       << "vector element" << op->getSourceRange();
     return QualType();
+  } else if (isa<ObjCPropertyRefExpr>(op)) {
+    // cannot take address of a property expression.
+    Diag(OpLoc, diag::err_typecheck_address_of)
+      << "property expression" << op->getSourceRange();
+    return QualType();
   } else if (dcl) { // C99 6.5.3.2p1
     // We have an lvalue with a decl. Make sure the decl is not declared
     // with the register storage-class specifier.

Added: cfe/branches/Apple/Dib/test/CodeGenObjC/objc-gc-aggr-assign.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/test/CodeGenObjC/objc-gc-aggr-assign.m?rev=81026&view=auto

==============================================================================
--- cfe/branches/Apple/Dib/test/CodeGenObjC/objc-gc-aggr-assign.m (added)
+++ cfe/branches/Apple/Dib/test/CodeGenObjC/objc-gc-aggr-assign.m Fri Sep  4 14:22:18 2009
@@ -0,0 +1,42 @@
+// RUN: clang-cc -fnext-runtime -fobjc-gc -emit-llvm -o %t %s &&
+// RUN: grep objc_memmove_collectable %t | grep call | count 2
+
+static int count;
+
+typedef struct S {
+   int ii;
+} SS;
+
+struct type_s {
+   SS may_recurse;
+   id id_val;
+};
+
+ at interface NamedObject
+{
+  struct type_s type_s_ivar;
+}
+- (void) setSome : (struct type_s) arg;
+- (struct type_s) getSome;
+ at property(assign) struct type_s aggre_prop;
+ at end
+
+ at implementation NamedObject 
+- (void) setSome : (struct type_s) arg
+  {
+     type_s_ivar = arg;
+  }
+- (struct type_s) getSome 
+  {
+    return type_s_ivar;
+  }
+ at synthesize aggre_prop = type_s_ivar;
+ at end
+
+struct type_s some = {{1234}, (id)0};
+
+struct type_s get(void)
+{
+  return some;
+}
+

Modified: cfe/branches/Apple/Dib/test/SemaObjC/invalid-objc-decls-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/test/SemaObjC/invalid-objc-decls-1.m?rev=81026&r1=81025&r2=81026&view=diff

==============================================================================
--- cfe/branches/Apple/Dib/test/SemaObjC/invalid-objc-decls-1.m (original)
+++ cfe/branches/Apple/Dib/test/SemaObjC/invalid-objc-decls-1.m Fri Sep  4 14:22:18 2009
@@ -32,3 +32,11 @@
 	Super p1; // expected-error{{interface type cannot be statically allocated}}
 	return p1;
 }
+
+ at interface NSMutableSet @end
+
+ at interface DVTDummyAnnotationProvider  
+  @property(readonly) NSMutableSet annotations;	// expected-error{{interface type cannot be statically allocated}}
+
+ at end
+

Added: cfe/branches/Apple/Dib/test/SemaObjC/property-expression-error.m
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/Dib/test/SemaObjC/property-expression-error.m?rev=81026&view=auto

==============================================================================
--- cfe/branches/Apple/Dib/test/SemaObjC/property-expression-error.m (added)
+++ cfe/branches/Apple/Dib/test/SemaObjC/property-expression-error.m Fri Sep  4 14:22:18 2009
@@ -0,0 +1,19 @@
+// RUN: clang-cc  -fsyntax-only -verify %s
+
+ at interface AddressMyProperties 
+{
+  unsigned index;
+}
+ at property unsigned index;
+ at end
+
+ at implementation AddressMyProperties
+ at synthesize index;
+ at end
+
+int main() {
+	AddressMyProperties *object;
+	&object.index; // expected-error {{address of property expression requested}}
+	return 0;
+}
+





More information about the llvm-branch-commits mailing list