]> granicus.if.org Git - clang/commitdiff
Fix a rewriter bug which originates in SemaInit involving
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 21 Jul 2010 17:36:39 +0000 (17:36 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 21 Jul 2010 17:36:39 +0000 (17:36 +0000)
Constructor Initialization which computes Source Location
differently now. Fixes radar 8213998.

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

lib/Rewrite/RewriteObjC.cpp
test/Rewriter/rewrite-constructor-init.mm [new file with mode: 0644]

index 351667e32f95b9d4126e210466854299d8f9bf20..2743a2bdc190854cc638a3b19c420bc24214c1c0 100644 (file)
@@ -5098,7 +5098,14 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) {
       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 @@ void RewriteObjC::RewriteByRefVar(VarDecl *ND) {
     // 
     // 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, "}");
   }
diff --git a/test/Rewriter/rewrite-constructor-init.mm b/test/Rewriter/rewrite-constructor-init.mm
new file mode 100644 (file)
index 0000000..534e7fa
--- /dev/null
@@ -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);
+    };
+}