]> granicus.if.org Git - clang/commitdiff
We should not generate __weak write barrier on indirect reference
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 23 Feb 2009 18:59:50 +0000 (18:59 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 23 Feb 2009 18:59:50 +0000 (18:59 +0000)
of a pointer to object; This patch does this odd behavior according to
gcc.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65334 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
lib/CodeGen/CGExpr.cpp

index a621119daefb1a7f4f8a0adbe996bfc56dd45a95..3aea3e324ba49ebc516117f1bfbb311d86c8694e 100644 (file)
@@ -753,6 +753,8 @@ bool Expr::isOBJCGCCandidate() const {
     return false;
   case ObjCIvarRefExprClass:
     return true;
+  case Expr::UnaryOperatorClass:
+    return cast<UnaryOperator>(this)->getSubExpr()->isOBJCGCCandidate();
   case ParenExprClass:
     return cast<ParenExpr>(this)->getSubExpr()->isOBJCGCCandidate();
   case ImplicitCastExprClass:
index c96265242ac4dad414b256782d78a1920a894932..0449900a0f88ff518c965b05c0aac467425452c5 100644 (file)
@@ -669,10 +669,19 @@ LValue CodeGenFunction::EmitUnaryOpLValue(const UnaryOperator *E) {
   case UnaryOperator::Deref:
     {
       QualType T = E->getSubExpr()->getType()->getAsPointerType()->getPointeeType();
-      return LValue::MakeAddr(EmitScalarExpr(E->getSubExpr()),
-                              ExprTy->getAsPointerType()->getPointeeType()
+      LValue LV = LValue::MakeAddr(EmitScalarExpr(E->getSubExpr()),
+                                   ExprTy->getAsPointerType()->getPointeeType()
                                       .getCVRQualifiers(), 
-                              getContext().getObjCGCAttrKind(T));
+                                   getContext().getObjCGCAttrKind(T));
+     // We should not generate __weak write barrier on indirect reference
+     // of a pointer to object; as in void foo (__weak id *param); *param = 0;
+     // But, we continue to generate __strong write barrier on indirect write
+     // into a pointer to object.
+     if (getContext().getLangOptions().ObjC1 &&
+         getContext().getLangOptions().getGCMode() != LangOptions::NonGC &&
+         LV.isObjCWeak())
+       LValue::SetObjCNonGC(LV, !E->isOBJCGCCandidate());
+     return LV;
     }
   case UnaryOperator::Real:
   case UnaryOperator::Imag: