[cfe-commits] r54986 - in /cfe/trunk: Driver/RewriteObjC.cpp test/Rewriter/objc-synchronized-1.m

Steve Naroff snaroff at apple.com
Tue Aug 19 06:04:27 PDT 2008


Author: snaroff
Date: Tue Aug 19 08:04:19 2008
New Revision: 54986

URL: http://llvm.org/viewvc/llvm-project?rev=54986&view=rev
Log:
Fix crasher in RewriteObjC::RewriteObjCSynchronizedStmt(). Can't depend on the source locations of the sync expression (since it may have been rewritten.
Fixes <rdar://problem/6156363> clang ObjC rewriter: rewriting attached file causes assertion failure: invalid FileID

Modified:
    cfe/trunk/Driver/RewriteObjC.cpp
    cfe/trunk/test/Rewriter/objc-synchronized-1.m

Modified: cfe/trunk/Driver/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/RewriteObjC.cpp?rev=54986&r1=54985&r2=54986&view=diff

==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Tue Aug 19 08:04:19 2008
@@ -1304,11 +1304,13 @@
   std::string buf; 
   buf = "objc_sync_enter";
   ReplaceText(startLoc, 13, buf.c_str(), buf.size());
-  SourceLocation endLoc = S->getSynchExpr()->getLocEnd();
+  // We can't use S->getSynchExpr()->getLocEnd() to find the end location, since 
+  // the sync expression is typically a message expression that's already 
+  // been rewritten! (which implies the SourceLocation's are invalid).
+  SourceLocation endLoc = S->getSynchBody()->getLocStart();
   const char *endBuf = SM->getCharacterData(endLoc);
-  endBuf++;
-  const char *rparenBuf = strchr(endBuf, ')');
-  SourceLocation rparenLoc = startLoc.getFileLocWithOffset(rparenBuf-startBuf);
+  while (*endBuf != ')') endBuf--;
+  SourceLocation rparenLoc = startLoc.getFileLocWithOffset(endBuf-startBuf);
   buf = ");\n";
   // declare a new scope with two variables, _stack and _rethrow.
   buf += "/* @try scope begin */ \n{ struct _objc_exception_data {\n";
@@ -1321,7 +1323,7 @@
   startLoc = S->getSynchBody()->getLocEnd();
   startBuf = SM->getCharacterData(startLoc);
   
-  assert((*startBuf == '}') && "bogus @try block");
+  assert((*startBuf == '}') && "bogus @synchronized block");
   SourceLocation lastCurlyLoc = startLoc;
   buf = "}\nelse {\n";
   buf += "  _rethrow = objc_exception_extract(&_stack);\n";

Modified: cfe/trunk/test/Rewriter/objc-synchronized-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-synchronized-1.m?rev=54986&r1=54985&r2=54986&view=diff

==============================================================================
--- cfe/trunk/test/Rewriter/objc-synchronized-1.m (original)
+++ cfe/trunk/test/Rewriter/objc-synchronized-1.m Tue Aug 19 08:04:19 2008
@@ -13,4 +13,8 @@
     return;
   }
  SYNC_AFTER();
+ @synchronized ([sem self]) {
+    SYNCH_BODY();
+    return;
+ }
 }





More information about the cfe-commits mailing list