[cfe-commits] r55118 - /cfe/trunk/Driver/RewriteObjC.cpp

Steve Naroff snaroff at apple.com
Thu Aug 21 06:03:16 PDT 2008


Author: snaroff
Date: Thu Aug 21 08:03:03 2008
New Revision: 55118

URL: http://llvm.org/viewvc/llvm-project?rev=55118&view=rev
Log:
RewriteObjC::RewriteObjCSynchronizedStmt(): Make sure the sync expr is cast to "id".
This fixes <rdar://problem/6163088> clang ObjC rewriter: @synchronized ([foo class]) {} does not cast properly.

Modified:
    cfe/trunk/Driver/RewriteObjC.cpp

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

==============================================================================
--- cfe/trunk/Driver/RewriteObjC.cpp (original)
+++ cfe/trunk/Driver/RewriteObjC.cpp Thu Aug 21 08:03:03 2008
@@ -1302,8 +1302,10 @@
   assert((*startBuf == '@') && "bogus @synchronized location");
   
   std::string buf; 
-  buf = "objc_sync_enter";
-  ReplaceText(startLoc, 13, buf.c_str(), buf.size());
+  buf = "objc_sync_enter((id)";
+  const char *lparenBuf = startBuf;
+  while (*lparenBuf != '(') lparenBuf++;
+  ReplaceText(startLoc, lparenBuf-startBuf+1, buf.c_str(), buf.size());
   // 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).
@@ -1329,8 +1331,10 @@
   buf += "  _rethrow = objc_exception_extract(&_stack);\n";
   buf += "  if (!_rethrow) objc_exception_try_exit(&_stack);\n";
   buf += "  objc_sync_exit(";
+  Expr *syncExpr = new ExplicitCastExpr(Context->getObjCIdType(), 
+                                        S->getSynchExpr(), SourceLocation());
   std::ostringstream syncExprBuf;
-  S->getSynchExpr()->printPretty(syncExprBuf);
+  syncExpr->printPretty(syncExprBuf);
   buf += syncExprBuf.str();
   buf += ");\n";
   buf += "  if (_rethrow) objc_exception_throw(_rethrow);\n";





More information about the cfe-commits mailing list