]> granicus.if.org Git - clang/commitdiff
Prevent rewriter crash when variable type is missing.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 26 Feb 2010 22:49:11 +0000 (22:49 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 26 Feb 2010 22:49:11 +0000 (22:49 +0000)
Fixes radar 7692183.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97281 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/RewriteObjC.cpp
test/Rewriter/rewrite-byref-in-nested-blocks.mm

index be07a6aadf4d598ab0e391fa8c4e1f2b8204a576..635280bf4326fc5f7ef653643738892a350f0fba 100644 (file)
@@ -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);
index c6279de5e1ddad76669c0d581206422d9e7c13ae..a8f5b140eaac942b989f8ac395f8b4f9f8cce20f 100644 (file)
@@ -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;
                 });
         });
 }