diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-01-16 19:36:43 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-01-16 19:36:43 +0000 |
commit | dfa4fa0fc5b78a91c74db84fce305771c2038229 (patch) | |
tree | 9cce161d826e15060f5a4139f7a0195b2437e9c7 /lib/Frontend/RewriteObjC.cpp | |
parent | 6a0166edea84e6abccce393c15e3dee7b96f7eb6 (diff) |
Fix a rewriting crash and correct rewriting of __block
declaration where its initializer has a type-cast.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93650 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/RewriteObjC.cpp')
-rw-r--r-- | lib/Frontend/RewriteObjC.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/Frontend/RewriteObjC.cpp b/lib/Frontend/RewriteObjC.cpp index 44a770a3ed..68c23c708a 100644 --- a/lib/Frontend/RewriteObjC.cpp +++ b/lib/Frontend/RewriteObjC.cpp @@ -4536,8 +4536,13 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { ByrefType += " " + Name + ";\n"; ByrefType += "};\n"; // Insert this type in global scope. It is needed by helper function. - assert(CurFunctionDef && "RewriteByRefVar - CurFunctionDef is null"); - SourceLocation FunLocStart = CurFunctionDef->getTypeSpecStartLoc(); + SourceLocation FunLocStart; + if (CurFunctionDef) + FunLocStart = CurFunctionDef->getTypeSpecStartLoc(); + else { + assert(CurMethodDef && "RewriteByRefVar - CurMethodDef is null"); + FunLocStart = CurMethodDef->getLocStart(); + } InsertText(FunLocStart, ByrefType.c_str(), ByrefType.size()); if (Ty.isObjCGCWeak()) { flag |= BLOCK_FIELD_IS_WEAK; @@ -4587,12 +4592,17 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { ByrefType.c_str(), ByrefType.size()); } else { - SourceLocation startLoc = ND->getInit()->getLocStart(); + SourceLocation startLoc; + Expr *E = ND->getInit(); + if (const CStyleCastExpr *ECE = dyn_cast<CStyleCastExpr>(E)) + startLoc = ECE->getLParenLoc(); + else + startLoc = E->getLocStart(); startLoc = SM->getInstantiationLoc(startLoc); + endBuf = SM->getCharacterData(startLoc); + ByrefType += " " + Name; - ReplaceText(DeclLoc, endBuf-startBuf, - ByrefType.c_str(), ByrefType.size()); - ByrefType = " = {(void*)"; + ByrefType += " = {(void*)"; ByrefType += utostr(isa); ByrefType += ", &" + Name + ", "; ByrefType += utostr(flags); @@ -4607,7 +4617,8 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { ByrefType += utostr(flag); ByrefType += ", "; } - InsertText(startLoc, ByrefType.c_str(), ByrefType.size()); + ReplaceText(DeclLoc, endBuf-startBuf, + ByrefType.c_str(), ByrefType.size()); // Complete the newly synthesized compound expression by inserting a right // curly brace before the end of the declaration. |