[cfe-commits] r109018 - in /cfe/trunk: lib/Rewrite/RewriteObjC.cpp test/Rewriter/rewrite-constructor-init.mm
Fariborz Jahanian
fjahanian at apple.com
Wed Jul 21 10:36:39 PDT 2010
Author: fjahanian
Date: Wed Jul 21 12:36:39 2010
New Revision: 109018
URL: http://llvm.org/viewvc/llvm-project?rev=109018&view=rev
Log:
Fix a rewriter bug which originates in SemaInit involving
Constructor Initialization which computes Source Location
differently now. Fixes radar 8213998.
Added:
cfe/trunk/test/Rewriter/rewrite-constructor-init.mm
Modified:
cfe/trunk/lib/Rewrite/RewriteObjC.cpp
Modified: cfe/trunk/lib/Rewrite/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteObjC.cpp?rev=109018&r1=109017&r2=109018&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteObjC.cpp Wed Jul 21 12:36:39 2010
@@ -5098,7 +5098,14 @@
startLoc = E->getLocStart();
startLoc = SM->getInstantiationLoc(startLoc);
endBuf = SM->getCharacterData(startLoc);
-
+ if (dyn_cast<CXXConstructExpr>(E)) {
+ // Hack alter!
+ // SemaInit sets startLoc to beginning of the initialized variable when
+ // rhs involvs copy construction initialization. Must compensate for this.
+ if (char *atEqual = strchr(endBuf, '='))
+ endBuf = atEqual + 1;
+ }
+
ByrefType += " " + Name;
ByrefType += " = {(void*)";
ByrefType += utostr(isa);
@@ -5125,11 +5132,11 @@
//
// double __block BYREFVAR = 1.34, BYREFVAR2 = 1.37;
//
- const char *startBuf = SM->getCharacterData(startLoc);
- const char *semiBuf = strchr(startBuf, ';');
+ const char *startInitializerBuf = SM->getCharacterData(startLoc);
+ const char *semiBuf = strchr(startInitializerBuf, ';');
assert((*semiBuf == ';') && "RewriteByRefVar: can't find ';'");
SourceLocation semiLoc =
- startLoc.getFileLocWithOffset(semiBuf-startBuf);
+ startLoc.getFileLocWithOffset(semiBuf-startInitializerBuf);
InsertText(semiLoc, "}");
}
Added: cfe/trunk/test/Rewriter/rewrite-constructor-init.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-constructor-init.mm?rev=109018&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-constructor-init.mm (added)
+++ cfe/trunk/test/Rewriter/rewrite-constructor-init.mm Wed Jul 21 12:36:39 2010
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// rdar : // 8213998
+
+typedef unsigned int NSUInteger;
+
+typedef struct _NSRange {
+ NSUInteger location;
+ NSUInteger length;
+} NSRange;
+
+static __inline NSRange NSMakeRange(NSUInteger loc, NSUInteger len) {
+ NSRange r;
+ r.location = loc;
+ r.length = len;
+ return r;
+}
+
+void bar() {
+ __block NSRange previousRange = NSMakeRange(0, 0);
+ void (^blk)() = ^{
+ previousRange = NSMakeRange(1, 0);
+ };
+}
More information about the cfe-commits
mailing list