[cfe-commits] r59682 - in /cfe/trunk: include/clang/Basic/DiagnosticKinds.def lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h lib/Sema/SemaDeclAttr.cpp

Fariborz Jahanian fjahanian at apple.com
Wed Nov 19 16:15:42 PST 2008


Author: fjahanian
Date: Wed Nov 19 18:15:42 2008
New Revision: 59682

URL: http://llvm.org/viewvc/llvm-project?rev=59682&view=rev
Log:
More objc gc stuff. Read/Write barriers for local static/extern,
diagnostics on use of __weak attribute on fields,
Early support for read/write barriers for objc fields.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=59682&r1=59681&r2=59682&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Nov 19 18:15:42 2008
@@ -790,6 +790,8 @@
      "argument to annotate attribute was not a string literal")
 DIAG(warn_attribute_ignored, WARNING,
   "'%0' attribute ignored")
+DIAG(warn_attribute_weak_on_field, WARNING,
+     "__weak attribute cannot be specified on a field declaration")
 DIAG(warn_attribute_wrong_decl_type, WARNING,
   "'%0' attribute only applies to %1 types")
 DIAG(warn_attribute_ignored_for_field_of_type, WARNING,

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=59682&r1=59681&r2=59682&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Nov 19 18:15:42 2008
@@ -521,33 +521,48 @@
   Builder.CreateStore(Vec, Dst.getExtVectorAddr(), Dst.isVolatileQualified());
 }
 
+/// SetVarDeclObjCAttribute - Set __weak/__strong attributes into the LValue
+/// object.
+void CodeGenFunction::SetVarDeclObjCAttribute(const VarDecl *VD, 
+                                              const QualType &Ty, 
+                                              LValue &LV)
+{
+  if (const ObjCGCAttr *A = VD->getAttr<ObjCGCAttr>()) {
+    ObjCGCAttr::GCAttrTypes attrType = A->getType();
+    LValue::SetObjCType(attrType == ObjCGCAttr::Weak, 
+                        attrType == ObjCGCAttr::Strong, LV);
+  }
+  else if (CGM.getLangOptions().ObjC1 &&
+           CGM.getLangOptions().getGCMode() != LangOptions::NonGC) {
+    if (getContext().isObjCObjectPointerType(Ty))
+      LValue::SetObjCType(false, true, LV);
+  }  
+}
 
 LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
   const VarDecl *VD = dyn_cast<VarDecl>(E->getDecl());
   
   if (VD && (VD->isBlockVarDecl() || isa<ParmVarDecl>(VD) ||
         isa<ImplicitParamDecl>(VD))) {
-    if (VD->getStorageClass() == VarDecl::Extern)
-      return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD),
-                              E->getType().getCVRQualifiers());
+    LValue LV;
+    if (VD->getStorageClass() == VarDecl::Extern) {
+      LV = LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD),
+                            E->getType().getCVRQualifiers());
+    }
     else {
       llvm::Value *V = LocalDeclMap[VD];
       assert(V && "BlockVarDecl not entered in LocalDeclMap?");
-      return LValue::MakeAddr(V, E->getType().getCVRQualifiers());
+      LV = LValue::MakeAddr(V, E->getType().getCVRQualifiers());
     }
+    if (VD->isBlockVarDecl() && 
+        (VD->getStorageClass() == VarDecl::Static || 
+         VD->getStorageClass() == VarDecl::Extern))
+      SetVarDeclObjCAttribute(VD, E->getType(), LV);
+    return LV;
   } else if (VD && VD->isFileVarDecl()) {
     LValue LV = LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD),
                                  E->getType().getCVRQualifiers());
-    if (const ObjCGCAttr *A = VD->getAttr<ObjCGCAttr>()) {
-      ObjCGCAttr::GCAttrTypes attrType = A->getType();
-      LValue::SetObjCType(attrType == ObjCGCAttr::Weak, attrType == ObjCGCAttr::Strong, LV);
-    }
-    else if (CGM.getLangOptions().ObjC1 &&
-             CGM.getLangOptions().getGCMode() != LangOptions::NonGC) {
-      QualType ExprTy = E->getType();
-      if (getContext().isObjCObjectPointerType(ExprTy))
-        LValue::SetObjCType(false, true, LV);
-    }
+    SetVarDeclObjCAttribute(VD, E->getType(), LV);
     return LV;
   } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(E->getDecl())) {
     return LValue::MakeAddr(CGM.GetAddrOfFunction(FD),
@@ -767,7 +782,7 @@
                                 Field->getType()->isSignedIntegerType(),
                             Field->getType().getCVRQualifiers()|CVRQualifiers);
   }
-
+  
   V = Builder.CreateStructGEP(BaseValue, idx, "tmp");
 
   // Match union field type.
@@ -782,8 +797,21 @@
                               "tmp");
   }
 
-  return LValue::MakeAddr(V, 
-                          Field->getType().getCVRQualifiers()|CVRQualifiers);
+  LValue LV =  
+    LValue::MakeAddr(V, 
+                     Field->getType().getCVRQualifiers()|CVRQualifiers);
+  if (const ObjCGCAttr *A = Field->getAttr<ObjCGCAttr>()) {
+    ObjCGCAttr::GCAttrTypes attrType = A->getType();
+    // __weak attribute on a field is ignored.
+    LValue::SetObjCType(false, attrType == ObjCGCAttr::Strong, LV);
+  }
+  else if (CGM.getLangOptions().ObjC1 &&
+           CGM.getLangOptions().getGCMode() != LangOptions::NonGC) {
+    QualType ExprTy = Field->getType();
+    if (getContext().isObjCObjectPointerType(ExprTy))
+      LValue::SetObjCType(false, true, LV);
+  }  
+  return LV;
 }
 
 LValue CodeGenFunction::EmitCompoundLiteralLValue(const CompoundLiteralExpr* E)

Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=59682&r1=59681&r2=59682&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Wed Nov 19 18:15:42 2008
@@ -462,7 +462,8 @@
   LValue EmitBinaryOperatorLValue(const BinaryOperator *E);
   // Note: only availabe for agg return types
   LValue EmitCallExprLValue(const CallExpr *E);
-  
+  void SetVarDeclObjCAttribute(const VarDecl *VD, const QualType &Ty, 
+                               LValue &LV);
   LValue EmitDeclRefLValue(const DeclRefExpr *E);
   LValue EmitStringLiteralLValue(const StringLiteral *E);
   LValue EmitPredefinedFunctionName(unsigned Type);

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=59682&r1=59681&r2=59682&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Nov 19 18:15:42 2008
@@ -555,8 +555,11 @@
   
   
   ObjCGCAttr::GCAttrTypes type;
-  if (Attr.getParameterName()->isName("weak"))
+  if (Attr.getParameterName()->isName("weak")) {
+    if (isa<FieldDecl>(d))
+      S.Diag(Attr.getLoc(), diag::warn_attribute_weak_on_field);
     type = ObjCGCAttr::Weak;
+  }
   else if (Attr.getParameterName()->isName("strong"))
     type = ObjCGCAttr::Strong;
   else {





More information about the cfe-commits mailing list