From: Fariborz Jahanian Date: Fri, 26 Feb 2010 22:49:11 +0000 (+0000) Subject: Prevent rewriter crash when variable type is missing. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d64a4f4798907495091daf2b081c3d62d729dca9;p=clang Prevent rewriter crash when variable type is missing. Fixes radar 7692183. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97281 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/RewriteObjC.cpp b/lib/Frontend/RewriteObjC.cpp index be07a6aadf..635280bf43 100644 --- a/lib/Frontend/RewriteObjC.cpp +++ b/lib/Frontend/RewriteObjC.cpp @@ -4781,6 +4781,10 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) { int flag = 0; int isa = 0; SourceLocation DeclLoc = ND->getTypeSpecStartLoc(); + if (DeclLoc.isInvalid()) + // If type location is missing, it is because of missing type (a warning). + // Use variable's location which is good for this case. + DeclLoc = ND->getLocation(); const char *startBuf = SM->getCharacterData(DeclLoc); SourceLocation X = ND->getLocEnd(); X = SM->getInstantiationLoc(X); diff --git a/test/Rewriter/rewrite-byref-in-nested-blocks.mm b/test/Rewriter/rewrite-byref-in-nested-blocks.mm index c6279de5e1..a8f5b140ea 100644 --- a/test/Rewriter/rewrite-byref-in-nested-blocks.mm +++ b/test/Rewriter/rewrite-byref-in-nested-blocks.mm @@ -13,10 +13,13 @@ void f(void (^block)(void)); @implementation X - (void)foo { __block int kerfluffle; + // radar 7692183 + __block x; f(^{ f(^{ y = 42; kerfluffle = 1; + x = 2; }); }); }