[cfe-commits] r93650 - in /cfe/trunk: lib/Frontend/RewriteObjC.cpp test/Rewriter/rewrite-byref-vars.mm

Fariborz Jahanian fjahanian at apple.com
Sat Jan 16 11:36:43 PST 2010


Author: fjahanian
Date: Sat Jan 16 13:36:43 2010
New Revision: 93650

URL: http://llvm.org/viewvc/llvm-project?rev=93650&view=rev
Log:
Fix a rewriting crash and correct rewriting of __block
declaration where its initializer has a type-cast.


Modified:
    cfe/trunk/lib/Frontend/RewriteObjC.cpp
    cfe/trunk/test/Rewriter/rewrite-byref-vars.mm

Modified: cfe/trunk/lib/Frontend/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/RewriteObjC.cpp?rev=93650&r1=93649&r2=93650&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Frontend/RewriteObjC.cpp Sat Jan 16 13:36:43 2010
@@ -4536,8 +4536,13 @@
   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 @@
                 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 @@
       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.

Modified: cfe/trunk/test/Rewriter/rewrite-byref-vars.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-byref-vars.mm?rev=93650&r1=93649&r2=93650&view=diff

==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-byref-vars.mm (original)
+++ cfe/trunk/test/Rewriter/rewrite-byref-vars.mm Sat Jan 16 13:36:43 2010
@@ -31,5 +31,16 @@
 
 }
 
+ at interface I
+{
+   id list;
+}
+- (void) Meth;
+ at end
+
+ at implementation I
+- (void) Meth { __attribute__((__blocks__(byref))) void ** listp = (void **)list; }
+ at end
+
 // $CLANG -cc1 -fms-extensions -rewrite-objc -x objective-c++ -fblocks bug.mm
 // g++ -c -D"__declspec(X)=" bug.cpp





More information about the cfe-commits mailing list