From: Fariborz Jahanian Date: Tue, 5 Jan 2010 19:21:35 +0000 (+0000) Subject: API support for __block variables which are also __weak. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2086d544d38f2611f2fba034e25833a47c81fb21;p=clang API support for __block variables which are also __weak. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92755 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/RewriteObjC.cpp b/lib/Frontend/RewriteObjC.cpp index 253e081658..fd3efe560b 100644 --- a/lib/Frontend/RewriteObjC.cpp +++ b/lib/Frontend/RewriteObjC.cpp @@ -603,8 +603,10 @@ void RewriteObjC::Initialize(ASTContext &context) { Preamble += "#undef __OBJC_RW_STATICIMPORT\n"; Preamble += "#define __attribute__(X)\n"; } - else + else { Preamble += "#define __block\n"; + Preamble += "#define __weak\n"; + } } @@ -4461,7 +4463,8 @@ std::string RewriteObjC::SynthesizeByrefCopyDestroyHelper(VarDecl *VD, /// /// void RewriteObjC::RewriteByRefVar(VarDecl *ND) { - int flag; + int flag = 0; + int isa = 0; SourceLocation DeclLoc = ND->getTypeSpecStartLoc(); const char *startBuf = SM->getCharacterData(DeclLoc); SourceLocation X = ND->getLocEnd(); @@ -4491,6 +4494,11 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { assert(CurFunctionDef && "RewriteByRefVar - CurFunctionDef is null"); SourceLocation FunLocStart = CurFunctionDef->getTypeSpecStartLoc(); InsertText(FunLocStart, ByrefType.c_str(), ByrefType.size()); + if (Ty.isObjCGCWeak()) { + flag |= BLOCK_FIELD_IS_WEAK; + isa = 1; + } + if (HasCopyAndDispose) { flag = BLOCK_BYREF_CALLER; QualType Ty = ND->getType(); @@ -4514,8 +4522,9 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { Name = ND->getNameAsString(); ByrefType = "struct __Block_byref_" + Name; if (!hasInit) { - ByrefType += " " + Name + " = "; - ByrefType += "{0, &" + Name + ", "; + ByrefType += " " + Name + " = {(void*)"; + ByrefType += utostr(isa); + ByrefType += ", &" + Name + ", "; ByrefType += utostr(flags); ByrefType += ", "; ByrefType += "sizeof(struct __Block_byref_" + Name + ")"; @@ -4534,7 +4543,9 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { ByrefType += " " + Name; ReplaceText(DeclLoc, endBuf-startBuf, ByrefType.c_str(), ByrefType.size()); - ByrefType = " = {0, &" + Name + ", "; + ByrefType = " = {(void*)"; + ByrefType += utostr(isa); + ByrefType += ", &" + Name + ", "; ByrefType += utostr(flags); ByrefType += ", "; ByrefType += "sizeof(struct __Block_byref_" + Name + "), ";