summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2008-11-20 00:15:42 +0000
committerFariborz Jahanian <fjahanian@apple.com>2008-11-20 00:15:42 +0000
commit003e83004b366285c2f15b6d871754775f5bd291 (patch)
tree68758261c6bd8fedf97aaa73a2fac9ec0add8162 /clang/lib/CodeGen
parent8d5b57b35438290d2007ae33c6408cf443dd616e (diff)
downloadbcm5719-llvm-003e83004b366285c2f15b6d871754775f5bd291.tar.gz
bcm5719-llvm-003e83004b366285c2f15b6d871754775f5bd291.zip
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. llvm-svn: 59682
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp62
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.h3
2 files changed, 47 insertions, 18 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 9e4d66a9478..4228bc22b6f 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -521,33 +521,48 @@ void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src,
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 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue,
Field->getType()->isSignedIntegerType(),
Field->getType().getCVRQualifiers()|CVRQualifiers);
}
-
+
V = Builder.CreateStructGEP(BaseValue, idx, "tmp");
// Match union field type.
@@ -782,8 +797,21 @@ LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue,
"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)
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 05b2793456b..1da4e195ba8 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -462,7 +462,8 @@ public:
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);
OpenPOWER on IntegriCloud