[cfe-commits] r59738 - in /cfe/trunk: lib/CodeGen/CGExpr.cpp lib/CodeGen/CodeGenFunction.h test/SemaObjC/warn-weak-field.m

Fariborz Jahanian fjahanian at apple.com
Thu Nov 20 10:11:11 PST 2008


Author: fjahanian
Date: Thu Nov 20 12:10:58 2008
New Revision: 59738

URL: http://llvm.org/viewvc/llvm-project?rev=59738&view=rev
Log:
Added a test case for __weak field decls. Change SetVarDeclObjCAttribute
to static function. Added comments.

Added:
    cfe/trunk/test/SemaObjC/warn-weak-field.m
Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/lib/CodeGen/CodeGenFunction.h

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Nov 20 12:10:58 2008
@@ -523,18 +523,19 @@
 
 /// SetVarDeclObjCAttribute - Set __weak/__strong attributes into the LValue
 /// object.
-void CodeGenFunction::SetVarDeclObjCAttribute(const VarDecl *VD, 
-                                              const QualType &Ty, 
-                                              LValue &LV)
+static void SetVarDeclObjCAttribute(ASTContext &Ctx, 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))
+  else if (Ctx.getLangOptions().ObjC1 &&
+           Ctx.getLangOptions().getGCMode() != LangOptions::NonGC) {
+    // Default behavious under objective-c's gc is for objective-c pointers
+    // be treated as though they were declared as __strong.
+    if (Ctx.isObjCObjectPointerType(Ty))
       LValue::SetObjCType(false, true, LV);
   }  
 }
@@ -557,12 +558,12 @@
     if (VD->isBlockVarDecl() && 
         (VD->getStorageClass() == VarDecl::Static || 
          VD->getStorageClass() == VarDecl::Extern))
-      SetVarDeclObjCAttribute(VD, E->getType(), LV);
+      SetVarDeclObjCAttribute(getContext(), VD, E->getType(), LV);
     return LV;
   } else if (VD && VD->isFileVarDecl()) {
     LValue LV = LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD),
                                  E->getType().getCVRQualifiers());
-    SetVarDeclObjCAttribute(VD, E->getType(), LV);
+    SetVarDeclObjCAttribute(getContext(), VD, E->getType(), LV);
     return LV;
   } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(E->getDecl())) {
     return LValue::MakeAddr(CGM.GetAddrOfFunction(FD),

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Thu Nov 20 12:10:58 2008
@@ -462,8 +462,6 @@
   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);

Added: cfe/trunk/test/SemaObjC/warn-weak-field.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/warn-weak-field.m?rev=59738&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/warn-weak-field.m (added)
+++ cfe/trunk/test/SemaObjC/warn-weak-field.m Thu Nov 20 12:10:58 2008
@@ -0,0 +1,13 @@
+// RUN: clang -fsyntax-only -fobjc-gc -verify %s
+
+struct S {
+	__weak id w; // expected-warning {{__weak attribute cannot be specified on a field declaration}}
+	__strong id p1;
+};
+
+int main ()
+{
+	struct I {
+        __weak id w1;  // expected-warning {{__weak attribute cannot be specified on a field declaration}}
+	};
+}





More information about the cfe-commits mailing list