aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/AST/ASTContext.h5
-rw-r--r--lib/AST/ASTContext.cpp16
-rw-r--r--lib/CodeGen/CGExpr.cpp27
3 files changed, 31 insertions, 17 deletions
diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h
index 76bb01ebe5..42b019df06 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -395,6 +395,11 @@ public:
/// to struct), Interface* (pointer to ObjCInterfaceType) and id<P> (qualified
/// ID type).
bool isObjCObjectPointerType(QualType Ty) const;
+
+ /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's
+ /// garbage collection attribute.
+ ///
+ QualType::GCAttrTypes getObjCGCAttrKind(const QualType &Ty) const;
/// isObjCNSObjectType - Return true if this is an NSObject object with
/// its NSObject attribute set.
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 9198bf71cd..bd9279fb50 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -2390,6 +2390,22 @@ bool ASTContext::isObjCObjectPointerType(QualType Ty) const {
return isObjCNSObjectType(Ty);
}
+/// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's
+/// garbage collection attribute.
+///
+QualType::GCAttrTypes ASTContext::getObjCGCAttrKind(const QualType &Ty) const {
+ QualType::GCAttrTypes attr = QualType::GCNone;
+ if (getLangOptions().ObjC1 &&
+ getLangOptions().getGCMode() != LangOptions::NonGC) {
+ attr = Ty.getObjCGCAttr();
+ // Default behavious under objective-c's gc is for objective-c pointers
+ // be treated as though they were declared as __strong.
+ if (attr == QualType::GCNone && isObjCObjectPointerType(Ty))
+ attr = QualType::Strong;
+ }
+ return attr;
+}
+
//===----------------------------------------------------------------------===//
// Type Compatibility Testing
//===----------------------------------------------------------------------===//
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index ae8d4b433a..e991c8ec77 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -604,22 +604,15 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
Builder.CreateStore(Vec, Dst.getExtVectorAddr(), Dst.isVolatileQualified());
}
-/// SetVarDeclObjCAttribute - Set __weak/__strong attributes into the LValue
+/// SetDeclObjCGCAttrInLvalue - Set __weak/__strong attributes into the LValue
/// object.
-static void SetVarDeclObjCAttribute(ASTContext &Ctx, const Decl *VD,
- const QualType &Ty, LValue &LV)
+static void SetDeclObjCGCAttrInLvalue(ASTContext &Ctx, const QualType &Ty,
+ LValue &LV)
{
- if (Ctx.getLangOptions().ObjC1 &&
- Ctx.getLangOptions().getGCMode() != LangOptions::NonGC) {
- QualType::GCAttrTypes attr = Ty.getObjCGCAttr();
- if (attr != QualType::GCNone)
- LValue::SetObjCType(attr == QualType::Weak,
- attr == QualType::Strong, LV);
- // Default behavious under objective-c's gc is for objective-c pointers
- // be treated as though they were declared as __strong.
- else if (Ctx.isObjCObjectPointerType(Ty))
- LValue::SetObjCType(false, true, LV);
- }
+ QualType::GCAttrTypes attr = Ctx.getObjCGCAttrKind(Ty);
+ if (attr != QualType::GCNone)
+ LValue::SetObjCType(attr == QualType::Weak,
+ attr == QualType::Strong, LV);
}
LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
@@ -640,12 +633,12 @@ LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
if (VD->isBlockVarDecl() &&
(VD->getStorageClass() == VarDecl::Static ||
VD->getStorageClass() == VarDecl::Extern))
- SetVarDeclObjCAttribute(getContext(), VD, E->getType(), LV);
+ SetDeclObjCGCAttrInLvalue(getContext(), E->getType(), LV);
return LV;
} else if (VD && VD->isFileVarDecl()) {
LValue LV = LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD),
E->getType().getCVRQualifiers());
- SetVarDeclObjCAttribute(getContext(), VD, E->getType(), LV);
+ SetDeclObjCGCAttrInLvalue(getContext(), E->getType(), LV);
return LV;
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(E->getDecl())) {
return LValue::MakeAddr(CGM.GetAddrOfFunction(FD),
@@ -1054,7 +1047,7 @@ LValue CodeGenFunction::EmitLValueForIvar(QualType ObjectTy,
ObjectTy,
BaseValue, Ivar, Field,
CVRQualifiers);
- SetVarDeclObjCAttribute(getContext(), Ivar, Ivar->getType(), LV);
+ SetDeclObjCGCAttrInLvalue(getContext(), Ivar->getType(), LV);
return LV;
}